self_drug_api_congtroller.go 89KB

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