self_drug_api_congtroller.go 87KB

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