self_drug_api_congtroller.go 86KB

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