self_drug_api_congtroller.go 78KB

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