self_drug_api_congtroller.go 87KB

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