self_drug_api_congtroller.go 90KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "reflect"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. type SelfDrugApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func SelfDrugRouters() {
  20. beego.Router("/api/drug/getcurrentpatient", &SelfDrugApiController{}, "Get:GetCurrentPatient")
  21. beego.Router("/api/drug/getalldrugname", &SelfDrugApiController{}, "Get:GetAllDrugName")
  22. beego.Router("/api/drug/savedrugname", &SelfDrugApiController{}, "Get:SaveDrugName")
  23. beego.Router("/api/drug/getdrugnamelist", &SelfDrugApiController{}, "Get:GetDrugNameList")
  24. beego.Router("/api/drug/getrullename", &SelfDrugApiController{}, "Get:GetRulleName")
  25. beego.Router("/api/drug/getunitbybaseid", &SelfDrugApiController{}, "Get:GetUnitByBaseId")
  26. beego.Router("/api/drug/saverullename", &SelfDrugApiController{}, "Get:SaveRulleName")
  27. beego.Router("/api/drug/editrullername", &SelfDrugApiController{}, "Get:EditRullerName")
  28. beego.Router("/api/drug/updatedrullername", &SelfDrugApiController{}, "Get:UpdatedRullerName")
  29. beego.Router("/api/drug/getalldrugnamelist", &SelfDrugApiController{}, "Get:GetAllDrugNameList")
  30. beego.Router("/api/drug/getrulllistbydrugname", &SelfDrugApiController{}, "Get:GetRullerListByDrugName")
  31. beego.Router("/api/drug/saveselfmedicines", &SelfDrugApiController{}, "Post:SaveSelfMedicines")
  32. beego.Router("/api/drug/getcurrentorgallstaff", &SelfDrugApiController{}, "Get:GetCurrentOrgAllStaff")
  33. beego.Router("/api/drug/savestock", &SelfDrugApiController{}, "Post:SaveStock")
  34. beego.Router("/api/drug/saveoutstock", &SelfDrugApiController{}, "Post:SaveOutStock")
  35. beego.Router("/api/drug/deletedrugbyid", &SelfDrugApiController{}, "Get:DeleteDrugById")
  36. beego.Router("/api/drug/saveradio", &SelfDrugApiController{}, "Get:SaveRadio")
  37. beego.Router("/api/drug/deletedrugstand", &SelfDrugApiController{}, "Get:DeleteDrugStand")
  38. beego.Router("/api/drug/getstocklist", &SelfDrugApiController{}, "Get:GetStockList")
  39. beego.Router("/api/drug/deletedrugname", &SelfDrugApiController{}, "Get:DeleteDrugName")
  40. beego.Router("/api/drug/getdrugdetail", &SelfDrugApiController{}, "Get:GetDrugDetail")
  41. beego.Router("/api/drug/getallpatientstocklist", &SelfDrugApiController{}, "Get:GetAllPatientStockList")
  42. beego.Router("/api/drug/getdrugdatabypatientid", &SelfDrugApiController{}, "Get:GetDrugDataByPatientId")
  43. beego.Router("/api/drug/getselfmedicallist", &SelfDrugApiController{}, "Get:GetSelfMedicalList")
  44. beego.Router("/api/drug/getdrugdescbydrugname", &SelfDrugApiController{}, "Get:GetDrugDescByDrugName")
  45. beego.Router("/api/drug/getdrugset", &SelfDrugApiController{}, "Get:GetDrugSet")
  46. beego.Router("/api/drug/getallmedicallist", &SelfDrugApiController{}, "Get:GetAllMedicalList")
  47. beego.Router("/api/drug/getstandname", &SelfDrugApiController{}, "Get:GetStandName")
  48. beego.Router("/api/drug/getrullerlist", &SelfDrugApiController{}, "Get:GetRullerList")
  49. beego.Router("/api/drug/deleteDrugNamebyid", &SelfDrugApiController{}, "Get:DeleteDrugNameById")
  50. beego.Router("/api/drug/getpatientdetail", &SelfDrugApiController{}, "Get:GetPatientDetail")
  51. //beego.Router("/api/drug/getpatientdetail",&SelfDrugApiController{},"Get:ToPatientDetail")
  52. beego.Router("/api/drug/getselfstockquery", &SelfDrugApiController{}, "Get:GetSelfStockQuery")
  53. beego.Router("/api/drug/postsearchdrugwarehouselist", &SelfDrugApiController{}, "Get:PostSearchDrugWarehouseList")
  54. beego.Router("/api/drug/savedrugpriceone", &SelfDrugApiController{}, "Post:SaveDrugPrice")
  55. beego.Router("/api/drug/drugpricelist", &SelfDrugApiController{}, "Get:GetDrugPriceList")
  56. beego.Router("/api/drug/savecheckdrugprice", &SelfDrugApiController{}, "Get:SaveCheckDrugPrice")
  57. beego.Router("/api/drug/savedrugdamageone", &SelfDrugApiController{}, "Post:SaveDrugDamage")
  58. beego.Router("/api/drug/getdrugdamagelist", &SelfDrugApiController{}, "Get:GetDrugDamageList")
  59. beego.Router("/api/drug/savedrugdamageprice", &SelfDrugApiController{}, "Get:SaveDrugDamagePrice")
  60. beego.Router("/api/drug/getdrugmodifyprice", &SelfDrugApiController{}, "Get:GetDrugModifyPrice")
  61. beego.Router("/api/drug/modifydrugprice", &SelfDrugApiController{}, "Get:ModifyDrugPrice")
  62. beego.Router("/api/drug/getmodifypriceprint", &SelfDrugApiController{}, "Get:GetModifyPricePrint")
  63. beego.Router("/api/drug/getdrugdamagedetail", &SelfDrugApiController{}, "Get:GetDrugDamageDetail")
  64. beego.Router("/api/drug/modifydrugdamage", &SelfDrugApiController{}, "Get:ModifyDrugDamage")
  65. beego.Router("/api/drug/deletedrugdamage", &SelfDrugApiController{}, "Get:DeleteDrugDamage")
  66. beego.Router("/api/drug/getdrugdamageprint", &SelfDrugApiController{}, "Get:GetDrugDamagePrint")
  67. beego.Router("/api/drug/warehouseinfobyid", &SelfDrugApiController{}, "Get:GetWarehoseInfoById")
  68. beego.Router("/api/drug/savedruginventory", &SelfDrugApiController{}, "Post:SaveDrugInventory")
  69. beego.Router("/api/drug/getdruginventorylist", &SelfDrugApiController{}, "Get:GetDrugInventoryList")
  70. beego.Router("/api/drug/savedrugcheckinventory", &SelfDrugApiController{}, "Get:SaveDrugCheckInventory")
  71. beego.Router("/api/drug/getdruginventorydetail", &SelfDrugApiController{}, "Get:GetDrugInventoryDetail")
  72. beego.Router("/api/drug/modifyinventory", &SelfDrugApiController{}, "Get:ModifyInventory")
  73. beego.Router("/api/drug/deletedruginventory", &SelfDrugApiController{}, "Get:DeleteDrugInventory")
  74. beego.Router("/api/drug/getdruginventoryprintlist", &SelfDrugApiController{}, "Get:GetDrugInventoryPrintList")
  75. beego.Router("/api/drug/getinventorydetaillist", &SelfDrugApiController{}, "Get:GetDrugInventoryDetailList")
  76. beego.Router("/api/drug/savedrugproofinventory", &SelfDrugApiController{}, "Get:SaveDrugProofInventory")
  77. beego.Router("/api/drug/getdrugwarehouseinfototal", &StockManagerApiController{}, "Get:GetDrugWarehouseInfoTotal")
  78. beego.Router("/api/drug/saveinentorylist", &SelfDrugApiController{}, "Post:SaveInventoryList")
  79. beego.Router("/api/drug/getdamagebydrugid", &SelfDrugApiController{}, "Get:GetDamageByDrugId")
  80. beego.Router("/api/drug/getinventorymodelist", &SelfDrugApiController{}, "Get:GetInventoryModeList")
  81. }
  82. func (this *SelfDrugApiController) GetCurrentPatient() {
  83. adminUserInfo := this.GetAdminUserInfo()
  84. orgId := adminUserInfo.CurrentOrgId
  85. patient, err := service.GetCurrentPatient(orgId)
  86. if err != nil {
  87. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  88. return
  89. }
  90. this.ServeSuccessJSON(map[string]interface{}{
  91. "patient": patient,
  92. })
  93. }
  94. func (this *SelfDrugApiController) GetAllDrugName() {
  95. adminUserInfo := this.GetAdminUserInfo()
  96. orgId := adminUserInfo.CurrentOrgId
  97. //查询药品库是否开启
  98. //configStock, _ := service.GetDrugStockConfig(orgId)
  99. //if configStock.IsOpen == 1 {
  100. //
  101. //}
  102. drugName, err := service.GetAllDrugName(orgId)
  103. if err != nil {
  104. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查寻成功")
  105. return
  106. }
  107. this.ServeSuccessJSON(map[string]interface{}{
  108. "drugName": drugName,
  109. })
  110. }
  111. func (this *SelfDrugApiController) SaveDrugName() {
  112. adminUserInfo := this.GetAdminUserInfo()
  113. orgId := adminUserInfo.CurrentOrgId
  114. drug_name := this.GetString("drug_name")
  115. id, _ := this.GetInt64("id")
  116. //fmt.Println("drug_name", drug_name)
  117. drugName := models.XtDrugName{
  118. UserOrgId: orgId,
  119. DrugName: drug_name,
  120. Status: 1,
  121. CreatedTime: time.Now().Unix(),
  122. DrugId: id,
  123. }
  124. _, errcode := service.GetDrugName(drug_name, orgId)
  125. if errcode == gorm.ErrRecordNotFound {
  126. err := service.SaveDrugName(&drugName)
  127. if err != nil {
  128. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  129. return
  130. }
  131. this.ServeSuccessJSON(map[string]interface{}{
  132. "drugName": drugName,
  133. })
  134. } else {
  135. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  136. return
  137. }
  138. }
  139. func (this *SelfDrugApiController) GetDrugNameList() {
  140. adminUserInfo := this.GetAdminUserInfo()
  141. orgId := adminUserInfo.CurrentOrgId
  142. list, err := service.GetDrugNameList(orgId)
  143. if err != nil {
  144. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  145. return
  146. }
  147. this.ServeSuccessJSON(map[string]interface{}{
  148. "list": list,
  149. })
  150. }
  151. func (this *SelfDrugApiController) GetRulleName() {
  152. adminUserInfo := this.GetAdminUserInfo()
  153. orgId := adminUserInfo.CurrentOrgId
  154. id, _ := this.GetInt64("id")
  155. drugId, _ := service.GetDrugId(id)
  156. rullerList, err := service.GetRulleList(orgId, drugId.DrugId)
  157. if err != nil {
  158. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  159. return
  160. }
  161. this.ServeSuccessJSON(map[string]interface{}{
  162. "rullerList": rullerList,
  163. })
  164. }
  165. func (this *SelfDrugApiController) GetUnitByBaseId() {
  166. id, _ := this.GetInt64("id")
  167. baseList, err := service.GetUnitByBaseId(id)
  168. if err != nil {
  169. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  170. return
  171. }
  172. this.ServeSuccessJSON(map[string]interface{}{
  173. "baseList": baseList,
  174. })
  175. }
  176. func (this *SelfDrugApiController) SaveRulleName() {
  177. drug_name := this.GetString("drug_name")
  178. drug_spec := this.GetString("drug_spec")
  179. drug_stock_limit := this.GetString("drug_stock_limit")
  180. drug_name_id, _ := this.GetInt64("drug_name_id")
  181. drug_id, _ := this.GetInt64("drug_id")
  182. price, _ := this.GetInt64("price")
  183. prices := strconv.FormatInt(price, 10)
  184. durg_price, _ := strconv.ParseFloat(prices, 64)
  185. unit := this.GetString("unit")
  186. adminUserInfo := this.GetAdminUserInfo()
  187. orgId := adminUserInfo.CurrentOrgId
  188. fmt.Println(drug_name, drug_stock_limit, unit, price, drug_spec, orgId)
  189. drugSpecName := models.XtStandName{
  190. DrugName: drug_name,
  191. DrugSpec: drug_spec,
  192. DrugStockLimit: drug_stock_limit,
  193. DrugNameId: drug_name_id,
  194. Price: durg_price,
  195. MinUnit: unit,
  196. UserOrgId: orgId,
  197. Status: 1,
  198. CreatedTime: time.Now().Unix(),
  199. DrugId: drug_id,
  200. }
  201. //查询该机构下药品规格名称是否存在
  202. _, errcode := service.IsExistStandName(drug_name, drug_spec, adminUserInfo.CurrentOrgId)
  203. if errcode == gorm.ErrRecordNotFound {
  204. err := service.SaveRulleName(&drugSpecName)
  205. if err != nil {
  206. this.ServeFailJsonSend(enums.ErrorCodeDataException, "创建规格失败")
  207. return
  208. }
  209. this.ServeSuccessJSON(map[string]interface{}{
  210. "RullerName": drugSpecName,
  211. })
  212. } else if errcode == nil {
  213. this.ServeFailJsonSend(enums.ErrorCodeDataException, "规格已存在")
  214. return
  215. }
  216. }
  217. func (this *SelfDrugApiController) EditRullerName() {
  218. id, _ := this.GetInt64("id")
  219. rullerDetail, err := service.GetRullerNameDetail(id)
  220. if err != nil {
  221. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  222. return
  223. }
  224. this.ServeSuccessJSON(map[string]interface{}{
  225. "rullerDetail": rullerDetail,
  226. })
  227. }
  228. func (this *SelfDrugApiController) UpdatedRullerName() {
  229. id, _ := this.GetInt64("id")
  230. drug_name := this.GetString("drug_name")
  231. drug_stock_limit := this.GetString("drug_stock_limit")
  232. price, _ := this.GetInt64("price")
  233. prices := strconv.FormatInt(price, 10)
  234. durg_price, _ := strconv.ParseFloat(prices, 64)
  235. drug_spec := this.GetString("drug_spec")
  236. unit := this.GetString("unit")
  237. drug_name_id, _ := this.GetInt64("drug_name_id")
  238. drug_id, _ := this.GetInt64("drug_id")
  239. RullerName := models.XtStandName{
  240. DrugName: drug_name,
  241. DrugStockLimit: drug_stock_limit,
  242. Price: durg_price,
  243. DrugSpec: drug_spec,
  244. MinUnit: unit,
  245. DrugNameId: drug_name_id,
  246. DrugId: drug_id,
  247. }
  248. _, errcode := service.GetIsExit(drug_name, drug_spec, id)
  249. if errcode == gorm.ErrRecordNotFound {
  250. err := service.UpdatedRullerName(id, &RullerName)
  251. if err != nil {
  252. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  253. return
  254. }
  255. this.ServeSuccessJSON(map[string]interface{}{
  256. "RullerName": RullerName,
  257. })
  258. } else if errcode == nil {
  259. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  260. return
  261. }
  262. }
  263. func (this *SelfDrugApiController) GetAllDrugNameList() {
  264. adminUserInfo := this.GetAdminUserInfo()
  265. orgId := adminUserInfo.CurrentOrgId
  266. rullerName, err := service.GetAllDrugNameList(orgId)
  267. list, err := service.GetMedicalDrugNameList(orgId)
  268. if err != nil {
  269. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  270. return
  271. }
  272. this.ServeSuccessJSON(map[string]interface{}{
  273. "rullerName": rullerName,
  274. "list": list,
  275. })
  276. }
  277. func (this *SelfDrugApiController) GetRullerListByDrugName() {
  278. id := this.GetString("id")
  279. adminUserInfo := this.GetAdminUserInfo()
  280. orgId := adminUserInfo.CurrentOrgId
  281. fmt.Println("orgid", orgId)
  282. drugName, err := service.GetRullerListByDrugName(id, orgId)
  283. if err != nil {
  284. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  285. return
  286. }
  287. this.ServeSuccessJSON(map[string]interface{}{
  288. "drugName": drugName,
  289. })
  290. }
  291. func (this *SelfDrugApiController) SaveSelfMedicines() {
  292. dataBody := make(map[string]interface{}, 0)
  293. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  294. fmt.Println(err)
  295. patient_id := int64(dataBody["patient_id"].(float64))
  296. medicineData, _ := dataBody["medicineData"].([]interface{})
  297. adminUserInfo := this.GetAdminUserInfo()
  298. orgId := adminUserInfo.CurrentOrgId
  299. for _, item := range medicineData {
  300. items := item.(map[string]interface{})
  301. drug_name := items["drug_name"].(string)
  302. drug_name_id := int64(items["drug_name_id"].(float64))
  303. drug_spec := items["drug_spec"].(string)
  304. min_unit := items["min_unit"].(string)
  305. drug_id := int64(items["drug_id"].(float64))
  306. //根据drug_id
  307. drugMedical, _ := service.GetBaseDrugMedical(drug_name_id)
  308. medical := models.XtSelfMedical{
  309. DrugName: drug_name,
  310. DrugNameId: drug_name_id,
  311. DrugSpec: drug_spec,
  312. CreatedTime: time.Now().Unix(),
  313. Status: 1,
  314. UserOrgId: orgId,
  315. PatientId: patient_id,
  316. MinUnit: min_unit,
  317. ExecutionFrequency: drugMedical.ExecutionFrequency,
  318. PrescribingNumber: drugMedical.PrescribingNumber,
  319. DeliveryWay: drugMedical.DeliveryWay,
  320. SingleDose: drugMedical.SingleDose,
  321. DrugId: drug_id,
  322. }
  323. //查询同个病人同个药品同个规格是否已存在
  324. _, errcode := service.GetSelfMedicalByDrugName(drug_name, drug_spec, patient_id)
  325. if errcode == gorm.ErrRecordNotFound {
  326. err := service.CreateSelfMedical(&medical)
  327. fmt.Println(err)
  328. } else if errcode == nil {
  329. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  330. return
  331. }
  332. }
  333. returnData := make(map[string]interface{}, 0)
  334. returnData["msg"] = "ok"
  335. this.ServeSuccessJSON(returnData)
  336. return
  337. }
  338. func (this *SelfDrugApiController) GetCurrentOrgAllStaff() {
  339. adminUserInfo := this.GetAdminUserInfo()
  340. orgid := adminUserInfo.CurrentOrgId
  341. //fmt.Println(orgid)
  342. appId := adminUserInfo.CurrentAppId
  343. staff, err := service.GetCurrentOrgAllStaff(orgid, appId)
  344. if err != nil {
  345. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  346. return
  347. }
  348. this.ServeSuccessJSON(map[string]interface{}{
  349. "staff": staff,
  350. })
  351. }
  352. func (this *SelfDrugApiController) SaveStock() {
  353. timeLayout := "2006-01-02"
  354. loc, _ := time.LoadLocation("Local")
  355. start_time := this.GetString("start_time")
  356. fmt.Println("start_time", start_time)
  357. admin_user_id, _ := this.GetInt64("admin_user_id")
  358. fmt.Println("admin_user_id", admin_user_id)
  359. patient_id, _ := this.GetInt64("patient_id")
  360. dataBody := make(map[string]interface{}, 0)
  361. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  362. fmt.Println(err)
  363. stocks, _ := dataBody["stocks"].([]interface{})
  364. adminUserInfo := this.GetAdminUserInfo()
  365. orgId := adminUserInfo.CurrentOrgId
  366. for _, item := range stocks {
  367. items := item.(map[string]interface{})
  368. drug_name := items["drug_name"].(string)
  369. fmt.Println("drug_name", drug_name)
  370. drug_name_id := int64(items["drug_name_id"].(float64))
  371. fmt.Println("parient_id", drug_name_id)
  372. drug_spec := items["drug_spec"].(string)
  373. store_number := items["store_number"].(string)
  374. fmt.Println("store_number", store_number)
  375. storeNumber, _ := strconv.ParseInt(store_number, 10, 64)
  376. remarks := items["remarks"].(string)
  377. min_unit := items["min_unit"].(string)
  378. medic_id := int64(items["id"].(float64))
  379. timeStr := time.Now().Format("2006-01-02")
  380. timeArr := strings.Split(timeStr, "-")
  381. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  382. total = total + 1
  383. warehousing_in_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  384. number, _ := strconv.ParseInt(warehousing_in_order, 10, 64)
  385. number = number + total
  386. warehousing_in_order = "RKD" + strconv.FormatInt(number, 10)
  387. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  388. stock := models.XtSelfStock{
  389. DrugName: drug_name,
  390. DrugNameId: drug_name_id,
  391. DrugSpec: drug_spec,
  392. StoreNumber: storeNumber,
  393. Remarks: remarks,
  394. AdminUserId: admin_user_id,
  395. StorckTime: theTime.Unix(),
  396. CreatedTime: time.Now().Unix(),
  397. Status: 1,
  398. UserOrgId: orgId,
  399. StockInNumber: warehousing_in_order,
  400. PatientId: patient_id,
  401. MinUnit: min_unit,
  402. StorageMode: 1,
  403. MedicId: medic_id,
  404. }
  405. err := service.CreateStock(&stock)
  406. fmt.Println("err", err)
  407. }
  408. returnData := make(map[string]interface{}, 0)
  409. returnData["msg"] = "ok"
  410. this.ServeSuccessJSON(returnData)
  411. return
  412. }
  413. func (this *SelfDrugApiController) SaveOutStock() {
  414. timeLayout := "2006-01-02"
  415. loc, _ := time.LoadLocation("Local")
  416. start_time := this.GetString("start_time")
  417. admin_user_id, _ := this.GetInt64("admin_user_id")
  418. patient_id, _ := this.GetInt64("patient_id")
  419. dataBody := make(map[string]interface{}, 0)
  420. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  421. fmt.Println(err)
  422. outStocks, _ := dataBody["outStocks"].([]interface{})
  423. adminUserInfo := this.GetAdminUserInfo()
  424. orgId := adminUserInfo.CurrentOrgId
  425. for _, item := range outStocks {
  426. items := item.(map[string]interface{})
  427. drug_name := items["drug_name"].(string)
  428. drug_name_id := int64(items["drug_name_id"].(float64))
  429. drug_spec := items["drug_spec"].(string)
  430. outstore_number := items["outstore_number"].(string)
  431. outStoreNumber, _ := strconv.ParseInt(outstore_number, 10, 64)
  432. remarks := items["remarks"].(string)
  433. medic_id := int64(items["id"].(float64))
  434. timeStr := time.Now().Format("2006-01-02")
  435. timeArr := strings.Split(timeStr, "-")
  436. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  437. total = total + 1
  438. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  439. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  440. number = number + total
  441. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  442. fmt.Println(remarks)
  443. fmt.Println(items)
  444. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  445. stock := models.XtSelfOutStock{
  446. DrugName: drug_name,
  447. DrugNameId: drug_name_id,
  448. DrugSpec: drug_spec,
  449. OutstoreNumber: outStoreNumber,
  450. Remarks: remarks,
  451. AdminUserId: admin_user_id,
  452. StorckTime: theTime.Unix(),
  453. CreatedTime: time.Now().Unix(),
  454. Status: 1,
  455. UserOrgId: orgId,
  456. StockOutNumber: warehousing_out_order,
  457. PatientId: patient_id,
  458. ExitMode: 1,
  459. MedicId: medic_id,
  460. }
  461. err := service.CreateOutStock(&stock)
  462. fmt.Println("err", err)
  463. }
  464. returnData := make(map[string]interface{}, 0)
  465. returnData["msg"] = "ok"
  466. this.ServeSuccessJSON(returnData)
  467. return
  468. }
  469. func (this *SelfDrugApiController) DeleteDrugById() {
  470. id, _ := this.GetInt64("id")
  471. drug_name := this.GetString("drug_name")
  472. adminUserInfo := this.GetAdminUserInfo()
  473. orgId := adminUserInfo.CurrentOrgId
  474. _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
  475. if errcode == gorm.ErrRecordNotFound {
  476. service.DeleteDrugName(id)
  477. returnData := make(map[string]interface{}, 0)
  478. returnData["msg"] = "ok"
  479. this.ServeSuccessJSON(returnData)
  480. } else if errcode == nil {
  481. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  482. return
  483. }
  484. }
  485. func (this *SelfDrugApiController) SaveRadio() {
  486. radio, _ := this.GetInt64("radio")
  487. adminUserInfo := this.GetAdminUserInfo()
  488. orgId := adminUserInfo.CurrentOrgId
  489. drugSet := models.XtDrugSet{
  490. DrugStart: radio,
  491. UserOrgId: orgId,
  492. Status: 1,
  493. CreatedTime: time.Now().Unix(),
  494. }
  495. _, errcode := service.GetDrugSetByUserOrgId(orgId)
  496. if errcode == gorm.ErrRecordNotFound {
  497. err := service.SaveRadio(&drugSet)
  498. if err != nil {
  499. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  500. return
  501. }
  502. this.ServeSuccessJSON(map[string]interface{}{
  503. "drugSet": drugSet,
  504. })
  505. } else if errcode == nil {
  506. err := service.UpdateDrugSet(&drugSet, orgId)
  507. if err != nil {
  508. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  509. return
  510. }
  511. this.ServeSuccessJSON(map[string]interface{}{
  512. "drugSet": drugSet,
  513. })
  514. }
  515. }
  516. func (this *SelfDrugApiController) DeleteDrugStand() {
  517. id, _ := this.GetInt64("id")
  518. name := this.GetString("name")
  519. adminUserInfo := this.GetAdminUserInfo()
  520. orgId := adminUserInfo.CurrentOrgId
  521. _, errcode := service.GetMedicalsByName(orgId, name)
  522. if errcode == gorm.ErrRecordNotFound {
  523. err := service.DeleteDrugStand(id)
  524. fmt.Println(err)
  525. returnData := make(map[string]interface{}, 0)
  526. returnData["msg"] = "ok"
  527. this.ServeSuccessJSON(returnData)
  528. } else if errcode == nil {
  529. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  530. return
  531. }
  532. }
  533. func (this *SelfDrugApiController) GetStockList() {
  534. patientid, _ := this.GetInt64("id")
  535. start_time := this.GetString("start_time")
  536. fmt.Println("开始时间", start_time)
  537. timeLayout := "2006-01-02"
  538. loc, _ := time.LoadLocation("Local")
  539. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  540. startimeUnix := theTime.Unix()
  541. keyword := this.GetString("keyword")
  542. fmt.Println("keyword", keyword)
  543. adminUserInfo := this.GetAdminUserInfo()
  544. orgId := adminUserInfo.CurrentOrgId
  545. //获取
  546. medicalList, _ := service.GetMedicalList(patientid, orgId, keyword)
  547. //统计总数量
  548. stocklist, err := service.GetStockList(patientid, startimeUnix, keyword, orgId)
  549. //统计出库数量
  550. outStocklist, err := service.GetOutStockList(patientid, startimeUnix, keyword, orgId)
  551. //统计该病人时间段内出库条数
  552. outList, err := service.GetTotalOutStockList(patientid, startimeUnix, keyword, orgId)
  553. if err != nil {
  554. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  555. return
  556. }
  557. this.ServeSuccessJSON(map[string]interface{}{
  558. "medicalList": medicalList,
  559. "stocklist": stocklist,
  560. "outStocklist": outStocklist,
  561. "outList": outList,
  562. })
  563. }
  564. func (this *SelfDrugApiController) DeleteDrugName() {
  565. drug_name := this.GetString("drugname")
  566. patient_id, _ := this.GetInt64("patientid")
  567. //查询该药品是否出库
  568. stocklist, _ := service.GetStockOutDetail(drug_name, patient_id)
  569. if len(stocklist) == 0 {
  570. //删除该药品
  571. service.DeleteDrugStockNumber(drug_name, patient_id)
  572. returnData := make(map[string]interface{}, 0)
  573. returnData["msg"] = "ok"
  574. this.ServeSuccessJSON(returnData)
  575. } else {
  576. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  577. return
  578. }
  579. }
  580. func (this *SelfDrugApiController) GetDrugDetail() {
  581. timeLayout := "2006-01-02"
  582. loc, _ := time.LoadLocation("Local")
  583. drug_name := this.GetString("drug_name")
  584. drug_spec := this.GetString("drug_spec")
  585. start_time := this.GetString("start_time")
  586. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  587. end_time := this.GetString("end_time")
  588. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  589. patient_id, _ := this.GetInt64("patient_id")
  590. adminUserInfo := this.GetAdminUserInfo()
  591. orgId := adminUserInfo.CurrentOrgId
  592. //查询入库明细
  593. stockDetail, err := service.GetStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
  594. //查询出库明细
  595. outStockDetail, err := service.GetOutStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
  596. if err != nil {
  597. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  598. return
  599. }
  600. this.ServeSuccessJSON(map[string]interface{}{
  601. "stockDetail": stockDetail,
  602. "outStockDetail": outStockDetail,
  603. })
  604. }
  605. func (this *SelfDrugApiController) GetAllPatientStockList() {
  606. timeLayout := "2006-01-02"
  607. loc, _ := time.LoadLocation("Local")
  608. drug_name := this.GetString("drug_name")
  609. drug_spec := this.GetString("drug_spec")
  610. start_time := this.GetString("start_time")
  611. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  612. startUnix := theTime.Unix()
  613. end_time := this.GetString("end_time")
  614. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  615. endTimeUnix := endTimes.Unix()
  616. keywords := this.GetString("search_input")
  617. adminUserInfo := this.GetAdminUserInfo()
  618. orgId := adminUserInfo.CurrentOrgId
  619. //入库
  620. stocklist, err := service.GetAllPatientStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
  621. //出库
  622. outStockList, err := service.GetAllPatientOutStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
  623. if err != nil {
  624. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  625. return
  626. }
  627. this.ServeSuccessJSON(map[string]interface{}{
  628. "stocklist": stocklist,
  629. "outStockList": outStockList,
  630. })
  631. }
  632. func (this *SelfDrugApiController) GetDrugDataByPatientId() {
  633. patient_id, _ := this.GetInt64("patient_id")
  634. fmt.Println("patient_id", patient_id)
  635. medicalList, err := service.GetDrugDataByPatientId(patient_id)
  636. if err != nil {
  637. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  638. return
  639. }
  640. this.ServeSuccessJSON(map[string]interface{}{
  641. "medicalList": medicalList,
  642. })
  643. }
  644. func (this *SelfDrugApiController) GetSelfMedicalList() {
  645. patient_id, _ := this.GetInt64("patient_id")
  646. adminUserInfo := this.GetAdminUserInfo()
  647. orgId := adminUserInfo.CurrentOrgId
  648. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  649. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(orgId)
  650. drugList, _ := service.GetAllBaseDrugLibList(orgId)
  651. privateDrugList, _ := service.GetPrivateDrugList(patient_id, orgId)
  652. this.ServeSuccessJSON(map[string]interface{}{
  653. "base_drug_config": drugStockConfig,
  654. "private_drug_config": privateDrugConfig,
  655. "base_drug_list": drugList,
  656. "private_drug_list": privateDrugList,
  657. })
  658. ////查询是否开启药品库
  659. //config, _ := service.GetDruckStockConfig(orgId)
  660. //
  661. //fmt.Println("--------------------------",config.IsOpen)
  662. ////开启
  663. //if config.IsOpen == 1 {
  664. // //查询该机构下的药品库
  665. // drugName, _ := service.GetAllDrugName(orgId)
  666. //
  667. // //查询该机构是否开启自备药
  668. // medical, _ := service.GetSetSelfMedical(orgId)
  669. // fmt.Println("medical+++++++++++++++++",medical.DrugStart)
  670. // //开启
  671. // if medical.DrugStart == 1 {
  672. // list, err := service.GetSelfMedicalList(patient_id)
  673. // if err != nil {
  674. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  675. // return
  676. // }
  677. // this.ServeSuccessJSON(map[string]interface{}{
  678. // "medicalList": list,
  679. // "drugName": drugName,
  680. // })
  681. // } else {
  682. // this.ServeSuccessJSON(map[string]interface{}{
  683. // "drugName": drugName,
  684. // })
  685. // }
  686. //}
  687. }
  688. func (this *SelfDrugApiController) GetDrugDescByDrugName() {
  689. drug_name := this.GetString("drug_name")
  690. patient_id, _ := this.GetInt64("patient_id")
  691. way, _ := this.GetInt64("way")
  692. adminUserInfo := this.GetAdminUserInfo()
  693. orgId := adminUserInfo.CurrentOrgId
  694. drug_id, _ := this.GetInt64("id")
  695. //从基础库查询
  696. if way == 1 {
  697. //查询基础库数据
  698. medcal, err := service.GetBaseMedcal(drug_name, orgId)
  699. //统计入库数量
  700. countInfo, err := service.GetTotalBaseMedicalCount(drug_id, orgId)
  701. //统计出库数量
  702. countout, err := service.GetTotalBaseMedicalCountOut(drug_id, orgId)
  703. if err != nil {
  704. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  705. return
  706. }
  707. this.ServeSuccessJSON(map[string]interface{}{
  708. "drugspec": medcal,
  709. "countInfo": countInfo,
  710. "countout": countout,
  711. })
  712. }
  713. //从自备药库查询
  714. if way == 2 {
  715. drugspec, err := service.GetDrugDescByDrugName(drug_name, patient_id, orgId)
  716. if err != nil {
  717. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  718. return
  719. }
  720. this.ServeSuccessJSON(map[string]interface{}{
  721. "drugspec": drugspec,
  722. })
  723. }
  724. }
  725. func (this *SelfDrugApiController) GetDrugSet() {
  726. adminUserInfo := this.GetAdminUserInfo()
  727. orgId := adminUserInfo.CurrentOrgId
  728. drugSet, err := service.GetDrugSet(orgId)
  729. if err != nil {
  730. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  731. return
  732. }
  733. this.ServeSuccessJSON(map[string]interface{}{
  734. "drugSet": drugSet,
  735. })
  736. }
  737. func (this *SelfDrugApiController) GetAllMedicalList() {
  738. adminUserInfo := this.GetAdminUserInfo()
  739. orgId := adminUserInfo.CurrentOrgId
  740. list, err := service.GetAllMedicalList(orgId)
  741. if err != nil {
  742. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  743. return
  744. }
  745. this.ServeSuccessJSON(map[string]interface{}{
  746. "drugName": list,
  747. })
  748. }
  749. func (this *SelfDrugApiController) GetStandName() {
  750. name := this.GetString("name")
  751. adminUserInfo := this.GetAdminUserInfo()
  752. orgId := adminUserInfo.CurrentOrgId
  753. rullerlist, err := service.GetRulleName(orgId, name)
  754. if err != nil {
  755. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  756. return
  757. }
  758. this.ServeSuccessJSON(map[string]interface{}{
  759. "rullerlist": rullerlist,
  760. })
  761. }
  762. func (this *SelfDrugApiController) GetRullerList() {
  763. id, _ := this.GetInt64("id")
  764. adminUserInfo := this.GetAdminUserInfo()
  765. orgId := adminUserInfo.CurrentOrgId
  766. rullerList, err := service.GetRulleList(orgId, id)
  767. if err != nil {
  768. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  769. return
  770. }
  771. this.ServeSuccessJSON(map[string]interface{}{
  772. "rullerlist": rullerList,
  773. })
  774. }
  775. func (this *SelfDrugApiController) DeleteDrugNameById() {
  776. id, _ := this.GetInt64("id")
  777. drug_name := this.GetString("drug_name")
  778. adminUserInfo := this.GetAdminUserInfo()
  779. orgId := adminUserInfo.CurrentOrgId
  780. _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
  781. if errcode == gorm.ErrRecordNotFound {
  782. service.DeleteDrugNameById(id)
  783. returnData := make(map[string]interface{}, 0)
  784. returnData["msg"] = "ok"
  785. this.ServeSuccessJSON(returnData)
  786. } else if errcode == nil {
  787. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  788. return
  789. }
  790. }
  791. func (this *SelfDrugApiController) GetPatientDetail() {
  792. id, _ := this.GetInt64("id")
  793. adminUserInfo := this.GetAdminUserInfo()
  794. patientDetail, err := service.GetPatientDetail(id, adminUserInfo.CurrentOrgId)
  795. if err != nil {
  796. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  797. return
  798. }
  799. this.ServeSuccessJSON(map[string]interface{}{
  800. "patientDetail": patientDetail,
  801. })
  802. }
  803. //func (this *SelfDrugApiController) ToPatientDetail() {
  804. //
  805. // keyword := this.GetString("keyword")
  806. // adminUser := this.GetAdminUserInfo()
  807. // orgId := adminUser.CurrentOrgId
  808. // patient, err := service.ToSeachPatient(keyword, orgId)
  809. // if err != nil {
  810. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  811. // return
  812. // }
  813. // this.ServeSuccessJSON(map[string]interface{}{
  814. // "patient": patient,
  815. // })
  816. //}
  817. func (this *SelfDrugApiController) GetSelfStockQuery() {
  818. adminUserInfo := this.GetAdminUserInfo()
  819. orgId := adminUserInfo.CurrentOrgId
  820. type_name, _ := this.GetInt64("type_name")
  821. keywords := this.GetString("keywords")
  822. timeLayout := "2006-01-02"
  823. loc, _ := time.LoadLocation("Local")
  824. start_time := this.GetString("start_time")
  825. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  826. startUnix := theTime.Unix()
  827. end_time := this.GetString("end_time")
  828. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  829. endTimeUnix := endTimes.Unix()
  830. page, _ := this.GetInt64("page")
  831. limit, _ := this.GetInt64("limit")
  832. //统计入库数量
  833. stockQuery, total, err := service.GetSelfStockQuery(type_name, keywords, startUnix, endTimeUnix, orgId, limit, page)
  834. //统计出库数量
  835. stockOutQuery, err := service.GetSelfOutStockQuery(startUnix, endTimeUnix, orgId)
  836. if err != nil {
  837. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  838. return
  839. }
  840. this.ServeSuccessJSON(map[string]interface{}{
  841. "stockQuery": stockQuery,
  842. "total": total,
  843. "stockOutQuery": stockOutQuery,
  844. })
  845. }
  846. func (this *SelfDrugApiController) PostSearchDrugWarehouseList() {
  847. keyword := this.GetString("keyword")
  848. storehouse_id, _ := this.GetInt64("storehouse_id")
  849. orgId := this.GetAdminUserInfo().CurrentOrgId
  850. list, err := service.PostSearchDrugWarehouseList(keyword, orgId, storehouse_id)
  851. manufacturerList, err := service.GetAllManufacturerList(orgId)
  852. dealerList, err := service.GetAllDealerList(orgId)
  853. if err != nil {
  854. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  855. return
  856. }
  857. this.ServeSuccessJSON(map[string]interface{}{
  858. "list": list,
  859. "manufacturerList": manufacturerList,
  860. "dealerList": dealerList,
  861. })
  862. }
  863. func (this *SelfDrugApiController) SaveDrugPrice() {
  864. timeLayout := "2006-01-02"
  865. loc, _ := time.LoadLocation("Local")
  866. dataBody := make(map[string]interface{}, 0)
  867. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  868. fmt.Println(err)
  869. tableData, _ := dataBody["tableData"].([]interface{})
  870. fmt.Println("999939433443", tableData)
  871. if len(tableData) > 0 {
  872. for _, item := range tableData {
  873. items := item.(map[string]interface{})
  874. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  875. utils.ErrorLog("drug_name")
  876. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  877. return
  878. }
  879. drug_name := items["drug_name"].(string)
  880. fmt.Println("drug_aname23232323232", drug_name)
  881. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  882. utils.ErrorLog("drug_name")
  883. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  884. return
  885. }
  886. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  887. utils.ErrorLog("retail_price")
  888. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  889. return
  890. }
  891. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  892. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  893. utils.ErrorLog("warehousing_order")
  894. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  895. return
  896. }
  897. warehousing_order := items["warehousing_order"].(string)
  898. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  899. utils.ErrorLog("number")
  900. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  901. return
  902. }
  903. number := items["number"].(string)
  904. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  905. utils.ErrorLog("dealer")
  906. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  907. return
  908. }
  909. dealer := items["dealer"].(string)
  910. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  911. utils.ErrorLog("manufacturer")
  912. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  913. return
  914. }
  915. manufacturer := items["manufacturer"].(string)
  916. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  917. utils.ErrorLog("specification_name")
  918. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  919. return
  920. }
  921. specification_name := items["specification_name"].(string)
  922. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  923. utils.ErrorLog("remark")
  924. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  925. return
  926. }
  927. remark := items["remark"].(string)
  928. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  929. utils.ErrorLog("warehousing_unit")
  930. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  931. return
  932. }
  933. warehousing_unit := items["warehousing_unit"].(string)
  934. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  935. utils.ErrorLog("last_price")
  936. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  937. return
  938. }
  939. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  940. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  941. utils.ErrorLog("new_price")
  942. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  943. return
  944. }
  945. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  946. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  947. utils.ErrorLog("drug_id")
  948. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  949. return
  950. }
  951. drug_id := int64(items["drug_id"].(float64))
  952. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  953. utils.ErrorLog("start_time")
  954. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  955. return
  956. }
  957. var startTime int64
  958. start_time := items["start_time"].(string)
  959. if len(start_time) > 0 {
  960. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  961. if err != nil {
  962. fmt.Println(err)
  963. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  964. return
  965. }
  966. startTime = theTime.Unix()
  967. }
  968. orgId := this.GetAdminUserInfo().CurrentOrgId
  969. Creater := this.GetAdminUserInfo().AdminUser.Id
  970. drugAdjust := models.XtDrugAdjustPrice{
  971. DrugName: drug_name,
  972. SpecificationName: specification_name,
  973. WarehousingUnit: warehousing_unit,
  974. LastPrice: last_price,
  975. RetailPrice: retail_price,
  976. NewPrice: new_price,
  977. Manufacturer: manufacturer,
  978. Dealer: dealer,
  979. Remark: remark,
  980. DrugId: drug_id,
  981. UserOrgId: orgId,
  982. Ctime: time.Now().Unix(),
  983. Mtime: 0,
  984. Status: 1,
  985. WarehousingOrder: warehousing_order,
  986. Number: number,
  987. StartTime: startTime,
  988. Creater: Creater,
  989. Checker: 0,
  990. CheckerStatus: 2,
  991. CheckerTime: 0,
  992. }
  993. err := service.CreateDrugPrice(drugAdjust)
  994. fmt.Println(err)
  995. }
  996. }
  997. returnData := make(map[string]interface{}, 0)
  998. returnData["msg"] = "ok"
  999. this.ServeSuccessJSON(returnData)
  1000. return
  1001. }
  1002. func (this *SelfDrugApiController) GetDrugPriceList() {
  1003. timeLayout := "2006-01-02"
  1004. loc, _ := time.LoadLocation("Local")
  1005. dataBody := make(map[string]interface{}, 0)
  1006. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1007. fmt.Println(err)
  1008. orgId := this.GetAdminUserInfo().CurrentOrgId
  1009. keyword := this.GetString("keyword")
  1010. start_time := this.GetString("start_time")
  1011. end_time := this.GetString("end_time")
  1012. var startTime int64
  1013. if len(start_time) > 0 {
  1014. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1015. if err != nil {
  1016. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1017. return
  1018. }
  1019. startTime = theTime.Unix()
  1020. }
  1021. var endTime int64
  1022. if len(end_time) > 0 {
  1023. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1024. if err != nil {
  1025. utils.ErrorLog(err.Error())
  1026. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1027. return
  1028. }
  1029. endTime = theTime.Unix()
  1030. }
  1031. limit, _ := this.GetInt64("limit")
  1032. page, _ := this.GetInt64("page")
  1033. list, total, err := service.GetDrugPriceList(startTime, endTime, orgId, keyword, limit, page)
  1034. doctorList, err := service.GetAllDoctorThree(orgId)
  1035. if err != nil {
  1036. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1037. return
  1038. }
  1039. this.ServeSuccessJSON(map[string]interface{}{
  1040. "total": total,
  1041. "list": list,
  1042. "doctorList": doctorList,
  1043. })
  1044. }
  1045. func (this *SelfDrugApiController) SaveCheckDrugPrice() {
  1046. timeLayout := "2006-01-02"
  1047. loc, _ := time.LoadLocation("Local")
  1048. dataBody := make(map[string]interface{}, 0)
  1049. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1050. fmt.Println(err)
  1051. idstr := this.GetString("ids")
  1052. ids := strings.Split(idstr, ",")
  1053. check_time := this.GetString("check_time")
  1054. var checkTime int64
  1055. if len(check_time) > 0 {
  1056. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1057. if err != nil {
  1058. fmt.Println(err)
  1059. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1060. return
  1061. }
  1062. checkTime = theTime.Unix()
  1063. }
  1064. checker, _ := this.GetInt64("checker")
  1065. adjustPrice := models.XtDrugAdjustPrice{
  1066. Checker: checker,
  1067. CheckerStatus: 1,
  1068. CheckerTime: checkTime,
  1069. }
  1070. err = service.UpdateDrugAdjuestPrice(ids, adjustPrice)
  1071. fmt.Println("err", err)
  1072. list, _ := service.GetDrugAdjuestPrice(ids)
  1073. for _, item := range list {
  1074. drug := models.BaseDrugLib{
  1075. RetailPrice: item.NewPrice,
  1076. LastPrice: item.NewPrice,
  1077. }
  1078. service.UpdateBaseDrugOne(drug, item.DrugId)
  1079. }
  1080. this.ServeSuccessJSON(map[string]interface{}{
  1081. "adjustPrice": adjustPrice,
  1082. })
  1083. }
  1084. func (this *SelfDrugApiController) SaveDrugDamage() {
  1085. timeLayout := "2006-01-02"
  1086. loc, _ := time.LoadLocation("Local")
  1087. dataBody := make(map[string]interface{}, 0)
  1088. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1089. fmt.Println(err)
  1090. tableData, _ := dataBody["tableData"].([]interface{})
  1091. fmt.Println("999939433443", tableData)
  1092. if len(tableData) > 0 {
  1093. for _, item := range tableData {
  1094. items := item.(map[string]interface{})
  1095. drug_name := items["drug_name"].(string)
  1096. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  1097. utils.ErrorLog("drug_name")
  1098. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1099. return
  1100. }
  1101. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1102. utils.ErrorLog("retail_price")
  1103. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1104. return
  1105. }
  1106. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1107. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  1108. utils.ErrorLog("warehousing_order")
  1109. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1110. return
  1111. }
  1112. warehousing_order := items["warehousing_order"].(string)
  1113. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  1114. utils.ErrorLog("number")
  1115. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1116. return
  1117. }
  1118. number := items["number"].(string)
  1119. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  1120. utils.ErrorLog("dealer")
  1121. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1122. return
  1123. }
  1124. dealer := items["dealer"].(string)
  1125. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  1126. utils.ErrorLog("manufacturer")
  1127. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1128. return
  1129. }
  1130. manufacturer := items["manufacturer"].(string)
  1131. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  1132. utils.ErrorLog("specification_name")
  1133. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1134. return
  1135. }
  1136. specification_name := items["specification_name"].(string)
  1137. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  1138. utils.ErrorLog("remark")
  1139. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1140. return
  1141. }
  1142. remark := items["remark"].(string)
  1143. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  1144. utils.ErrorLog("warehousing_unit")
  1145. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1146. return
  1147. }
  1148. warehousing_unit := items["warehousing_unit"].(string)
  1149. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  1150. utils.ErrorLog("last_price")
  1151. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1152. return
  1153. }
  1154. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  1155. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  1156. utils.ErrorLog("count")
  1157. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1158. return
  1159. }
  1160. count := int64(items["count"].(float64))
  1161. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  1162. utils.ErrorLog("new_price")
  1163. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1164. return
  1165. }
  1166. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  1167. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1168. utils.ErrorLog("drug_id")
  1169. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1170. return
  1171. }
  1172. drug_id := int64(items["drug_id"].(float64))
  1173. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  1174. utils.ErrorLog("start_time")
  1175. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1176. return
  1177. }
  1178. var startTime int64
  1179. start_time := items["start_time"].(string)
  1180. if len(start_time) > 0 {
  1181. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1182. if err != nil {
  1183. fmt.Println(err)
  1184. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1185. return
  1186. }
  1187. startTime = theTime.Unix()
  1188. }
  1189. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  1190. utils.ErrorLog("warehousing_info_id")
  1191. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1192. return
  1193. }
  1194. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  1195. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  1196. utils.ErrorLog("expiry_date")
  1197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1198. return
  1199. }
  1200. expiry_date := int64(items["expiry_date"].(float64))
  1201. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  1202. utils.ErrorLog("product_date")
  1203. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1204. return
  1205. }
  1206. product_date := int64(items["product_date"].(float64))
  1207. if items["drug_origin_place"] == nil || reflect.TypeOf(items["drug_origin_place"]).String() != "string" {
  1208. utils.ErrorLog("drug_origin_place")
  1209. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1210. return
  1211. }
  1212. drug_origin_place := items["drug_origin_place"].(string)
  1213. orgId := this.GetAdminUserInfo().CurrentOrgId
  1214. Creater := this.GetAdminUserInfo().AdminUser.Id
  1215. if items["stock_max_number"] == nil || reflect.TypeOf(items["stock_max_number"]).String() != "float64" {
  1216. utils.ErrorLog("stock_max_number")
  1217. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1218. return
  1219. }
  1220. stock_max_number := int64(items["stock_max_number"].(float64))
  1221. if items["stock_min_number"] == nil || reflect.TypeOf(items["stock_min_number"]).String() != "float64" {
  1222. utils.ErrorLog("stock_min_number")
  1223. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1224. return
  1225. }
  1226. stock_min_number := int64(items["stock_min_number"].(float64))
  1227. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "string" {
  1228. utils.ErrorLog("total")
  1229. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1230. return
  1231. }
  1232. total := items["total"].(string)
  1233. drugDamage := models.XtDrugDamage{
  1234. DrugName: drug_name,
  1235. SpecificationName: specification_name,
  1236. WarehousingUnit: warehousing_unit,
  1237. Count: count,
  1238. LastPrice: last_price,
  1239. RetailPrice: retail_price,
  1240. NewPrice: new_price,
  1241. Manufacturer: manufacturer,
  1242. Dealer: dealer,
  1243. Remark: remark,
  1244. DrugId: drug_id,
  1245. UserOrgId: orgId,
  1246. Ctime: time.Now().Unix(),
  1247. Mtime: 0,
  1248. Status: 1,
  1249. WarehousingOrder: warehousing_order,
  1250. Number: number,
  1251. StartTime: startTime,
  1252. Creater: Creater,
  1253. Checker: 0,
  1254. CheckerStatus: 2,
  1255. CheckerTime: 0,
  1256. ExpiryDate: expiry_date,
  1257. ProductDate: product_date,
  1258. WarehousingInfoId: warehousing_info_id,
  1259. DrugOriginPlace: drug_origin_place,
  1260. StockMaxNumber: stock_max_number,
  1261. StockMinNumber: stock_min_number,
  1262. Total: total,
  1263. }
  1264. err := service.CreateDrugDamage(drugDamage)
  1265. fmt.Println(err)
  1266. }
  1267. }
  1268. returnData := make(map[string]interface{}, 0)
  1269. returnData["msg"] = "ok"
  1270. this.ServeSuccessJSON(returnData)
  1271. }
  1272. func (this *SelfDrugApiController) GetDrugDamageList() {
  1273. timeLayout := "2006-01-02"
  1274. loc, _ := time.LoadLocation("Local")
  1275. dataBody := make(map[string]interface{}, 0)
  1276. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1277. fmt.Println(err)
  1278. orgId := this.GetAdminUserInfo().CurrentOrgId
  1279. keyword := this.GetString("keyword")
  1280. start_time := this.GetString("start_time")
  1281. end_time := this.GetString("end_time")
  1282. storehouse_id, _ := this.GetInt64("storehouse_id")
  1283. var startTime int64
  1284. if len(start_time) > 0 {
  1285. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1286. if err != nil {
  1287. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1288. return
  1289. }
  1290. startTime = theTime.Unix()
  1291. }
  1292. var endTime int64
  1293. if len(end_time) > 0 {
  1294. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1295. if err != nil {
  1296. utils.ErrorLog(err.Error())
  1297. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1298. return
  1299. }
  1300. endTime = theTime.Unix()
  1301. }
  1302. limit, _ := this.GetInt64("limit")
  1303. page, _ := this.GetInt64("page")
  1304. list, total, err := service.GetDrugDamageList(startTime, endTime, orgId, keyword, limit, page, storehouse_id)
  1305. damagelist, _ := service.GetDrugDamageByOrgId(orgId)
  1306. doctorList, err := service.GetAllDoctorThree(orgId)
  1307. houseList, _ := service.GetAllStoreHouseList(orgId)
  1308. if err != nil {
  1309. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1310. return
  1311. }
  1312. this.ServeSuccessJSON(map[string]interface{}{
  1313. "total": total,
  1314. "list": list,
  1315. "damagelist": damagelist,
  1316. "doctorList": doctorList,
  1317. "houseList": houseList,
  1318. })
  1319. }
  1320. func (this *SelfDrugApiController) SaveDrugDamagePrice() {
  1321. timeLayout := "2006-01-02"
  1322. loc, _ := time.LoadLocation("Local")
  1323. dataBody := make(map[string]interface{}, 0)
  1324. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1325. fmt.Println(err)
  1326. idstr := this.GetString("ids")
  1327. ids := strings.Split(idstr, ",")
  1328. check_time := this.GetString("check_time")
  1329. var checkTime int64
  1330. if len(check_time) > 0 {
  1331. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1332. if err != nil {
  1333. fmt.Println(err)
  1334. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1335. return
  1336. }
  1337. checkTime = theTime.Unix()
  1338. }
  1339. checker, _ := this.GetInt64("checker")
  1340. damage := models.XtDrugDamage{
  1341. Checker: checker,
  1342. CheckerStatus: 1,
  1343. CheckerTime: checkTime,
  1344. }
  1345. err = service.UpdateDrugDamage(ids, damage)
  1346. fmt.Println(err)
  1347. list, _ := service.GetDrugDamage(ids)
  1348. ctime := time.Now().Unix()
  1349. adminUserInfo := this.GetAdminUserInfo()
  1350. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  1351. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  1352. var manufacturer_id int64
  1353. var dealer_id int64
  1354. timeStr := time.Now().Format("2006-01-02")
  1355. timeArr := strings.Split(timeStr, "-")
  1356. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1357. total = total + 1
  1358. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1359. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1360. number = number + total
  1361. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1362. operation_time := time.Now().Unix()
  1363. creater := adminUserInfo.AdminUser.Id
  1364. warehouseOut := models.DrugWarehouseOut{
  1365. WarehouseOutOrderNumber: warehousing_out_order,
  1366. OperationTime: operation_time,
  1367. OrgId: adminUserInfo.CurrentOrgId,
  1368. Creater: creater,
  1369. Ctime: ctime,
  1370. Status: 1,
  1371. WarehouseOutTime: time.Now().Unix(),
  1372. Type: 1,
  1373. }
  1374. service.AddSigleDrugWarehouseOut(&warehouseOut)
  1375. for _, item := range list {
  1376. for _, it := range manufacturerList {
  1377. if item.Manufacturer == it.ManufacturerName {
  1378. manufacturer_id = it.ID
  1379. }
  1380. }
  1381. for _, its := range dealerList {
  1382. if its.DealerName == item.Dealer {
  1383. dealer_id = its.ID
  1384. }
  1385. }
  1386. warehouseOutInfo := models.XtDrugWarehouseOutInfo{
  1387. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1388. WarehouseOutId: warehouseOut.ID,
  1389. DrugId: item.DrugId,
  1390. Count: item.Count,
  1391. Price: item.RetailPrice,
  1392. Status: 1,
  1393. Ctime: ctime,
  1394. Remark: item.Remark,
  1395. OrgId: adminUserInfo.CurrentOrgId,
  1396. Type: 1,
  1397. Manufacturer: manufacturer_id,
  1398. Dealer: dealer_id,
  1399. RetailPrice: item.RetailPrice,
  1400. CountUnit: item.WarehousingUnit,
  1401. ExpiryDate: item.ExpiryDate,
  1402. ProductDate: item.ProductDate,
  1403. Number: item.Number,
  1404. BatchNumber: item.BatchNumber,
  1405. IsSys: 0,
  1406. WarehouseInfoId: item.WarehousingInfoId,
  1407. }
  1408. drugflow := models.DrugFlow{
  1409. WarehouseOutId: warehouseOut.ID,
  1410. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1411. DrugId: item.DrugId,
  1412. Number: item.Number,
  1413. ProductDate: item.ProductDate,
  1414. ExpireDate: item.ExpiryDate,
  1415. Count: item.Count,
  1416. Price: item.RetailPrice,
  1417. Status: 1,
  1418. Ctime: ctime,
  1419. UserOrgId: adminUserInfo.CurrentOrgId,
  1420. Manufacturer: manufacturer_id,
  1421. Dealer: dealer_id,
  1422. BatchNumber: item.BatchNumber,
  1423. MaxUnit: item.WarehousingUnit,
  1424. ConsumableType: 5,
  1425. IsEdit: 1,
  1426. Creator: adminUserInfo.AdminUser.Id,
  1427. IsSys: 0,
  1428. }
  1429. service.CreateWareHouseOutInfo(&warehouseOutInfo)
  1430. service.CreateDrugFlowOne(drugflow)
  1431. info, _ := service.GetDrugByWarehouseInfo(item.WarehousingInfoId)
  1432. //扣减库存
  1433. warehouseInfo := models.XtDrugWarehouseInfo{
  1434. StockMaxNumber: info.StockMaxNumber - info.StockMaxNumber,
  1435. }
  1436. service.UpdateDrugWarehouseingInfo(item.WarehousingInfoId, warehouseInfo)
  1437. }
  1438. this.ServeSuccessJSON(map[string]interface{}{
  1439. "damage": damage,
  1440. })
  1441. }
  1442. func (this *SelfDrugApiController) GetDrugModifyPrice() {
  1443. id, _ := this.GetInt64("id")
  1444. detail, err := service.GetDrugModifyPrice(id)
  1445. fmt.Println(err)
  1446. this.ServeSuccessJSON(map[string]interface{}{
  1447. "detail": detail,
  1448. })
  1449. }
  1450. func (this *SelfDrugApiController) ModifyDrugPrice() {
  1451. drug_name := this.GetString("drug_name")
  1452. specification_name := this.GetString("specification_name")
  1453. warehousing_unit := this.GetString("warehousing_unit")
  1454. manufacturer := this.GetString("manufacturer")
  1455. number := this.GetString("number")
  1456. retailPrice := this.GetString("retail_price")
  1457. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  1458. newPrice := this.GetString("new_price")
  1459. new_price, _ := strconv.ParseFloat(newPrice, 64)
  1460. count, _ := this.GetInt64("count")
  1461. remark := this.GetString("remark")
  1462. id, _ := this.GetInt64("id")
  1463. drug_id, _ := this.GetInt64("drug_id")
  1464. adjustPrice := models.XtDrugAdjustPrice{
  1465. DrugName: drug_name,
  1466. Count: count,
  1467. RetailPrice: retail_price,
  1468. NewPrice: new_price,
  1469. Remark: remark,
  1470. SpecificationName: specification_name,
  1471. WarehousingUnit: warehousing_unit,
  1472. Manufacturer: manufacturer,
  1473. Number: number,
  1474. DrugId: drug_id,
  1475. }
  1476. err := service.ModifyDrugPrice(id, adjustPrice)
  1477. fmt.Println(err)
  1478. this.ServeSuccessJSON(map[string]interface{}{
  1479. "adjustPrice": adjustPrice,
  1480. })
  1481. }
  1482. func (this *SelfDrugApiController) GetModifyPricePrint() {
  1483. ids := this.GetString("ids")
  1484. idsSplit := strings.Split(ids, ",")
  1485. list, err := service.GetModifyPricePrint(idsSplit)
  1486. fmt.Println(err)
  1487. this.ServeSuccessJSON(map[string]interface{}{
  1488. "list": list,
  1489. })
  1490. }
  1491. func (this *SelfDrugApiController) GetDrugDamageDetail() {
  1492. id, _ := this.GetInt64("id")
  1493. detail, _ := service.GetDrugDamageDetail(id)
  1494. this.ServeSuccessJSON(map[string]interface{}{
  1495. "detail": detail,
  1496. })
  1497. }
  1498. func (this *SelfDrugApiController) ModifyDrugDamage() {
  1499. id, _ := this.GetInt64("id")
  1500. drug_id, _ := this.GetInt64("drug_id")
  1501. drug_name := this.GetString("drug_name")
  1502. drug_origin_place := this.GetString("drug_origin_place")
  1503. lastPrice := this.GetString("last_price")
  1504. last_price, _ := strconv.ParseFloat(lastPrice, 64)
  1505. newPrice := this.GetString("new_price")
  1506. new_price, _ := strconv.ParseFloat(newPrice, 64)
  1507. manufacturer := this.GetString("manufacturer")
  1508. number := this.GetString("number")
  1509. retailPrice := this.GetString("retail_price")
  1510. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  1511. remark := this.GetString("remark")
  1512. count, _ := this.GetInt64("count")
  1513. warehousing_unit := this.GetString("warehousing_unit")
  1514. stock_max_number, _ := this.GetInt64("stock_max_number")
  1515. stock_min_number, _ := this.GetInt64("stock_min_number")
  1516. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  1517. damage := models.XtDrugDamage{
  1518. DrugName: drug_name,
  1519. SpecificationName: "",
  1520. WarehousingUnit: warehousing_unit,
  1521. Count: count,
  1522. LastPrice: last_price,
  1523. RetailPrice: retail_price,
  1524. NewPrice: new_price,
  1525. Manufacturer: manufacturer,
  1526. Dealer: "",
  1527. Remark: remark,
  1528. DrugId: drug_id,
  1529. Number: number,
  1530. StockMaxNumber: stock_max_number,
  1531. StockMinNumber: stock_min_number,
  1532. WarehousingInfoId: warehousing_info_id,
  1533. DrugOriginPlace: drug_origin_place,
  1534. }
  1535. err := service.ModifyDrugDamage(id, damage)
  1536. fmt.Println(err)
  1537. this.ServeSuccessJSON(map[string]interface{}{
  1538. "damage": damage,
  1539. })
  1540. }
  1541. func (this *SelfDrugApiController) DeleteDrugDamage() {
  1542. id, _ := this.GetInt64("id")
  1543. err := service.DeleteDrugDamage(id)
  1544. fmt.Println(err)
  1545. returnData := make(map[string]interface{}, 0)
  1546. returnData["msg"] = "ok"
  1547. this.ServeSuccessJSON(returnData)
  1548. }
  1549. func (this *SelfDrugApiController) GetDrugDamagePrint() {
  1550. idsSplit := this.GetString("ids")
  1551. ids := strings.Split(idsSplit, ",")
  1552. list, _ := service.GetDrugDamagePrint(ids)
  1553. this.ServeSuccessJSON(map[string]interface{}{
  1554. "list": list,
  1555. })
  1556. }
  1557. func (this *SelfDrugApiController) GetWarehoseInfoById() {
  1558. id, _ := this.GetInt64("id")
  1559. storehouse_id, _ := this.GetInt64("storehouse_id")
  1560. list, _ := service.GetWarehoseInfoById(id, storehouse_id)
  1561. this.ServeSuccessJSON(map[string]interface{}{
  1562. "list": list,
  1563. })
  1564. }
  1565. func (this *SelfDrugApiController) SaveDrugInventory() {
  1566. timeLayout := "2006-01-02"
  1567. loc, _ := time.LoadLocation("Local")
  1568. dataBody := make(map[string]interface{}, 0)
  1569. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1570. fmt.Println(err)
  1571. tableData, _ := dataBody["tableData"].([]interface{})
  1572. fmt.Println("999939433443", tableData)
  1573. if len(tableData) > 0 {
  1574. for _, item := range tableData {
  1575. items := item.(map[string]interface{})
  1576. drug_name := items["drug_name"].(string)
  1577. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  1578. utils.ErrorLog("drug_name")
  1579. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1580. return
  1581. }
  1582. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1583. utils.ErrorLog("retail_price")
  1584. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1585. return
  1586. }
  1587. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1588. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  1589. utils.ErrorLog("warehousing_order")
  1590. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1591. return
  1592. }
  1593. warehousing_order := items["warehousing_order"].(string)
  1594. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  1595. utils.ErrorLog("dealer")
  1596. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1597. return
  1598. }
  1599. dealer := items["dealer"].(string)
  1600. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  1601. utils.ErrorLog("manufacturer")
  1602. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1603. return
  1604. }
  1605. manufacturer := items["manufacturer"].(string)
  1606. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  1607. utils.ErrorLog("specification_name")
  1608. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1609. return
  1610. }
  1611. specification_name := items["specification_name"].(string)
  1612. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  1613. utils.ErrorLog("remark")
  1614. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1615. return
  1616. }
  1617. remark := items["remark"].(string)
  1618. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  1619. utils.ErrorLog("warehousing_unit")
  1620. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1621. return
  1622. }
  1623. warehousing_unit := items["warehousing_unit"].(string)
  1624. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  1625. utils.ErrorLog("last_price")
  1626. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1627. return
  1628. }
  1629. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  1630. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  1631. utils.ErrorLog("count")
  1632. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1633. return
  1634. }
  1635. count := int64(items["count"].(float64))
  1636. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  1637. utils.ErrorLog("new_price")
  1638. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1639. return
  1640. }
  1641. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  1642. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1643. utils.ErrorLog("drug_id")
  1644. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1645. return
  1646. }
  1647. drug_id := int64(items["drug_id"].(float64))
  1648. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  1649. utils.ErrorLog("start_time")
  1650. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1651. return
  1652. }
  1653. var startTime int64
  1654. start_time := items["start_time"].(string)
  1655. if len(start_time) > 0 {
  1656. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1657. if err != nil {
  1658. fmt.Println(err)
  1659. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1660. return
  1661. }
  1662. startTime = theTime.Unix()
  1663. }
  1664. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  1665. utils.ErrorLog("product_date")
  1666. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1667. return
  1668. }
  1669. product_date := int64(items["product_date"].(float64))
  1670. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  1671. utils.ErrorLog("expiry_date")
  1672. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1673. return
  1674. }
  1675. expiry_date := int64(items["expiry_date"].(float64))
  1676. orgId := this.GetAdminUserInfo().CurrentOrgId
  1677. Creater := this.GetAdminUserInfo().AdminUser.Id
  1678. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  1679. utils.ErrorLog("number")
  1680. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1681. return
  1682. }
  1683. numbers := items["number"].(string)
  1684. if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
  1685. utils.ErrorLog("warehouse_info_id")
  1686. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1687. return
  1688. }
  1689. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1690. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "string" {
  1691. utils.ErrorLog("total")
  1692. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1693. return
  1694. }
  1695. total := items["total"].(string)
  1696. drug_origin_place := items["drug_origin_place"].(string)
  1697. min_count := int64(items["min_count"].(float64))
  1698. min_unit := items["min_unit"].(string)
  1699. inventory := models.XtDrugInventory{
  1700. DrugName: drug_name,
  1701. SpecificationName: specification_name,
  1702. WarehousingUnit: warehousing_unit,
  1703. Count: count,
  1704. LastPrice: last_price,
  1705. RetailPrice: retail_price,
  1706. NewPrice: new_price,
  1707. Manufacturer: manufacturer,
  1708. Dealer: dealer,
  1709. Remark: remark,
  1710. DrugId: drug_id,
  1711. UserOrgId: orgId,
  1712. Ctime: time.Now().Unix(),
  1713. Mtime: 0,
  1714. Status: 1,
  1715. WarehousingOrder: warehousing_order,
  1716. LicenseNumber: "",
  1717. StartTime: startTime,
  1718. Creater: Creater,
  1719. Checker: 0,
  1720. CheckerStatus: 2,
  1721. CheckerTime: 0,
  1722. ExpiryDate: expiry_date,
  1723. ProductDate: product_date,
  1724. Number: numbers,
  1725. //BatchNumber: batch_number,
  1726. Total: total,
  1727. WarehouseInfoId: warehouse_info_id,
  1728. DrugOriginPlace: drug_origin_place,
  1729. MinUnit: min_unit,
  1730. MinCount: min_count,
  1731. }
  1732. err = service.CreateDrugInventory(inventory)
  1733. fmt.Println(err)
  1734. }
  1735. }
  1736. this.ServeSuccessJSON(map[string]interface{}{
  1737. "msg": "msg",
  1738. })
  1739. }
  1740. func (this *SelfDrugApiController) GetDrugInventoryList() {
  1741. timeLayout := "2006-01-02"
  1742. loc, _ := time.LoadLocation("Local")
  1743. dataBody := make(map[string]interface{}, 0)
  1744. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1745. fmt.Println(err)
  1746. orgId := this.GetAdminUserInfo().CurrentOrgId
  1747. keyword := this.GetString("keyword")
  1748. start_time := this.GetString("start_time")
  1749. end_time := this.GetString("end_time")
  1750. var startTime int64
  1751. if len(start_time) > 0 {
  1752. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1753. if err != nil {
  1754. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1755. return
  1756. }
  1757. startTime = theTime.Unix()
  1758. }
  1759. var endTime int64
  1760. if len(end_time) > 0 {
  1761. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1762. if err != nil {
  1763. utils.ErrorLog(err.Error())
  1764. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1765. return
  1766. }
  1767. endTime = theTime.Unix()
  1768. }
  1769. limit, _ := this.GetInt64("limit")
  1770. page, _ := this.GetInt64("page")
  1771. list, total, err := service.GetDrugInventoryList(keyword, page, limit, orgId, startTime, endTime)
  1772. doctorList, _ := service.GetAllDoctorThree(orgId)
  1773. houseList, _ := service.GetAllStoreHouseList(orgId)
  1774. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1775. if err != nil {
  1776. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1777. return
  1778. }
  1779. this.ServeSuccessJSON(map[string]interface{}{
  1780. "total": total,
  1781. "list": list,
  1782. "doctorList": doctorList,
  1783. "houseList": houseList,
  1784. "houseConfig": houseConfig,
  1785. })
  1786. }
  1787. func (this *SelfDrugApiController) SaveDrugCheckInventory() {
  1788. timeLayout := "2006-01-02"
  1789. loc, _ := time.LoadLocation("Local")
  1790. dataBody := make(map[string]interface{}, 0)
  1791. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1792. fmt.Println(err)
  1793. idstr := this.GetString("ids")
  1794. ids := strings.Split(idstr, ",")
  1795. check_time := this.GetString("check_time")
  1796. var checkTime int64
  1797. if len(check_time) > 0 {
  1798. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1799. if err != nil {
  1800. fmt.Println(err)
  1801. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1802. return
  1803. }
  1804. checkTime = theTime.Unix()
  1805. }
  1806. checker, _ := this.GetInt64("checker")
  1807. inventory := models.XtDrugInventory{
  1808. Checker: checker,
  1809. CheckerStatus: 1,
  1810. CheckerTime: checkTime,
  1811. }
  1812. err = service.UpdateDrugInventory(ids, inventory)
  1813. fmt.Println(err)
  1814. list, _ := service.GetDrugInventoryListByIds(ids)
  1815. adminUserInfo := this.GetAdminUserInfo()
  1816. var stock_total int64
  1817. var proof_count int64
  1818. var maxNumber int64
  1819. var minNumber int64
  1820. for _, item := range list {
  1821. //查询药品信息
  1822. drug, _ := service.GetDrugDetailByDrugId(item.DrugId)
  1823. //查询库存
  1824. info, _ := service.GetDrugWareInfoByIdTwo(item.WarehouseInfoId)
  1825. var max_count int64
  1826. var min_count int64
  1827. for _, it := range info {
  1828. max_count += it.StockMaxNumber
  1829. min_count += it.StockMinNumber
  1830. }
  1831. //获取最晚的库存数量
  1832. lastInfo, _ := service.GetLastDrugWarehouseInfo(item.DrugId)
  1833. firstInfo, _ := service.GetFirstDrugWarehouseInfo(item.DrugId)
  1834. stock_total = max_count*drug.MinNumber + min_count
  1835. proof_count = item.Count*drug.MinNumber + item.MinCount
  1836. fmt.Println("stock_total", stock_total)
  1837. fmt.Println("proof_count", proof_count)
  1838. //判断 如果库存数量 大于盘点库存,则出库
  1839. if stock_total > proof_count {
  1840. minNumber = (stock_total - proof_count) % drug.MinNumber
  1841. maxNumber = (stock_total - proof_count) / drug.MinNumber
  1842. ctime := time.Now().Unix()
  1843. timeStr := time.Now().Format("2006-01-02")
  1844. timeArr := strings.Split(timeStr, "-")
  1845. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1846. total = total + 1
  1847. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1848. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1849. number = number + total
  1850. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1851. operation_time := time.Now().Unix()
  1852. creater := adminUserInfo.AdminUser.Id
  1853. warehouseOut := models.DrugWarehouseOut{
  1854. WarehouseOutOrderNumber: warehousing_out_order,
  1855. OperationTime: operation_time,
  1856. OrgId: adminUserInfo.CurrentOrgId,
  1857. Creater: creater,
  1858. Ctime: ctime,
  1859. Status: 1,
  1860. WarehouseOutTime: ctime,
  1861. Type: 1,
  1862. }
  1863. service.AddSigleDrugWarehouseOut(&warehouseOut)
  1864. warehouse, _ := service.GetLastDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1865. warehouseOutInfo := models.DrugWarehouseOutInfo{
  1866. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1867. WarehouseOutId: warehouse.ID,
  1868. DrugId: item.DrugId,
  1869. Count: maxNumber,
  1870. Price: firstInfo.Price,
  1871. TotalPrice: firstInfo.TotalPrice,
  1872. Status: 1,
  1873. Ctime: ctime,
  1874. Remark: item.Remark,
  1875. OrgId: adminUserInfo.CurrentOrgId,
  1876. Type: 1,
  1877. Manufacturer: firstInfo.Manufacturer,
  1878. Dealer: firstInfo.Dealer,
  1879. RetailPrice: firstInfo.RetailPrice,
  1880. RetailTotalPrice: firstInfo.RetailTotalPrice,
  1881. CountUnit: drug.MaxUnit,
  1882. ExpiryDate: firstInfo.ExpiryDate,
  1883. ProductDate: firstInfo.ProductDate,
  1884. Number: firstInfo.Number,
  1885. BatchNumber: firstInfo.BatchNumber,
  1886. IsSys: 0,
  1887. WarehouseInfoId: firstInfo.ID,
  1888. }
  1889. drugflow := models.DrugFlow{
  1890. WarehouseOutId: warehouseOut.ID,
  1891. WarehouseOutOrderNumber: warehousing_out_order,
  1892. DrugId: item.DrugId,
  1893. Number: firstInfo.Number,
  1894. ProductDate: firstInfo.ProductDate,
  1895. ExpireDate: firstInfo.ExpiryDate,
  1896. Count: maxNumber,
  1897. Price: firstInfo.Price,
  1898. Status: 1,
  1899. Ctime: ctime,
  1900. UserOrgId: adminUserInfo.CurrentOrgId,
  1901. Manufacturer: firstInfo.Manufacturer,
  1902. Dealer: firstInfo.Dealer,
  1903. BatchNumber: firstInfo.BatchNumber,
  1904. MaxUnit: drug.MaxUnit,
  1905. ConsumableType: 2,
  1906. IsEdit: 1,
  1907. Creator: adminUserInfo.AdminUser.Id,
  1908. IsSys: 0,
  1909. }
  1910. service.CreateDrugWarehouseOutInfo(warehouseOutInfo)
  1911. service.CreateDrugFlowOne(drugflow)
  1912. //扣减当前批次号的库存
  1913. var total_count int64
  1914. //查询当前批次库存的数量
  1915. warehosueInfoList, _ := service.GetCurrentWarehosueInfo(item.WarehouseInfoId)
  1916. fmt.Println(warehosueInfoList)
  1917. for _, item := range warehosueInfoList {
  1918. total_count += item.StockMaxNumber*drug.MinNumber + item.StockMinNumber
  1919. }
  1920. //判断当前批次库存 和 需要出库的数据
  1921. //出库
  1922. if proof_count <= total_count {
  1923. //var total_count_one int64
  1924. //获取当前批次号的库存
  1925. //warehouseinfoOne, _ := service.GetCurrentWarehosueInfoOne(item.WarehouseInfoId)
  1926. //total_count_one = warehouseinfoOne.StockMaxNumber * drug.MinNumber + warehouseinfoOne.StockMinNumber
  1927. }
  1928. //报错提示
  1929. if proof_count > total_count {
  1930. this.ServeSuccessJSON(map[string]interface{}{
  1931. "msg": "1",
  1932. })
  1933. }
  1934. }
  1935. //判断 如果库存数量 小于于盘点库存,则入库
  1936. fmt.Println("stock_total2332322323223", stock_total, proof_count)
  1937. if stock_total < proof_count {
  1938. maxNumber = (proof_count - stock_total) / drug.MinNumber
  1939. minNumber = (proof_count - stock_total) % drug.MinNumber
  1940. fmt.Println("min_number23233232323223322323", minNumber)
  1941. ctime := time.Now().Unix()
  1942. timeStr := time.Now().Format("2006-01-02")
  1943. timeArr := strings.Split(timeStr, "-")
  1944. total, _ := service.FindAllWarehouseTotalOne(adminUserInfo.CurrentOrgId)
  1945. total = total + 1
  1946. fmt.Println("total2323232323232", total)
  1947. warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1948. operation_time := time.Now().Unix()
  1949. creater := adminUserInfo.AdminUser.Id
  1950. warehousing := models.DrugWarehouse{
  1951. WarehousingOrder: warehousing_order,
  1952. OperationTime: operation_time,
  1953. OrgId: adminUserInfo.CurrentOrgId,
  1954. Creater: creater,
  1955. Ctime: ctime,
  1956. Status: 1,
  1957. WarehousingTime: ctime,
  1958. Type: 1,
  1959. }
  1960. service.AddSigleDrugWarehouse(&warehousing)
  1961. warehouse, _ := service.GetLastDrugWarehouse(adminUserInfo.CurrentOrgId)
  1962. warehouseInfo := models.DrugWarehouseInfo{
  1963. WarehousingOrder: warehousing.WarehousingOrder,
  1964. WarehousingId: warehouse.ID,
  1965. DrugId: item.DrugId,
  1966. Number: lastInfo.Number,
  1967. ProductDate: lastInfo.ProductDate,
  1968. ExpiryDate: lastInfo.ExpiryDate,
  1969. WarehousingCount: maxNumber,
  1970. Price: lastInfo.Price,
  1971. TotalPrice: lastInfo.TotalPrice,
  1972. Status: 1,
  1973. Ctime: ctime,
  1974. Remark: item.Remark,
  1975. OrgId: adminUserInfo.CurrentOrgId,
  1976. Type: 1,
  1977. Manufacturer: lastInfo.Manufacturer,
  1978. Dealer: lastInfo.Dealer,
  1979. StockMaxNumber: maxNumber,
  1980. StockMinNumber: minNumber,
  1981. RetailTotalPrice: lastInfo.RetailTotalPrice,
  1982. BatchNumber: lastInfo.BatchNumber,
  1983. MaxUnit: drug.MaxUnit,
  1984. MinUnit: drug.MinUnit,
  1985. WarehousingInfoId: item.WarehouseInfoId,
  1986. }
  1987. drugflow := models.DrugFlow{
  1988. WarehousingOrder: warehousing.WarehousingOrder,
  1989. WarehousingId: warehouse.ID,
  1990. DrugId: item.DrugId,
  1991. Number: lastInfo.Number,
  1992. ProductDate: lastInfo.ProductDate,
  1993. ExpireDate: lastInfo.ExpiryDate,
  1994. Count: maxNumber,
  1995. Price: lastInfo.Price,
  1996. Status: 1,
  1997. Ctime: ctime,
  1998. UserOrgId: adminUserInfo.CurrentOrgId,
  1999. Manufacturer: lastInfo.Manufacturer,
  2000. Dealer: lastInfo.Dealer,
  2001. BatchNumber: lastInfo.BatchNumber,
  2002. MaxUnit: drug.MaxUnit,
  2003. MinUnit: drug.MinUnit,
  2004. ConsumableType: 1,
  2005. IsEdit: 1,
  2006. Creator: adminUserInfo.AdminUser.Id,
  2007. IsSys: 0,
  2008. }
  2009. service.CreateDrugWarehouseInfo(warehouseInfo)
  2010. service.CreateDrugFlowOne(drugflow)
  2011. }
  2012. }
  2013. returnData := make(map[string]interface{}, 0)
  2014. returnData["msg"] = "ok"
  2015. this.ServeSuccessJSON(returnData)
  2016. }
  2017. func (this *SelfDrugApiController) GetDrugInventoryDetail() {
  2018. id, _ := this.GetInt64("id")
  2019. detail, err := service.GetDrugInventoryDetail(id)
  2020. if err != nil {
  2021. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2022. return
  2023. }
  2024. this.ServeSuccessJSON(map[string]interface{}{
  2025. "detail": detail,
  2026. })
  2027. }
  2028. func (this *SelfDrugApiController) ModifyInventory() {
  2029. id, _ := this.GetInt64("id")
  2030. drug_id, _ := this.GetInt64("drug_id")
  2031. drug_name := this.GetString("drug_name")
  2032. specification_name := this.GetString("specification_name")
  2033. retailPrice := this.GetString("retail_price")
  2034. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  2035. warehousing_order := this.GetString("warehousing_order")
  2036. number := this.GetString("number")
  2037. manufacturer := this.GetString("manufacturer")
  2038. remark := this.GetString("remark")
  2039. warehousing_unit := this.GetString("warehousing_unit")
  2040. total := this.GetString("total")
  2041. lastPrice := this.GetString("last_price")
  2042. last_price, _ := strconv.ParseFloat(lastPrice, 64)
  2043. count, _ := this.GetInt64("count")
  2044. drug_origin_place := this.GetString("drug_origin_place")
  2045. stock_max_number, _ := this.GetInt64("stock_max_number")
  2046. stock_min_number, _ := this.GetInt64("stock_min_number")
  2047. warehouse_info_id, _ := this.GetInt64("warehouse_info_id")
  2048. min_count, _ := this.GetInt64("min_count")
  2049. min_unit := this.GetString("min_unit")
  2050. inventory := models.XtDrugInventory{
  2051. DrugName: drug_name,
  2052. SpecificationName: specification_name,
  2053. WarehousingUnit: warehousing_unit,
  2054. Count: count,
  2055. LastPrice: last_price,
  2056. RetailPrice: retail_price,
  2057. Manufacturer: manufacturer,
  2058. Remark: remark,
  2059. DrugId: drug_id,
  2060. WarehousingOrder: warehousing_order,
  2061. Number: number,
  2062. Total: total,
  2063. DrugOriginPlace: drug_origin_place,
  2064. StockMaxNumber: stock_max_number,
  2065. StockMinNumber: stock_min_number,
  2066. WarehouseInfoId: warehouse_info_id,
  2067. MinCount: min_count,
  2068. MinUnit: min_unit,
  2069. }
  2070. err := service.ModifyDrugInventory(id, inventory)
  2071. if err != nil {
  2072. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2073. return
  2074. }
  2075. this.ServeSuccessJSON(map[string]interface{}{
  2076. "inventory": inventory,
  2077. })
  2078. }
  2079. func (this *SelfDrugApiController) DeleteDrugInventory() {
  2080. id, _ := this.GetInt64("id")
  2081. err := service.DeleteDrugInventory(id)
  2082. fmt.Println(err)
  2083. returnData := make(map[string]interface{}, 0)
  2084. returnData["msg"] = "ok"
  2085. this.ServeSuccessJSON(returnData)
  2086. }
  2087. func (this *SelfDrugApiController) GetDrugInventoryPrintList() {
  2088. ids := this.GetString("ids")
  2089. idssplit := strings.Split(ids, ",")
  2090. list, err := service.GetDrugInventoryPrintList(idssplit)
  2091. if err != nil {
  2092. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2093. return
  2094. }
  2095. this.ServeSuccessJSON(map[string]interface{}{
  2096. "list": list,
  2097. })
  2098. }
  2099. func (this *SelfDrugApiController) GetDrugInventoryDetailList() {
  2100. keyword := this.GetString("keyword")
  2101. limit, _ := this.GetInt64("limit")
  2102. page, _ := this.GetInt64("page")
  2103. storehouse_id, _ := this.GetInt64("storehouse_id")
  2104. orgId := this.GetAdminUserInfo().CurrentOrgId
  2105. list, total, err := service.GetDrugInventoryDetailList(keyword, page, limit, orgId, storehouse_id)
  2106. inventoryList, _, _ := service.GetDrugInventoryDetailListTwo(keyword, page, limit, orgId, storehouse_id)
  2107. houseList, _ := service.GetAllStoreHouseList(orgId)
  2108. doctorList, _ := service.GetAllDoctorThree(orgId)
  2109. if err != nil {
  2110. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2111. return
  2112. }
  2113. this.ServeSuccessJSON(map[string]interface{}{
  2114. "total": total,
  2115. "list": list,
  2116. "doctorList": doctorList,
  2117. "houseList": houseList,
  2118. "inventoryList": inventoryList,
  2119. })
  2120. }
  2121. func (this *SelfDrugApiController) SaveDrugProofInventory() {
  2122. id, _ := this.GetInt64("id")
  2123. warehouse_info_id, _ := this.GetInt64("warehouse_info_id")
  2124. warehousing_unit := this.GetString("warehousing_unit")
  2125. remark := this.GetString("remark")
  2126. proof_count, _ := this.GetInt64("proof_count")
  2127. inventory := models.XtDrugInventory{
  2128. WarehouseInfoId: warehouse_info_id,
  2129. ProofCount: proof_count,
  2130. WarehousingUnit: warehousing_unit,
  2131. Remark: remark,
  2132. }
  2133. err := service.UpdateDrugProofInventory(id, &inventory)
  2134. info := models.XtDrugWarehouseInfo{
  2135. StockMaxNumber: proof_count,
  2136. }
  2137. service.UpdateDrugWarehouseInfoById(warehouse_info_id, &info)
  2138. if err != nil {
  2139. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2140. return
  2141. }
  2142. this.ServeSuccessJSON(map[string]interface{}{
  2143. "inventory": inventory,
  2144. })
  2145. }
  2146. func (this *StockManagerApiController) GetDrugWarehouseInfoTotal() {
  2147. id, _ := this.GetInt64("id")
  2148. list, _ := service.GetDrugWarehouseInfoTotal(id)
  2149. this.ServeSuccessJSON(map[string]interface{}{
  2150. "list": list,
  2151. })
  2152. }
  2153. //新改造
  2154. func (this *SelfDrugApiController) SaveInventoryList() {
  2155. dataBody := make(map[string]interface{}, 0)
  2156. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2157. fmt.Println(err)
  2158. tableData, _ := dataBody["tableData"].([]interface{})
  2159. if len(tableData) > 0 {
  2160. for _, item := range tableData {
  2161. items := item.(map[string]interface{})
  2162. drug_name := items["drug_name"].(string)
  2163. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  2164. utils.ErrorLog("drug_name")
  2165. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2166. return
  2167. }
  2168. fmt.Println("drug_name", drug_name)
  2169. specification_name := items["specification_name"].(string)
  2170. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  2171. utils.ErrorLog("specification_name")
  2172. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2173. return
  2174. }
  2175. max_unit := items["max_unit"].(string)
  2176. if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
  2177. utils.ErrorLog("max_unit")
  2178. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2179. return
  2180. }
  2181. min_unit := items["min_unit"].(string)
  2182. if items["min_unit"] == nil || reflect.TypeOf(items["min_unit"]).String() != "string" {
  2183. utils.ErrorLog("min_unit")
  2184. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2185. return
  2186. }
  2187. drug_id := int64(items["drug_id"].(float64))
  2188. min_number := int64(items["min_number"].(float64))
  2189. stock_max_number := int64(items["stock_max_number"].(float64))
  2190. stock_min_number := int64(items["stock_min_number"].(float64))
  2191. last_stock_max_number := int64(items["last_stock_max_number"].(float64))
  2192. last_stock_min_number := int64(items["last_stock_min_number"].(float64))
  2193. warehousing_order := items["warehousing_order"].(string)
  2194. price := items["price"].(float64)
  2195. manufacturer_name := items["manufacturer_name"].(string)
  2196. batch_number := items["batch_number"].(string)
  2197. id := int64(items["id"].(float64))
  2198. orgId := this.GetAdminUserInfo().CurrentOrgId
  2199. type_id := int64(items["type"].(float64))
  2200. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  2201. utils.ErrorLog("expiry_date")
  2202. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2203. return
  2204. }
  2205. expiry_date := int64(items["expiry_date"].(float64))
  2206. manufacturer := int64(items["manufacturer"].(float64))
  2207. storehouse_id := int64(items["storehouse_id"].(float64))
  2208. timeLayout := "2006-01-02"
  2209. loc, _ := time.LoadLocation("Local")
  2210. timeNow := time.Now().Format("2006-01-02")
  2211. locationTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", timeNow+" 00:00:00", loc)
  2212. var consumable_type int64
  2213. var consumable_count int64
  2214. var ord_total int64
  2215. var new_total int64
  2216. var total int64
  2217. ord_total = stock_max_number*min_number + stock_min_number
  2218. new_total = last_stock_max_number*min_number + last_stock_min_number
  2219. medical, _ := service.GetBaseDrugMedical(drug_id)
  2220. //改变库存
  2221. info := models.DrugWarehouseInfo{
  2222. DrugId: drug_id,
  2223. StockMaxNumber: last_stock_max_number,
  2224. StockMinNumber: last_stock_min_number,
  2225. WarehousingCount: last_stock_max_number,
  2226. MaxUnit: max_unit,
  2227. MinUnit: min_unit,
  2228. }
  2229. drugInfo, _ := service.GetCurrentWarehosueInfoOne(id)
  2230. if drugInfo.MaxUnit == medical.MaxUnit {
  2231. total = drugInfo.WarehousingCount * medical.MinNumber
  2232. }
  2233. if drugInfo.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2234. total = drugInfo.WarehousingCount
  2235. }
  2236. //如果库存数据大于盘点数据,则减去数量
  2237. if ord_total > new_total {
  2238. consumable_type = 11
  2239. consumable_count = ord_total - new_total
  2240. err = service.ModifyDrugWarehouseInfo(&info, id)
  2241. }
  2242. //如果库存数据小于盘点数据,则增加数量
  2243. if ord_total < new_total && new_total <= total {
  2244. consumable_type = 10
  2245. consumable_count = new_total - ord_total
  2246. err = service.ModifyDrugWarehouseInfo(&info, id)
  2247. }
  2248. if ord_total < new_total && new_total > total {
  2249. consumable_type = 10
  2250. consumable_count = new_total - ord_total
  2251. err = service.ModifyDrugWarehouseInfoSix(&info, id)
  2252. }
  2253. //查询默认仓库
  2254. houseConfig, _ := service.GetAllStoreHouseConfig(drugInfo.OrgId)
  2255. //查询默认仓库剩余多少库存
  2256. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, drugInfo.OrgId, drugInfo.DrugId)
  2257. var sum_count int64
  2258. var sum_in_count int64
  2259. for _, it := range list {
  2260. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  2261. if it.MaxUnit == baseDrug.MaxUnit {
  2262. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2263. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2264. }
  2265. sum_count += it.StockMaxNumber + it.StockMinNumber
  2266. sum_in_count += it.WarehousingCount
  2267. }
  2268. service.UpdateMedicalSumCount(drugInfo.DrugId, sum_count, sum_in_count, drugInfo.OrgId)
  2269. inventory := models.XtDrugInventory{
  2270. DrugName: drug_name,
  2271. SpecificationName: specification_name,
  2272. WarehousingUnit: max_unit,
  2273. Count: consumable_count,
  2274. LastPrice: price,
  2275. RetailPrice: 0,
  2276. NewPrice: 0,
  2277. Manufacturer: manufacturer_name,
  2278. Dealer: "",
  2279. Remark: "",
  2280. DrugId: drug_id,
  2281. UserOrgId: orgId,
  2282. Ctime: time.Now().Unix(),
  2283. Mtime: 0,
  2284. Status: 1,
  2285. WarehousingOrder: warehousing_order,
  2286. LicenseNumber: "",
  2287. StartTime: locationTime.Unix(),
  2288. Creater: this.GetAdminUserInfo().AdminUser.Id,
  2289. Checker: 0,
  2290. CheckerStatus: 0,
  2291. CheckerTime: 0,
  2292. ExpiryDate: expiry_date,
  2293. ProductDate: 0,
  2294. Number: "",
  2295. BatchNumber: batch_number,
  2296. Total: "",
  2297. DrugOriginPlace: "",
  2298. WarehouseInfoId: id,
  2299. ProofCount: 0,
  2300. StockMaxNumber: stock_max_number,
  2301. StockMinNumber: stock_min_number,
  2302. MinCount: 0,
  2303. MinUnit: min_unit,
  2304. LastStockMaxNumber: last_stock_max_number,
  2305. LastStockMinNumber: last_stock_min_number,
  2306. InventoryType: consumable_type,
  2307. Type: type_id,
  2308. StorehouseId: storehouse_id,
  2309. }
  2310. err = service.CreateDrugInventory(inventory)
  2311. flow := models.DrugFlow{
  2312. WarehousingId: id,
  2313. DrugId: drug_id,
  2314. Number: "",
  2315. BatchNumber: batch_number,
  2316. Count: consumable_count,
  2317. UserOrgId: orgId,
  2318. PatientId: 0,
  2319. SystemTime: locationTime.Unix(),
  2320. ConsumableType: consumable_type,
  2321. IsSys: 1,
  2322. WarehousingOrder: warehousing_order,
  2323. WarehouseOutId: 0,
  2324. WarehouseOutOrderNumber: "",
  2325. IsEdit: 0,
  2326. CancelStockId: 0,
  2327. CancelOrderNumber: "",
  2328. Manufacturer: manufacturer,
  2329. Dealer: 0,
  2330. Creator: this.GetAdminUserInfo().AdminUser.Id,
  2331. UpdateCreator: 0,
  2332. Status: 1,
  2333. Ctime: time.Now().Unix(),
  2334. Mtime: 0,
  2335. Price: price,
  2336. WarehousingDetailId: id,
  2337. WarehouseOutDetailId: 0,
  2338. CancelOutDetailId: 0,
  2339. ExpireDate: expiry_date,
  2340. ProductDate: 0,
  2341. MaxUnit: min_unit,
  2342. MinUnit: min_unit,
  2343. StorehouseId: storehouse_id,
  2344. }
  2345. if ord_total != new_total {
  2346. service.CreateDrugFlowOne(flow)
  2347. }
  2348. if err != nil {
  2349. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2350. return
  2351. }
  2352. this.ServeSuccessJSON(map[string]interface{}{
  2353. "inventory": inventory,
  2354. })
  2355. }
  2356. }
  2357. }
  2358. func (this *SelfDrugApiController) GetDamageByDrugId() {
  2359. drug_id, _ := this.GetInt64("drug_id")
  2360. warehousing_order := this.GetString("warehouseing_order")
  2361. drug_type, _ := this.GetInt64("type")
  2362. list, err := service.GetDamageByDrugId(drug_id, warehousing_order, drug_type)
  2363. if err != nil {
  2364. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2365. return
  2366. }
  2367. this.ServeSuccessJSON(map[string]interface{}{
  2368. "list": list,
  2369. })
  2370. }
  2371. func (this *SelfDrugApiController) GetInventoryModeList() {
  2372. orgId := this.GetAdminUserInfo().CurrentOrgId
  2373. list, err := service.GetInventoryModeList(orgId)
  2374. manufacturerList, err := service.GetAllManufacturerList(orgId)
  2375. if err != nil {
  2376. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2377. return
  2378. }
  2379. this.ServeSuccessJSON(map[string]interface{}{
  2380. "list": list,
  2381. "manufacturerList": manufacturerList,
  2382. })
  2383. }