gobal_config_api_controller.go 86KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825
  1. package controllers
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "fmt"
  6. "io/ioutil"
  7. "log"
  8. "os"
  9. "path"
  10. "reflect"
  11. "regexp"
  12. "runtime"
  13. "strconv"
  14. "strings"
  15. "time"
  16. "XT_New/enums"
  17. "XT_New/models"
  18. "XT_New/service"
  19. "XT_New/utils"
  20. "github.com/jinzhu/gorm"
  21. "github.com/astaxie/beego"
  22. )
  23. type GobalConfigApiController struct {
  24. BaseAuthAPIController
  25. }
  26. func GobalConfigRegistRouters() {
  27. beego.Router("/api/stock/automaticreduce/isopen", &GobalConfigApiController{}, "post:PostStockConfig")
  28. beego.Router("/api/drugstock/automaticreduce/isopen", &GobalConfigApiController{}, "post:PostDrugStockConfig")
  29. beego.Router("/api/automaticreduce/get", &GobalConfigApiController{}, "get:GetConfig")
  30. beego.Router("/api/drugstockautomaticreduce/get", &GobalConfigApiController{}, "get:GetDrugStockConfig")
  31. beego.Router("/api/print/template/commit", &GobalConfigApiController{}, "post:PostPrintTemplateTwo")
  32. beego.Router("/api/print/template/get", &GobalConfigApiController{}, "get:GetPrintTemplate")
  33. beego.Router("/api/dataupload/config/commit", &GobalConfigApiController{}, "post:PostConfig")
  34. beego.Router("/api/dataupload/config/modify", &GobalConfigApiController{}, "post:ModifyConfig")
  35. beego.Router("/api/dataupload/config/get", &GobalConfigApiController{}, "get:GetDataUploadConfig")
  36. beego.Router("/api/dataupload/is_docking/get", &GobalConfigApiController{}, "get:GetDataUploadIsDocking")
  37. beego.Router("/api/adviceconfig/isopen", &GobalConfigApiController{}, "post:PostDoctorAdviceConfig")
  38. beego.Router("/api/adviceconfig/get", &GobalConfigApiController{}, "get:GetDoctorAdviceConfig")
  39. beego.Router("/api/advicetemplate/init/commit", &GobalConfigApiController{}, "post:PostInitAdviceTemplate")
  40. beego.Router("/api/advicetemplate/init/get", &GobalConfigApiController{}, "get:GetAdviceInitConfig")
  41. beego.Router("/api/systemprescription/commit", &GobalConfigApiController{}, "post:CreateSystemPrescription")
  42. beego.Router("/api/systemprescription/update", &GobalConfigApiController{}, "post:UpdateSystemPrescription")
  43. beego.Router("/api/systemprescription/all", &GobalConfigApiController{}, "get:GetAllSystemPrescription")
  44. beego.Router("/api/systemprescription/get", &GobalConfigApiController{}, "get:GetSystemPrescription")
  45. beego.Router("/api/advicetemplate/getprintinfo", &GobalConfigApiController{}, "post:GetPrintInfo")
  46. beego.Router("/api/public/orgs", &GobalConfigApiController{}, "get:GetOrgs")
  47. beego.Router("/api/org/change", &GobalConfigApiController{}, "post:ChangeOrg")
  48. beego.Router("/api/log/generate", &GobalConfigApiController{}, "get:GenerateLog")
  49. beego.Router("/api/patients/search", &GobalConfigApiController{}, "Post:GetPatientsByKeyWord")
  50. beego.Router("/api/xtconfig/get", &GobalConfigApiController{}, "get:GetXTHisConfig")
  51. beego.Router("/api/xtconfig/isopen", &GobalConfigApiController{}, "post:PostXTHisConfig")
  52. beego.Router("/api/hisstockpriceconfig/get", &GobalConfigApiController{}, "get:GetHisStockPriceConfig")
  53. beego.Router("/api/hisstockpriceconfig/isopen", &GobalConfigApiController{}, "post:PostHisStockPriceConfig")
  54. beego.Router("/api/xtconfigproject/isopen", &GobalConfigApiController{}, "post:PostXTHisProjectConfig")
  55. beego.Router("/api/isopen/init", &GobalConfigApiController{}, "get:GetAllIsOpenConfig")
  56. beego.Router("/api/passdetail/export", &GobalConfigApiController{}, "get:GetPassExportData")
  57. beego.Router("/api/consumedetail/export", &GobalConfigApiController{}, "get:GetExportData")
  58. beego.Router("/api/drugstock/getdrugindetail", &GobalConfigApiController{}, "get:GetDrugInDetail")
  59. beego.Router("/api/drugstock/getdrugcancelorder", &GobalConfigApiController{}, "get:GetDrugCancelOrder")
  60. beego.Router("/api/drugstock/getdrugoutdetail", &GobalConfigApiController{}, "get:GetDrugOutDetail")
  61. beego.Router("/api/drugstock/getdrugcanceldetail", &GobalConfigApiController{}, "get:GetDrugCancelDetail")
  62. beego.Router("/api/monitor/open", &GobalConfigApiController{}, "get:AddMonitorOpen")
  63. beego.Router("/api/monitor/getmonitorconfig", &GobalConfigApiController{}, "Get:GetMonitorConfig")
  64. beego.Router("/api/order/addorderconfig", &GobalConfigApiController{}, "Get:AddOrderConfig")
  65. beego.Router("/api/order/getorderconfig", &GobalConfigApiController{}, "Get:GetOrderConfig")
  66. beego.Router("/api/drugstock/getdrugautomaticlist", &GobalConfigApiController{}, "Get:GetDrugAutoMaticList")
  67. beego.Router("/api/drugstock/getdrugwarehouseorderinfo", &GobalConfigApiController{}, "Get:GetDrugWarehuseOrderInfo")
  68. //新接口
  69. beego.Router("/api/drugstock/drugstocklist", &GobalConfigApiController{}, "Get:GetDrugStockList")
  70. beego.Router("/api/drugstock/getdrugstockflow", &GobalConfigApiController{}, "Get:GetDrugStockFllow")
  71. beego.Router("/api/drugoutstock/getoutdrugstockflow", &GobalConfigApiController{}, "Get:GetDrugOutStockFlow")
  72. beego.Router("/api/drug/getbatchorderdetail", &GobalConfigApiController{}, "Get:GetBatchOrderDetail")
  73. beego.Router("/api/drug/getdrugcountlist", &GobalConfigApiController{}, "Get:GetDrugCountList")
  74. beego.Router("/api/drug/getsingleorderdetail", &GobalConfigApiController{}, "Get:GetSingleOrderDetail")
  75. beego.Router("/api/drug/getautodrugdetial", &GobalConfigApiController{}, "Get:GetAutoDrugDetail")
  76. beego.Router("/api/drug/getdrugorderinprint", &GobalConfigApiController{}, "Get:GetDrugOrderInPrint")
  77. beego.Router("/api/drug/getdrugoutorderdetailprint", &GobalConfigApiController{}, "Get:GetDrugOutOrderPrint")
  78. beego.Router("/api/drug/getdrugbatchnumber", &GobalConfigApiController{}, "Get:GetDrugBatchNumber")
  79. beego.Router("/api/drug/exportdruglist", &GobalConfigApiController{}, "Get:ExportDrugList")
  80. beego.Router("/api/drug/getexportoutorderdruglist", &GobalConfigApiController{}, "Get:GetExportOutOrderDrugList")
  81. beego.Router("/api/drug/getdrugflow", &GobalConfigApiController{}, "Get:GetDrugFlow")
  82. beego.Router("/api/drug/getcancelstockdetail", &GobalConfigApiController{}, "Get:GetCancelStockDetail")
  83. beego.Router("/api/changestocksetting/isopen", &GobalConfigApiController{}, "Get:ChangeStockSetting")
  84. beego.Router("/api/changeadviceconfig", &GobalConfigApiController{}, "Get:ChangeAdviceConfig")
  85. beego.Router("/api/changeprescriptionconfig", &GobalConfigApiController{}, "Get:ChangePrescriptionConfig")
  86. beego.Router("/api/changedrugopenconfig", &GobalConfigApiController{}, "Get:ChangeDrugOpenConfig")
  87. beego.Router("/api/changesettleopenconfig", &GobalConfigApiController{}, "Get:ChangeSettleOpenConfig")
  88. beego.Router("/api/changegoodoutopen", &GobalConfigApiController{}, "Get:ChangeGoodOutOpen")
  89. beego.Router("/api/schedule/config/commit", &GobalConfigApiController{}, "post:PostScheduleConfig")
  90. beego.Router("/api/schedule/config/get", &GobalConfigApiController{}, "get:GetScheduleConfig")
  91. beego.Router("/api/checkremind/config/commit", &GobalConfigApiController{}, "post:PostCheckRemindConfig")
  92. beego.Router("/api/checkremind/config/get", &GobalConfigApiController{}, "get:GetCheckRemindConfig")
  93. beego.Router("/api/changeselfprescriptionopen", &GobalConfigApiController{}, "Get:ChangeSelfPrescriptionOpen")
  94. beego.Router("/api/changeselfprescriptionoutopen", &GobalConfigApiController{}, "Get:ChangeSelfPrescriptionOutOpen")
  95. beego.Router("/api/getselfprintlist", &GobalConfigApiController{}, "Get:GetSelfPrintList")
  96. beego.Router("/api/changedrugcodeopen", &GobalConfigApiController{}, "Get:ChangeDrugCodeOpen")
  97. }
  98. //provinces, _ := service.GetDistrictsByUpid(0)21
  99. func (c *GobalConfigApiController) PostCheckRemindConfig() {
  100. is_open, _ := c.GetInt64("is_open", 0)
  101. id, _ := c.GetInt64("id", 0)
  102. config, _ := service.GetCheckRemindConfigByIdTwo(id)
  103. var err error
  104. if config.ID == 0 {
  105. config.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  106. config.Ctime = time.Now().Unix()
  107. config.Mtime = time.Now().Unix()
  108. config.Status = 1
  109. config.IsOpen = is_open
  110. err = service.CreateCheckRemindConfig(&config)
  111. } else {
  112. config.IsOpen = is_open
  113. config.Mtime = time.Now().Unix()
  114. err = service.SaveCheckRemindConfig(&config)
  115. }
  116. if err == nil {
  117. c.ServeSuccessJSON(map[string]interface{}{
  118. "config": config,
  119. })
  120. }
  121. }
  122. func (c *GobalConfigApiController) GetCheckRemindConfig() {
  123. config, _ := service.GetCheckRemindConfigById(c.GetAdminUserInfo().CurrentOrgId)
  124. c.ServeSuccessJSON(map[string]interface{}{
  125. "config": config,
  126. })
  127. }
  128. func (c *GobalConfigApiController) PostScheduleConfig() {
  129. is_show_mode, _ := c.GetInt64("is_show_mode", 0)
  130. is_show_machine, _ := c.GetInt64("is_show_machine", 0)
  131. id, _ := c.GetInt64("id", 0)
  132. config, _ := service.GetScheduleConfigById(id)
  133. var err error
  134. if config.ID == 0 {
  135. config.IsShowMode = is_show_mode
  136. config.IsShowMachine = is_show_machine
  137. config.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  138. config.Ctime = time.Now().Unix()
  139. config.Mtime = time.Now().Unix()
  140. config.Status = 1
  141. err = service.CreateScheduleConfig(config)
  142. } else {
  143. config.IsShowMachine = is_show_machine
  144. config.IsShowMode = is_show_mode
  145. config.Mtime = time.Now().Unix()
  146. err = service.SaveScheduleConfig(config)
  147. }
  148. if err == nil {
  149. c.ServeSuccessJSON(map[string]interface{}{
  150. "config": config,
  151. })
  152. }
  153. }
  154. func (c *GobalConfigApiController) GetScheduleConfig() {
  155. config, _ := service.GetScheduleConfigByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  156. c.ServeSuccessJSON(map[string]interface{}{
  157. "config": config,
  158. })
  159. }
  160. func (c *GobalConfigApiController) PostStockConfig() {
  161. is_open, _ := c.GetInt64("is_open", 0)
  162. adminUserInfo := c.GetAdminUserInfo()
  163. org_id := adminUserInfo.CurrentOrgId
  164. config := models.GobalConfig{
  165. OrgId: org_id,
  166. IsOpen: is_open,
  167. Status: 1,
  168. CreateTime: time.Now().Unix(),
  169. UpdateTime: time.Now().Unix(),
  170. IsOpenRemind: 0,
  171. }
  172. errs, configs := service.FindAutomaticReduceRecordByOrgId(org_id)
  173. if errs == gorm.ErrRecordNotFound {
  174. err := service.CreateAutomaticReduceRecord(&config)
  175. if err != nil {
  176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  177. return
  178. }
  179. } else if errs == nil {
  180. modifyConfig := models.GobalConfig{
  181. ID: configs.ID,
  182. OrgId: org_id,
  183. IsOpen: is_open,
  184. Status: 1,
  185. CreateTime: time.Now().Unix(),
  186. UpdateTime: time.Now().Unix(),
  187. IsOpenRemind: configs.IsOpenRemind,
  188. }
  189. err := service.UpdateAutomaticReduceRecord(&modifyConfig)
  190. if err != nil {
  191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  192. return
  193. }
  194. }
  195. if is_open == 1 {
  196. service.UpdateGobalConfig(org_id)
  197. }
  198. c.ServeSuccessJSON(map[string]interface{}{
  199. "is_open": is_open,
  200. })
  201. return
  202. }
  203. func (c *GobalConfigApiController) PostDrugStockConfig() {
  204. is_open, _ := c.GetInt64("is_open", 0)
  205. adminUserInfo := c.GetAdminUserInfo()
  206. org_id := adminUserInfo.CurrentOrgId
  207. config := models.DrugStockConfig{
  208. OrgId: org_id,
  209. IsOpen: is_open,
  210. Status: 1,
  211. CreateTime: time.Now().Unix(),
  212. UpdateTime: time.Now().Unix(),
  213. }
  214. errs, configs := service.FindDrugStockAutomaticReduceRecordByOrgId(org_id)
  215. if is_open == 1 {
  216. service.UpdateSettleOpenConfigOne(org_id, 2)
  217. }
  218. if errs == gorm.ErrRecordNotFound {
  219. err := service.CreateDrugAutomaticReduceRecord(&config)
  220. if err != nil {
  221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  222. return
  223. }
  224. } else if errs == nil {
  225. modifyConfig := models.DrugStockConfig{
  226. ID: configs.ID,
  227. OrgId: org_id,
  228. IsOpen: is_open,
  229. Status: 1,
  230. CreateTime: time.Now().Unix(),
  231. UpdateTime: time.Now().Unix(),
  232. }
  233. err := service.UpdateDrugStockAutomaticReduceRecord(&modifyConfig)
  234. if err != nil {
  235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  236. return
  237. }
  238. }
  239. c.ServeSuccessJSON(map[string]interface{}{
  240. "is_open": is_open,
  241. })
  242. return
  243. }
  244. func (c *GobalConfigApiController) GetConfig() {
  245. adminUserInfo := c.GetAdminUserInfo()
  246. _, config := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  247. c.ServeSuccessJSON(map[string]interface{}{
  248. "config": config,
  249. })
  250. }
  251. func (c *GobalConfigApiController) GetDrugStockConfig() {
  252. adminUserInfo := c.GetAdminUserInfo()
  253. _, config := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  254. c.ServeSuccessJSON(map[string]interface{}{
  255. "config": config,
  256. })
  257. }
  258. func (c *GobalConfigApiController) PostPrintTemplate() {
  259. template_id, _ := c.GetInt64("template_id", 0)
  260. adminUserInfo := c.GetAdminUserInfo()
  261. org_id := adminUserInfo.CurrentOrgId
  262. template := models.GobalTemplate{
  263. OrgId: org_id,
  264. TemplateId: template_id,
  265. Status: 1,
  266. Ctime: time.Now().Unix(),
  267. Mtime: time.Now().Unix(),
  268. }
  269. errs, templates := service.FindPrintTemplateByOrgId(org_id)
  270. if errs == gorm.ErrRecordNotFound {
  271. err := service.CreatePrintTemplateRecord(&template)
  272. if err != nil {
  273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  274. return
  275. }
  276. } else if errs == nil {
  277. templates := models.GobalTemplate{
  278. ID: templates.ID,
  279. OrgId: org_id,
  280. TemplateId: template_id,
  281. Status: 1,
  282. Ctime: templates.Ctime,
  283. Mtime: time.Now().Unix(),
  284. }
  285. err := service.UpdatePrintTemplate(&templates)
  286. if err != nil {
  287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  288. return
  289. }
  290. }
  291. c.ServeSuccessJSON(map[string]interface{}{
  292. "template_id": template_id,
  293. })
  294. return
  295. }
  296. func (c *GobalConfigApiController) PostPrintTemplateTwo() {
  297. template_id, _ := c.GetInt64("template_id", 0)
  298. adminUserInfo := c.GetAdminUserInfo()
  299. org_id := adminUserInfo.CurrentOrgId
  300. template := models.GobalTemplate{
  301. OrgId: org_id,
  302. TemplateId: template_id,
  303. Status: 1,
  304. Ctime: time.Now().Unix(),
  305. Mtime: time.Now().Unix(),
  306. }
  307. errs, templates := service.FindPrintTemplateByOrgId(org_id)
  308. if errs == gorm.ErrRecordNotFound {
  309. err := service.CreatePrintTemplateRecord(&template)
  310. if err != nil {
  311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  312. return
  313. }
  314. if err == nil { //处理模版切换,显示配置处理逻辑
  315. //service.FindAllConfig
  316. //先将所有数据设置为显示
  317. updateErr := service.UpdateFiledConfig(adminUserInfo.CurrentOrgId)
  318. if updateErr == nil {
  319. //查出该模版对应显示配置字段中所有隐藏的字段
  320. _, config := service.FindAllHideFiledConfig(template_id)
  321. var fileds []string
  322. for _, item := range config {
  323. fileds = append(fileds, item.FiledName)
  324. }
  325. service.UpdateShowFieldConfig(adminUserInfo.CurrentOrgId, fileds)
  326. }
  327. }
  328. FiledList, _ := service.FindFiledByOrgId(adminUserInfo.CurrentOrgId)
  329. c.ServeSuccessJSON(map[string]interface{}{
  330. "template_id": template_id,
  331. "fileds": FiledList,
  332. })
  333. } else if errs == nil {
  334. templates := models.GobalTemplate{
  335. ID: templates.ID,
  336. OrgId: org_id,
  337. TemplateId: template_id,
  338. Status: 1,
  339. Ctime: templates.Ctime,
  340. Mtime: time.Now().Unix(),
  341. }
  342. err := service.UpdatePrintTemplate(&templates)
  343. if err != nil {
  344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  345. return
  346. }
  347. if err == nil { //处理模版切换,显示配置处理逻辑
  348. //service.FindAllConfig
  349. //先将所有数据设置为显示
  350. updateErr := service.UpdateFiledConfig(adminUserInfo.CurrentOrgId)
  351. if updateErr == nil {
  352. //查出该模版对应显示配置字段中所有隐藏的字段
  353. _, config := service.FindAllHideFiledConfig(template_id)
  354. var fileds []string
  355. for _, item := range config {
  356. fileds = append(fileds, item.FiledName)
  357. }
  358. service.UpdateShowFieldConfig(adminUserInfo.CurrentOrgId, fileds)
  359. }
  360. }
  361. FiledList, _ := service.FindFiledByOrgId(adminUserInfo.CurrentOrgId)
  362. c.ServeSuccessJSON(map[string]interface{}{
  363. "template_id": template_id,
  364. "fileds": FiledList,
  365. })
  366. return
  367. }
  368. }
  369. func (c *GobalConfigApiController) GetPrintTemplate() {
  370. adminUserInfo := c.GetAdminUserInfo()
  371. _, template := service.FindPrintTemplateByOrgId(adminUserInfo.CurrentOrgId)
  372. c.ServeSuccessJSON(map[string]interface{}{
  373. "template": template,
  374. })
  375. }
  376. func (c *GobalConfigApiController) PostConfig() {
  377. gateway_address := c.GetString("gateway_address")
  378. app_id := c.GetString("app_id")
  379. key := c.GetString("key")
  380. config_type, _ := c.GetInt64("config_type")
  381. time_type, _ := c.GetInt64("time_type")
  382. province, _ := c.GetInt64("province")
  383. city, _ := c.GetInt64("city")
  384. if config_type > 1 {
  385. _, err := service.GetDockingStatus(config_type, province, city)
  386. if err == gorm.ErrRecordNotFound {
  387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotDocking)
  388. return
  389. }
  390. }
  391. adminUserInfo := c.GetAdminUserInfo()
  392. org_id := adminUserInfo.CurrentOrgId
  393. config := &models.DataUploadConfig{
  394. OrgId: org_id,
  395. ProvinceId: province,
  396. CityId: city,
  397. GatewayAddress: gateway_address,
  398. AppId: app_id,
  399. Key: key,
  400. Status: 1,
  401. CreateTime: time.Now().Unix(),
  402. ModifyTime: time.Now().Unix(),
  403. TimeQuantum: time_type,
  404. ConfigType: config_type,
  405. }
  406. err := service.CreateConfigData(config)
  407. if err == nil {
  408. c.ServeSuccessJSON(map[string]interface{}{
  409. "config": config,
  410. })
  411. } else {
  412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  413. return
  414. }
  415. }
  416. func (c *GobalConfigApiController) GetDataUploadConfig() {
  417. config_type, _ := c.GetInt64("config_type")
  418. adminUserInfo := c.GetAdminUserInfo()
  419. org_id := adminUserInfo.CurrentOrgId
  420. config, err := service.GetConfigData(org_id, config_type)
  421. fmt.Println(err)
  422. if err == nil {
  423. c.ServeSuccessJSON(map[string]interface{}{
  424. "config": config,
  425. })
  426. } else {
  427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  428. return
  429. }
  430. }
  431. func (c *GobalConfigApiController) GetDataUploadIsDocking() {
  432. config_type, _ := c.GetInt64("config_type")
  433. province, _ := c.GetInt64("province")
  434. city, _ := c.GetInt64("city")
  435. config, err := service.GetDockingStatus(config_type, province, city)
  436. fmt.Println(config)
  437. fmt.Println(err)
  438. if err == gorm.ErrRecordNotFound {
  439. c.ServeSuccessJSON(map[string]interface{}{
  440. "is_docking": 2,
  441. })
  442. } else if err == nil {
  443. if config.ID > 0 {
  444. c.ServeSuccessJSON(map[string]interface{}{
  445. "is_docking": 1,
  446. })
  447. } else {
  448. c.ServeSuccessJSON(map[string]interface{}{
  449. "is_docking": 2,
  450. })
  451. }
  452. }
  453. }
  454. func (c *GobalConfigApiController) ModifyConfig() {
  455. id, _ := c.GetInt64("id")
  456. gateway_address := c.GetString("gateway_address")
  457. app_id := c.GetString("app_id")
  458. key := c.GetString("key")
  459. config_type, _ := c.GetInt64("config_type")
  460. time_type, _ := c.GetInt64("time_type")
  461. province, _ := c.GetInt64("province")
  462. city, _ := c.GetInt64("city")
  463. adminUserInfo := c.GetAdminUserInfo()
  464. org_id := adminUserInfo.CurrentOrgId
  465. if config_type > 1 {
  466. _, err := service.GetDockingStatus(config_type, province, city)
  467. if err == gorm.ErrRecordNotFound {
  468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotDocking)
  469. return
  470. }
  471. }
  472. tempConfig, _ := service.GetConfigDataById(id)
  473. config := &models.DataUploadConfig{
  474. ID: tempConfig.ID,
  475. OrgId: org_id,
  476. ProvinceId: province,
  477. CityId: city,
  478. GatewayAddress: gateway_address,
  479. AppId: app_id,
  480. Key: key,
  481. Status: 1,
  482. CreateTime: tempConfig.CreateTime,
  483. ModifyTime: time.Now().Unix(),
  484. TimeQuantum: time_type,
  485. ConfigType: config_type,
  486. }
  487. err := service.SaveConfigData(config)
  488. if err == nil {
  489. c.ServeSuccessJSON(map[string]interface{}{
  490. "config": config,
  491. })
  492. } else {
  493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  494. return
  495. }
  496. }
  497. func (c *GobalConfigApiController) PostDoctorAdviceConfig() {
  498. is_open_remind, _ := c.GetInt64("is_open_remind", 0)
  499. adminUserInfo := c.GetAdminUserInfo()
  500. org_id := adminUserInfo.CurrentOrgId
  501. config := models.DoctorAdviceConfig{
  502. UserOrgId: org_id,
  503. IsOpenRemind: is_open_remind,
  504. Status: 1,
  505. CreateTime: time.Now().Unix(),
  506. UpdateTime: time.Now().Unix(),
  507. }
  508. errs, configs := service.FindDoctorAdviceRecordByOrgId(org_id)
  509. if errs == gorm.ErrRecordNotFound {
  510. err := service.CreateDoctorAdviceRecord(&config)
  511. if err != nil {
  512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  513. return
  514. }
  515. } else if errs == nil {
  516. modifyConfig := models.DoctorAdviceConfig{
  517. ID: configs.ID,
  518. UserOrgId: org_id,
  519. Status: 1,
  520. CreateTime: time.Now().Unix(),
  521. UpdateTime: time.Now().Unix(),
  522. IsOpenRemind: is_open_remind,
  523. }
  524. err := service.UpdateDoctorAdviceRecord(&modifyConfig)
  525. if err != nil {
  526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  527. return
  528. }
  529. }
  530. c.ServeSuccessJSON(map[string]interface{}{
  531. "is_open_remind": is_open_remind,
  532. })
  533. return
  534. }
  535. func (c *GobalConfigApiController) GetDoctorAdviceConfig() {
  536. adminUserInfo := c.GetAdminUserInfo()
  537. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  538. c.ServeSuccessJSON(map[string]interface{}{
  539. "config": config,
  540. })
  541. }
  542. // SF6090214798525
  543. func (c *GobalConfigApiController) Load(filename string, v interface{}) {
  544. //ReadFile函数会读取文件的全部内容,并将结果以[]byte类型返回
  545. data, err := ioutil.ReadFile(filename)
  546. if err != nil {
  547. return
  548. }
  549. //读取的数据为json格式,需要进行解码
  550. err = json.Unmarshal(data, v)
  551. if err != nil {
  552. return
  553. }
  554. }
  555. type Config struct {
  556. Parent_template []*models.VMDoctorAdviceParentTemplate "json:parent_template"
  557. }
  558. func LoadConfig(dataFile string) *Config {
  559. var config Config
  560. _, filename, _, _ := runtime.Caller(1)
  561. datapath := path.Join(path.Dir(filename), dataFile)
  562. config_file, err := os.Open(datapath)
  563. if err != nil {
  564. emit("Failed to open config file '%s': %s\n", datapath, err)
  565. return &config
  566. }
  567. fi, _ := config_file.Stat()
  568. buffer := make([]byte, fi.Size())
  569. _, err = config_file.Read(buffer)
  570. buffer, err = StripComments(buffer) //去掉注释
  571. if err != nil {
  572. emit("Failed to strip comments from json: %s\n", err)
  573. return &config
  574. }
  575. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  576. err = json.Unmarshal(buffer, &config) //解析json格式数据
  577. if err != nil {
  578. emit("Failed unmarshalling json: %s\n", err)
  579. return &config
  580. }
  581. return &config
  582. }
  583. func StripComments(data []byte) ([]byte, error) {
  584. data = bytes.Replace(data, []byte("\r"), []byte(""), 0) // Windows
  585. lines := bytes.Split(data, []byte("\n")) //split to muli lines
  586. filtered := make([][]byte, 0)
  587. for _, line := range lines {
  588. match, err := regexp.Match(`^\s*#`, line)
  589. if err != nil {
  590. return nil, err
  591. }
  592. if !match {
  593. filtered = append(filtered, line)
  594. }
  595. }
  596. return bytes.Join(filtered, []byte("\n")), nil
  597. }
  598. func emit(msgfmt string, args ...interface{}) {
  599. log.Printf(msgfmt, args...)
  600. }
  601. func (c *GobalConfigApiController) GetAdviceInitConfig() {
  602. adminUserInfo := c.GetAdminUserInfo()
  603. advice_init, _ := service.FindAdviceInitConfig(adminUserInfo.CurrentOrgId)
  604. c.ServeSuccessJSON(map[string]interface{}{
  605. "advice_init": advice_init,
  606. })
  607. }
  608. func (c *GobalConfigApiController) PostInitAdviceTemplate() {
  609. is_init, _ := c.GetInt64("is_init")
  610. adminUserInfo := c.GetAdminUserInfo()
  611. adviceInit := &models.AdviceInit{
  612. UserOrgId: adminUserInfo.CurrentOrgId,
  613. CreateTime: time.Now().Unix(),
  614. UpdateTime: time.Now().Unix(),
  615. Status: 1,
  616. IsInit: is_init,
  617. }
  618. adviceParentTemplate := LoadConfig("./advice_template.json").Parent_template
  619. for _, item := range adviceParentTemplate {
  620. parentTemplate := &models.DoctorAdviceParentTemplate{
  621. OrgId: adminUserInfo.CurrentOrgId,
  622. Name: item.Name,
  623. Status: 1,
  624. CreatedTime: time.Now().Unix(),
  625. UpdatedTime: time.Now().Unix(),
  626. AdviceType: item.AdviceType,
  627. }
  628. createErr := service.CreateDoctorParentTemplate(parentTemplate)
  629. fmt.Println(parentTemplate.ID)
  630. if createErr == nil {
  631. for _, adviceTemplateItem := range item.DoctorAdviceTemplate {
  632. adviceTeplate := &models.DoctorAdviceTemplate{
  633. OrgId: adminUserInfo.CurrentOrgId,
  634. AdviceName: adviceTemplateItem.AdviceName,
  635. AdviceDesc: adviceTemplateItem.AdviceDesc,
  636. SingleDose: adviceTemplateItem.SingleDose,
  637. SingleDoseUnit: adviceTemplateItem.SingleDoseUnit,
  638. PrescribingNumber: adviceTemplateItem.PrescribingNumber,
  639. PrescribingNumberUnit: adviceTemplateItem.PrescribingNumberUnit,
  640. DeliveryWay: adviceTemplateItem.DeliveryWay,
  641. ExecutionFrequency: adviceTemplateItem.ExecutionFrequency,
  642. AdviceDoctor: adviceTemplateItem.AdviceDoctor,
  643. Status: 1,
  644. CreatedTime: time.Now().Unix(),
  645. UpdatedTime: time.Now().Unix(),
  646. TemplateId: parentTemplate.ID,
  647. DrugSpec: adviceTemplateItem.DrugSpec,
  648. DrugSpecUnit: adviceTemplateItem.DrugSpecUnit,
  649. ParentId: adviceTemplateItem.ParentId,
  650. AdviceType: adviceTemplateItem.AdviceType,
  651. DayCount: adviceTemplateItem.DayCount,
  652. WeekDays: adviceTemplateItem.WeekDays,
  653. FrequencyType: adviceTemplateItem.FrequencyType,
  654. }
  655. createErr := service.CreateDoctorTemplate(adviceTeplate)
  656. if createErr == nil {
  657. for _, childItem := range adviceTemplateItem.SubDoctorAdviceTemplate {
  658. adviceTeplate := &models.DoctorAdviceTemplate{
  659. OrgId: adminUserInfo.CurrentOrgId,
  660. AdviceName: childItem.AdviceName,
  661. AdviceDesc: childItem.AdviceDesc,
  662. SingleDose: childItem.SingleDose,
  663. SingleDoseUnit: childItem.SingleDoseUnit,
  664. PrescribingNumber: childItem.PrescribingNumber,
  665. PrescribingNumberUnit: childItem.PrescribingNumberUnit,
  666. DeliveryWay: childItem.DeliveryWay,
  667. ExecutionFrequency: childItem.ExecutionFrequency,
  668. AdviceDoctor: childItem.AdviceDoctor,
  669. Status: 1,
  670. CreatedTime: time.Now().Unix(),
  671. UpdatedTime: time.Now().Unix(),
  672. TemplateId: parentTemplate.ID,
  673. DrugSpec: childItem.DrugSpec,
  674. DrugSpecUnit: childItem.DrugSpecUnit,
  675. ParentId: adviceTeplate.ID,
  676. AdviceType: childItem.AdviceType,
  677. DayCount: childItem.DayCount,
  678. WeekDays: childItem.WeekDays,
  679. FrequencyType: childItem.FrequencyType,
  680. }
  681. service.CreateDoctorTemplate(adviceTeplate)
  682. }
  683. }
  684. }
  685. }
  686. }
  687. err := service.CreateAdviceInitConfig(adviceInit)
  688. if err == nil {
  689. c.ServeSuccessJSON(map[string]interface{}{
  690. "init_config": adviceInit,
  691. })
  692. } else {
  693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  694. return
  695. }
  696. }
  697. func (c *GobalConfigApiController) CreateSystemPrescription() {
  698. adminUserInfo := c.GetAdminUserInfo()
  699. var solution models.SystemPrescription
  700. code := defaultSystemSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  701. if code > 0 {
  702. c.ServeFailJSONWithSGJErrorCode(code)
  703. return
  704. }
  705. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  706. solution.Doctor = adminUserInfo.AdminUser.Id
  707. solution.Status = 1
  708. solution.CreatedTime = time.Now().Unix()
  709. solution.UserOrgId = adminUserInfo.CurrentOrgId
  710. solution.UpdatedTime = time.Now().Unix()
  711. err := service.CreateSystemDialysisSolution(&solution)
  712. if err != nil {
  713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  714. return
  715. }
  716. prescriptions, _ := service.FindAllSystemPrescription(adminUserInfo.CurrentOrgId)
  717. c.ServeSuccessJSON(map[string]interface{}{
  718. "prescription": solution,
  719. "prescriptions": prescriptions,
  720. })
  721. return
  722. }
  723. func (c *GobalConfigApiController) UpdateSystemPrescription() {
  724. id, _ := c.GetInt64("id", 0)
  725. if id <= 0 {
  726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  727. return
  728. }
  729. adminUserInfo := c.GetAdminUserInfo()
  730. solution, _ := service.FindSystemDialysisSolution(adminUserInfo.CurrentOrgId, id)
  731. if solution.ID == 0 {
  732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  733. return
  734. }
  735. code := defaultSystemSolutionFormData(&solution, c.Ctx.Input.RequestBody, "edit")
  736. if code > 0 {
  737. c.ServeFailJSONWithSGJErrorCode(code)
  738. return
  739. }
  740. solution.UpdatedTime = time.Now().Unix()
  741. solution.Doctor = adminUserInfo.AdminUser.Id
  742. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  743. err := service.UpdateSystemDialysisSolution(&solution)
  744. if err != nil {
  745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  746. return
  747. }
  748. c.ServeSuccessJSON(map[string]interface{}{
  749. "msg": "ok",
  750. "prescription": solution,
  751. })
  752. return
  753. }
  754. func (c *GobalConfigApiController) GetAllSystemPrescription() {
  755. adminUserInfo := c.GetAdminUserInfo()
  756. prescriptions, _ := service.FindAllSystemPrescription(adminUserInfo.CurrentOrgId)
  757. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  758. c.ServeSuccessJSON(map[string]interface{}{
  759. "prescriptions": prescriptions,
  760. "stockType": stockType,
  761. })
  762. }
  763. func (c *GobalConfigApiController) GetSystemPrescription() {
  764. adminUserInfo := c.GetAdminUserInfo()
  765. id, _ := c.GetInt64("id", 0)
  766. prescription, _ := service.FindSystemDialysisPrescriptionByMode(adminUserInfo.CurrentOrgId, id)
  767. c.ServeSuccessJSON(map[string]interface{}{
  768. "prescription": prescription,
  769. })
  770. }
  771. func defaultSystemSolutionFormData(solution *models.SystemPrescription, data []byte, method string) (code int) {
  772. dataBody := make(map[string]interface{}, 0)
  773. err := json.Unmarshal(data, &dataBody)
  774. utils.InfoLog(string(data))
  775. if err != nil {
  776. utils.ErrorLog(err.Error())
  777. code = enums.ErrorCodeParamWrong
  778. return
  779. }
  780. if method == "create" {
  781. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  782. utils.ErrorLog("mode")
  783. code = enums.ErrorCodeParamWrong
  784. return
  785. }
  786. mode := int64(dataBody["mode"].(float64))
  787. if mode <= 0 {
  788. utils.ErrorLog("mode <= 0")
  789. code = enums.ErrorCodeParamWrong
  790. return
  791. }
  792. solution.ModeId = mode
  793. }
  794. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  795. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  796. solution.DialysisDuration = dialysisDuration
  797. }
  798. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  799. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  800. solution.TargetUltrafiltration = targetUltrafiltration
  801. }
  802. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  803. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  804. solution.DialysateFormulation = dialysateFormulation
  805. }
  806. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  807. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  808. solution.DialysisDurationHour = int64(dialysisDurationHour)
  809. }
  810. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  811. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  812. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  813. }
  814. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  815. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  816. solution.HemodialysisMachine = hemodialysisMachine
  817. }
  818. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  819. dialyzer := int64(dataBody["dialyzer"].(float64))
  820. solution.Dialyzer = dialyzer
  821. }
  822. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  823. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  824. solution.PerfusionApparatus = perfusionApparatus
  825. }
  826. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  827. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  828. solution.BloodFlowVolume = bloodFlowVolume
  829. }
  830. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  831. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  832. solution.Dewater = dewater
  833. }
  834. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  835. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  836. solution.DisplaceLiqui = displaceLiqui
  837. }
  838. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  839. replacementWay := int64(dataBody["replacement_way"].(float64))
  840. solution.ReplacementWay = replacementWay
  841. }
  842. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  843. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  844. solution.Anticoagulant = anticoagulant
  845. }
  846. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  847. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  848. solution.AnticoagulantShouji = anticoagulantShouji
  849. }
  850. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  851. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  852. solution.AnticoagulantWeichi = anticoagulantWeichi
  853. }
  854. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  855. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  856. solution.AnticoagulantZongliang = anticoagulantZongliang
  857. }
  858. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  859. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  860. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  861. }
  862. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  863. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  864. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  865. }
  866. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  867. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  868. solution.Kalium = kalium
  869. }
  870. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  871. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  872. solution.Sodium = sodium
  873. }
  874. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  875. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  876. solution.Calcium = calcium
  877. }
  878. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  879. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  880. solution.Bicarbonate = bicarbonate
  881. }
  882. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  883. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  884. solution.Glucose = glucose
  885. }
  886. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  887. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  888. // solution.DryWeight = dryWeight
  889. // }
  890. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  891. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  892. solution.DialysateFlow = dialysateFlow
  893. }
  894. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  895. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  896. solution.DialysateTemperature = dialysateTemperature
  897. }
  898. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  899. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  900. solution.Conductivity = conductivity
  901. }
  902. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  903. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  904. solution.ReplacementTotal = replacementTotal
  905. }
  906. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  907. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  908. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  909. }
  910. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  911. body_fluid := int64(dataBody["body_fluid"].(float64))
  912. solution.BodyFluid = body_fluid
  913. }
  914. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  915. body_fluid_other := dataBody["body_fluid_other"].(string)
  916. solution.BodyFluidOther = body_fluid_other
  917. }
  918. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  919. special_medicine := int64(dataBody["special_medicine"].(float64))
  920. solution.SpecialMedicine = special_medicine
  921. }
  922. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  923. special_medicine_other := dataBody["special_medicine_other"].(string)
  924. solution.SpecialMedicineOther = special_medicine_other
  925. }
  926. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  927. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  928. solution.DisplaceLiquiPart = displace_liqui_part
  929. }
  930. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  931. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  932. solution.DisplaceLiquiValue = displace_liqui_value
  933. }
  934. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  935. blood_access := int64(dataBody["blood_access"].(float64))
  936. solution.BloodAccess = blood_access
  937. }
  938. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  939. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  940. solution.Ultrafiltration = ultrafiltration
  941. }
  942. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  943. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  944. solution.TargetKtv = target_ktv
  945. }
  946. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  947. remark := dataBody["remark"].(string)
  948. solution.Remark = remark
  949. }
  950. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  951. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  952. fmt.Println("dialysisDialysis22222222222", dialysisDialyszers)
  953. solution.DialysisDialyszers = dialysisDialyszers
  954. }
  955. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  956. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  957. solution.DialysisIrrigation = dialysisIrrigation
  958. }
  959. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  960. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  961. solution.BloodAccessPartId = blood_access_part_id
  962. }
  963. return
  964. }
  965. func (c *GobalConfigApiController) GetPrintInfo() {
  966. adminUserInfo := c.GetAdminUserInfo()
  967. OrgID := adminUserInfo.CurrentOrgId
  968. dataBody := make(map[string]interface{}, 0)
  969. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  970. idsInters := dataBody["ids"].([]interface{})
  971. advice_type, _ := c.GetInt64("advice_type")
  972. stop_type, _ := c.GetInt64("stop_type")
  973. if len(idsInters) == 0 {
  974. if err != nil {
  975. c.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  976. return
  977. }
  978. }
  979. ids := make([]int64, 0)
  980. for _, idsInter := range idsInters {
  981. id := int64(idsInter.(float64))
  982. ids = append(ids, id)
  983. }
  984. getPrint, err := service.GetPrint(ids, OrgID, advice_type, stop_type)
  985. c.ServeSuccessJSON(map[string]interface{}{
  986. "doctoradvice": getPrint,
  987. })
  988. }
  989. func (c *GobalConfigApiController) GetOrgs() {
  990. adminUserInfo := c.GetAdminUserInfo()
  991. //获取当前人姓名
  992. var id = adminUserInfo.AdminUser.Id
  993. orgId := adminUserInfo.CurrentOrgId
  994. var orgs []*models.Org
  995. adminUser, err := service.GetHomeData(adminUserInfo.AdminUser.Id)
  996. creator, err := service.GetCreator(id, orgId)
  997. admin, err := service.GetSuperAdmin(id)
  998. if err != nil {
  999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1000. return
  1001. }
  1002. for _, item := range adminUser.Org {
  1003. orgs = append(orgs, item)
  1004. }
  1005. for _, item := range adminUser.VMApp_Role {
  1006. for _, subItem := range item.Org {
  1007. orgs = append(orgs, subItem)
  1008. }
  1009. }
  1010. orgs = RemoveRepeatedOrgElement(orgs)
  1011. fmt.Println("~~~~")
  1012. role, _ := service.GetAdminUserInfoByID(orgId, id)
  1013. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  1014. c.ServeSuccessJSON(map[string]interface{}{
  1015. "orgs": orgs,
  1016. "adminUser": adminUser,
  1017. "creator": creator,
  1018. "admin": admin,
  1019. "role": role,
  1020. "org_config": miConfig,
  1021. })
  1022. }
  1023. func (this *GobalConfigApiController) ChangeOrg() {
  1024. org_id, _ := this.GetInt64("org_id")
  1025. adminUserInfo := this.GetAdminUserInfo()
  1026. tempOrg, err := service.GetOrgById(org_id)
  1027. if err != nil {
  1028. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1029. return
  1030. }
  1031. if tempOrg == nil {
  1032. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrgNoExist)
  1033. return
  1034. }
  1035. mobile := adminUserInfo.AdminUser.Mobile
  1036. // 只取最近被创建的 admin_role
  1037. adminUser, getAdminErr := service.GetValidAdminUserByMobileReturnErr(mobile) //账号信息唯一值
  1038. if getAdminErr != nil {
  1039. utils.ErrorLog("获取管理员失败:%v", getAdminErr)
  1040. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1041. this.ServeJSON()
  1042. return
  1043. } else if adminUser == nil {
  1044. utils.ErrorLog("查找不到 mobile = %v 的用户", mobile)
  1045. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
  1046. this.ServeJSON()
  1047. return
  1048. } else {
  1049. adminUserInfo.CurrentOrgId = tempOrg.Id
  1050. orgApp, _ := service.GetOrgApp(tempOrg.Id, 3)
  1051. subscibe, _ := service.GetOrgSubscibe(tempOrg.Id)
  1052. adminUserInfo.CurrentAppId = orgApp.Id
  1053. appRole, _ := service.GetAppRole(tempOrg.Id, orgApp.Id, adminUserInfo.AdminUser.Id)
  1054. var FiledList []*models.FiledConfig
  1055. FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
  1056. if len(FiledList) == 0 {
  1057. err := service.BatchInsertFiledConfig(tempOrg.Id)
  1058. if err == nil {
  1059. FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
  1060. } else {
  1061. utils.ErrorLog("字段批量插入失败:%v", err)
  1062. }
  1063. }
  1064. //产寻该机构是否有收缩压和舒张压
  1065. pressure, err := service.GetDefaultSystolicPressure(tempOrg.Id)
  1066. fmt.Println(err)
  1067. if len(pressure) == 0 {
  1068. err = service.BathInsertQualityControlTwo(tempOrg.Id)
  1069. } else {
  1070. utils.ErrorLog("字段批量插入失败:%v", err)
  1071. }
  1072. major, err := service.GetInspectionMajor(tempOrg.Id)
  1073. if len(major) == 0 {
  1074. QualityeList, err := service.FindQualityByOrgId(tempOrg.Id)
  1075. if len(QualityeList) == 0 {
  1076. err = service.BatchInsertQualityControl(tempOrg.Id)
  1077. } else {
  1078. utils.ErrorLog("字段批量插入失败:%v", err)
  1079. }
  1080. InspectionList, err := service.FindeInspectionByOrgId(tempOrg.Id)
  1081. if len(InspectionList) == 0 {
  1082. err = service.BatchInspectionConfiguration(tempOrg.Id)
  1083. } else {
  1084. utils.ErrorLog("字段批量插入失败:%v", err)
  1085. }
  1086. } else {
  1087. utils.ErrorLog("字段批量插入失败:%v", err)
  1088. }
  1089. //查询该机构是否存在医护排班
  1090. _, errcode := service.GetDoctorScheduleByOrgId(tempOrg.Id)
  1091. //如果没有就插入
  1092. if errcode == gorm.ErrRecordNotFound {
  1093. err = service.BatchInsertDoctorSchedule(tempOrg.Id)
  1094. } else {
  1095. utils.ErrorLog("医护排班默认数据插入失败:%v", err)
  1096. }
  1097. var didRegistedForSCRM bool = false
  1098. var didRegistedForCDM bool = false
  1099. var didRegistedForMall bool = false
  1100. var curAppUrlfors []string
  1101. var pruviews []*models.Purview
  1102. if len(curAppUrlfors) == 0 {
  1103. if adminUser.Id == tempOrg.Creator {
  1104. urlfors_xt, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(3)
  1105. urlfors_cdm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(4)
  1106. urlfors_scrm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(6)
  1107. urlfors_mall, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(7)
  1108. curAppUrlfors = append(curAppUrlfors, urlfors_xt...)
  1109. curAppUrlfors = append(curAppUrlfors, urlfors_scrm...)
  1110. curAppUrlfors = append(curAppUrlfors, urlfors_cdm...)
  1111. curAppUrlfors = append(curAppUrlfors, urlfors_mall...)
  1112. didRegistedForSCRM = true
  1113. didRegistedForCDM = true
  1114. didRegistedForMall = true
  1115. } else {
  1116. appRole, _ := service.FindAdminUserIDA(appRole.Id)
  1117. if appRole.Id > 0 && len(appRole.RoleIds) > 0 {
  1118. role_arr := strings.Split(appRole.RoleIds, ",")
  1119. var ids string
  1120. for _, role_id := range role_arr {
  1121. id, _ := strconv.ParseInt(role_id, 10, 64)
  1122. purview_ids, _ := service.GetRolePurviewIds(id)
  1123. if len(ids) == 0 {
  1124. ids = purview_ids
  1125. } else {
  1126. ids = ids + "," + purview_ids
  1127. }
  1128. }
  1129. if len(ids) != 0 {
  1130. pruviews, _ = service.GetPurviewById(ids)
  1131. for _, item := range pruviews {
  1132. if item.Module == 3 && item.Parentid > 0 {
  1133. fmt.Println(item.Urlfor)
  1134. curAppUrlfors = append(curAppUrlfors, item.Urlfor)
  1135. }
  1136. }
  1137. } else {
  1138. curAppUrlfors = append(curAppUrlfors, "")
  1139. }
  1140. } else {
  1141. curAppUrlfors = append(curAppUrlfors, "")
  1142. }
  1143. for _, item := range pruviews {
  1144. if item.Module == 6 {
  1145. didRegistedForSCRM = true
  1146. }
  1147. if item.Module == 4 {
  1148. didRegistedForCDM = true
  1149. }
  1150. if item.Module == 7 {
  1151. didRegistedForMall = true
  1152. }
  1153. }
  1154. }
  1155. }
  1156. userInfo := map[string]interface{}{
  1157. "id": adminUser.Id,
  1158. "mobile": adminUser.Mobile,
  1159. "user_name": appRole.UserName,
  1160. "avatar": appRole.Avatar,
  1161. "intro": appRole.Intro,
  1162. "user_type": appRole.UserType,
  1163. "user_title": appRole.UserTitle,
  1164. }
  1165. org := map[string]interface{}{
  1166. "id": tempOrg.Id,
  1167. "org_name": tempOrg.OrgName,
  1168. "org_short_name": tempOrg.OrgShortName,
  1169. "org_intro": tempOrg.OrgIntroduction,
  1170. "org_logo": tempOrg.OrgLogo,
  1171. "province": tempOrg.Province,
  1172. "city": tempOrg.City,
  1173. "district": tempOrg.District,
  1174. "address": tempOrg.Address,
  1175. }
  1176. tempInfo, _ := service.GetOrgInfoTemplate(tempOrg.Id)
  1177. template_info := map[string]interface{}{
  1178. "id": tempInfo.ID,
  1179. "org_id": tempInfo.OrgId,
  1180. "template_id": tempInfo.TemplateId,
  1181. }
  1182. if tempOrg != nil && appRole != nil {
  1183. // 插入一条登录记录
  1184. ip := this.GetString("ip")
  1185. loginLog := &models.AdminUserLoginLog{
  1186. AdminUserId: adminUser.Id,
  1187. OrgId: tempOrg.Id,
  1188. AppId: appRole.AppId,
  1189. IP: ip,
  1190. OperateType: 3,
  1191. AppType: 3,
  1192. CreateTime: time.Now().Unix(),
  1193. }
  1194. if insertErr := service.InsertLoginLog(loginLog); insertErr != nil {
  1195. utils.ErrorLog("为手机号为%v的用户插入一条登录记录失败:%v", mobile, insertErr)
  1196. }
  1197. }
  1198. this.SetSession("admin_user_info", adminUserInfo)
  1199. this.ServeSuccessJSON(map[string]interface{}{
  1200. "user": userInfo,
  1201. "org": org,
  1202. "urlfors": curAppUrlfors,
  1203. "current_org_id": adminUserInfo.CurrentOrgId,
  1204. "current_app_id": adminUserInfo.CurrentAppId,
  1205. "subscibe": subscibe,
  1206. "template_info": template_info,
  1207. "fileds": FiledList,
  1208. "scrm_role_exist": didRegistedForSCRM,
  1209. "cdm_role_exist": didRegistedForCDM,
  1210. "mall_role_exist": didRegistedForMall,
  1211. })
  1212. }
  1213. }
  1214. func RemoveRepeatedOrgElement(orgs []*models.Org) (newOrgs []*models.Org) {
  1215. newOrgs = make([]*models.Org, 0)
  1216. for i := 0; i < len(orgs); i++ {
  1217. repeat := false
  1218. for j := i + 1; j < len(orgs); j++ {
  1219. if orgs[i].Id == orgs[j].Id {
  1220. repeat = true
  1221. break
  1222. }
  1223. }
  1224. if !repeat {
  1225. newOrgs = append(newOrgs, orgs[i])
  1226. }
  1227. }
  1228. return
  1229. }
  1230. func (this *GobalConfigApiController) GenerateLog() {
  1231. log_type, _ := this.GetInt64("log_type", 0)
  1232. logs, err := service.GetExportLogByType(this.GetAdminUserInfo().CurrentOrgId, log_type)
  1233. if err != nil {
  1234. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1235. return
  1236. }
  1237. this.ServeSuccessJSON(map[string]interface{}{
  1238. "logs": logs,
  1239. })
  1240. }
  1241. func (this *GobalConfigApiController) GetPatientsByKeyWord() {
  1242. keyWord := this.GetString("keyword")
  1243. adminUserInfo := this.GetAdminUserInfo()
  1244. patient, err := service.GetPatientsByKey(adminUserInfo.CurrentOrgId, keyWord)
  1245. if err != nil {
  1246. utils.ErrorLog(err.Error())
  1247. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1248. return
  1249. }
  1250. this.ServeSuccessJSON(map[string]interface{}{
  1251. "patient": patient,
  1252. })
  1253. }
  1254. func (c *GobalConfigApiController) PostXTHisConfig() {
  1255. is_open, _ := c.GetBool("is_open", false)
  1256. adminUserInfo := c.GetAdminUserInfo()
  1257. org_id := adminUserInfo.CurrentOrgId
  1258. isOpen := 0
  1259. if is_open {
  1260. isOpen = 1
  1261. } else {
  1262. isOpen = 2
  1263. }
  1264. config := models.XtHisConfig{
  1265. UserOrgId: org_id,
  1266. IsOpen: int64(isOpen),
  1267. Status: 1,
  1268. Ctime: time.Now().Unix(),
  1269. Mtime: time.Now().Unix(),
  1270. }
  1271. errs, configs := service.FindXTHisRecordByOrgId(org_id)
  1272. if errs == gorm.ErrRecordNotFound {
  1273. err := service.CreateXTHisRecord(&config)
  1274. if err != nil {
  1275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1276. return
  1277. }
  1278. } else if errs == nil {
  1279. modifyConfig := models.XtHisConfig{
  1280. ID: configs.ID,
  1281. UserOrgId: org_id,
  1282. Status: 1,
  1283. Ctime: time.Now().Unix(),
  1284. Mtime: time.Now().Unix(),
  1285. IsOpen: int64(isOpen),
  1286. }
  1287. err := service.UpdateXTHisRecord(&modifyConfig)
  1288. redis := service.RedisClient()
  1289. defer redis.Close()
  1290. key := strconv.FormatInt(org_id, 10) + ":" + ":his_config"
  1291. redis.Set(key, "", time.Second)
  1292. if err != nil {
  1293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1294. return
  1295. }
  1296. }
  1297. c.ServeSuccessJSON(map[string]interface{}{
  1298. "is_open": is_open,
  1299. })
  1300. return
  1301. }
  1302. func (c *GobalConfigApiController) PostHisStockPriceConfig() {
  1303. is_open, _ := c.GetBool("is_open", false)
  1304. adminUserInfo := c.GetAdminUserInfo()
  1305. org_id := adminUserInfo.CurrentOrgId
  1306. isOpen := 0
  1307. if is_open {
  1308. isOpen = 1
  1309. } else {
  1310. isOpen = 2
  1311. }
  1312. config := models.HisStockPriceConfig{
  1313. UserOrgId: org_id,
  1314. IsOpen: int64(isOpen),
  1315. Status: 1,
  1316. Ctime: time.Now().Unix(),
  1317. Mtime: time.Now().Unix(),
  1318. }
  1319. errs, configs := service.FindHisStockPriceRecordByOrgId(org_id)
  1320. if errs == gorm.ErrRecordNotFound {
  1321. err := service.CreateHisStockPriceRecord(&config)
  1322. if err != nil {
  1323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1324. return
  1325. }
  1326. } else if errs == nil {
  1327. modifyConfig := models.HisStockPriceConfig{
  1328. ID: configs.ID,
  1329. UserOrgId: org_id,
  1330. Status: 1,
  1331. Ctime: time.Now().Unix(),
  1332. Mtime: time.Now().Unix(),
  1333. IsOpen: int64(isOpen),
  1334. }
  1335. err := service.UpdateHisStockPriceRecord(&modifyConfig)
  1336. if err != nil {
  1337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1338. return
  1339. }
  1340. }
  1341. c.ServeSuccessJSON(map[string]interface{}{
  1342. "is_open": is_open,
  1343. })
  1344. return
  1345. }
  1346. func (c *GobalConfigApiController) PostXTHisProjectConfig() {
  1347. is_open, _ := c.GetBool("is_open", false)
  1348. adminUserInfo := c.GetAdminUserInfo()
  1349. org_id := adminUserInfo.CurrentOrgId
  1350. isOpen := 0
  1351. if is_open {
  1352. isOpen = 1
  1353. } else {
  1354. isOpen = 2
  1355. }
  1356. config := models.XtHisProjectConfig{
  1357. UserOrgId: org_id,
  1358. IsOpen: int64(isOpen),
  1359. Status: 1,
  1360. Ctime: time.Now().Unix(),
  1361. Mtime: time.Now().Unix(),
  1362. }
  1363. errs, configs := service.FindXTHisProjectByOrgId(org_id)
  1364. if errs == gorm.ErrRecordNotFound {
  1365. err := service.CreateXTHisProjectRecord(&config)
  1366. redis := service.RedisClient()
  1367. key := strconv.FormatInt(org_id, 10) + ":his_project_config"
  1368. redis.Set(key, "", time.Second)
  1369. defer redis.Close()
  1370. if err != nil {
  1371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1372. return
  1373. }
  1374. } else if errs == nil {
  1375. modifyConfig := models.XtHisProjectConfig{
  1376. ID: configs.ID,
  1377. UserOrgId: org_id,
  1378. Status: 1,
  1379. Ctime: time.Now().Unix(),
  1380. Mtime: time.Now().Unix(),
  1381. IsOpen: int64(isOpen),
  1382. }
  1383. err := service.UpdateXTHisProjectRecord(&modifyConfig)
  1384. if err != nil {
  1385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1386. return
  1387. }
  1388. }
  1389. c.ServeSuccessJSON(map[string]interface{}{
  1390. "is_open": is_open,
  1391. })
  1392. return
  1393. }
  1394. func (c *GobalConfigApiController) GetXTHisConfig() {
  1395. adminUserInfo := c.GetAdminUserInfo()
  1396. _, config := service.FindXTHisRecordByOrgId(adminUserInfo.CurrentOrgId)
  1397. _, project_config := service.FindXTHisProjectByOrgId(adminUserInfo.CurrentOrgId)
  1398. c.ServeSuccessJSON(map[string]interface{}{
  1399. "config": config,
  1400. "project_config": project_config,
  1401. })
  1402. }
  1403. func (c *GobalConfigApiController) GetHisStockPriceConfig() {
  1404. adminUserInfo := c.GetAdminUserInfo()
  1405. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1406. c.ServeSuccessJSON(map[string]interface{}{
  1407. "config": config,
  1408. })
  1409. }
  1410. func (c *GobalConfigApiController) GetAllIsOpenConfig() {
  1411. adminUserInfo := c.GetAdminUserInfo()
  1412. _, config := service.FindXTHisRecordByOrgId(adminUserInfo.CurrentOrgId)
  1413. _, project_config := service.FindXTHisProjectByOrgIdOne(adminUserInfo.CurrentOrgId)
  1414. stockSetting, _ := service.FindStockSettingById(adminUserInfo.CurrentOrgId)
  1415. adviceSetting, _ := service.FindAdviceSettingById(adminUserInfo.CurrentOrgId)
  1416. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminUserInfo.CurrentOrgId)
  1417. drugOutConfig, _ := service.FindDrugOutConfigById(adminUserInfo.CurrentOrgId)
  1418. drugSettleConfig, _ := service.FindeDrugSettleConfigById(adminUserInfo.CurrentOrgId)
  1419. goodOutConfig, _ := service.FindGoodOutConfigById(adminUserInfo.CurrentOrgId)
  1420. drugCodeOpen, _ := service.GetDrugCodeOpen(adminUserInfo.CurrentOrgId)
  1421. c.ServeSuccessJSON(map[string]interface{}{
  1422. "is_open_xt_his": config.IsOpen,
  1423. "is_open_xt_his_project": project_config.IsOpen,
  1424. "is_open_stock": stockSetting.IsType,
  1425. "is_open_advice": adviceSetting.IsAdviceOpen,
  1426. "is_prescription_advice": prescriptionConfig.IsOpen,
  1427. "is_open": drugOutConfig.IsOpen,
  1428. "is_seetle_open": drugSettleConfig.IsOpen,
  1429. "is_out_open": goodOutConfig.IsOpen,
  1430. "is_code_open": drugCodeOpen.IsOpen,
  1431. })
  1432. }
  1433. func (c *GobalConfigApiController) GetPassExportData() {
  1434. }
  1435. func (c *GobalConfigApiController) GetExportData() {
  1436. start_time := c.GetString("start_time")
  1437. end_time := c.GetString("end_time")
  1438. p_type, _ := c.GetInt64("p_type")
  1439. ex_type, _ := c.GetInt64("sort_type")
  1440. timeLayout := "2006-01-02"
  1441. loc, _ := time.LoadLocation("Local")
  1442. var startTime int64
  1443. if len(start_time) > 0 {
  1444. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1445. if err != nil {
  1446. fmt.Println(err)
  1447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1448. return
  1449. }
  1450. startTime = theTime.Unix()
  1451. }
  1452. var endTime int64
  1453. if len(end_time) > 0 {
  1454. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1455. if err != nil {
  1456. utils.ErrorLog(err.Error())
  1457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1458. return
  1459. }
  1460. endTime = theTime.Unix()
  1461. }
  1462. adminInfo := c.GetAdminUserInfo()
  1463. var order []*models.HisOrder
  1464. if ex_type == 1 {
  1465. order, _ = service.GetExportHisOrderList(adminInfo.CurrentOrgId, startTime, endTime, p_type)
  1466. } else {
  1467. order, _ = service.GetExportHisOrderListBySetlTIME(adminInfo.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", p_type)
  1468. }
  1469. c.ServeSuccessJSON(map[string]interface{}{
  1470. "order": order,
  1471. })
  1472. }
  1473. func (c *GobalConfigApiController) GetDrugInDetail() {
  1474. start_time := c.GetString("start_time")
  1475. end_time := c.GetString("end_time")
  1476. storehouse_id, _ := c.GetInt64("storehouse_id")
  1477. timeLayout := "2006-01-02"
  1478. loc, _ := time.LoadLocation("Local")
  1479. var startTime int64
  1480. if len(start_time) > 0 {
  1481. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1482. if err != nil {
  1483. fmt.Println(err)
  1484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1485. return
  1486. }
  1487. startTime = theTime.Unix()
  1488. }
  1489. var endTime int64
  1490. if len(end_time) > 0 {
  1491. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1492. if err != nil {
  1493. utils.ErrorLog(err.Error())
  1494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1495. return
  1496. }
  1497. endTime = theTime.Unix()
  1498. }
  1499. adminInfo := c.GetAdminUserInfo()
  1500. order_type, _ := c.GetInt64("order_type")
  1501. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1502. keyword := c.GetString("keyword")
  1503. page, _ := c.GetInt64("page")
  1504. limit, _ := c.GetInt64("limit")
  1505. detail, total, err := service.GetDrugInOrderDetail(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit, storehouse_id)
  1506. var drugType = "药品类型"
  1507. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  1508. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminInfo.CurrentOrgId)
  1509. houseList, _ := service.GetAllStorehouseName(adminInfo.CurrentOrgId)
  1510. if err != nil {
  1511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1512. return
  1513. }
  1514. c.ServeSuccessJSON(map[string]interface{}{
  1515. "detail": detail,
  1516. "total": total,
  1517. "drugTypeParent": drugTypeList,
  1518. "houseList": houseList,
  1519. })
  1520. }
  1521. func (c *GobalConfigApiController) GetDrugCancelOrder() {
  1522. start_time := c.GetString("start_time")
  1523. end_time := c.GetString("end_time")
  1524. timeLayout := "2006-01-02"
  1525. loc, _ := time.LoadLocation("Local")
  1526. var startTime int64
  1527. if len(start_time) > 0 {
  1528. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1529. if err != nil {
  1530. fmt.Println(err)
  1531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1532. return
  1533. }
  1534. startTime = theTime.Unix()
  1535. }
  1536. var endTime int64
  1537. if len(end_time) > 0 {
  1538. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1539. if err != nil {
  1540. utils.ErrorLog(err.Error())
  1541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1542. return
  1543. }
  1544. endTime = theTime.Unix()
  1545. }
  1546. adminInfo := c.GetAdminUserInfo()
  1547. order_type, _ := c.GetInt64("order_type")
  1548. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1549. keyword := c.GetString("keyword")
  1550. limit, _ := c.GetInt64("limit")
  1551. page, _ := c.GetInt64("page")
  1552. order, total, err := service.GetDrugReturnOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, limit, page)
  1553. if err != nil {
  1554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1555. return
  1556. }
  1557. c.ServeSuccessJSON(map[string]interface{}{
  1558. "order": order,
  1559. "total": total,
  1560. })
  1561. }
  1562. func (c *GobalConfigApiController) GetDrugOutDetail() {
  1563. start_time := c.GetString("start_time")
  1564. end_time := c.GetString("end_time")
  1565. storehouse_id, _ := c.GetInt64("storehouse_id")
  1566. timeLayout := "2006-01-02"
  1567. loc, _ := time.LoadLocation("Local")
  1568. var startTime int64
  1569. if len(start_time) > 0 {
  1570. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1571. if err != nil {
  1572. fmt.Println(err)
  1573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1574. return
  1575. }
  1576. startTime = theTime.Unix()
  1577. }
  1578. var endTime int64
  1579. if len(end_time) > 0 {
  1580. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1581. if err != nil {
  1582. utils.ErrorLog(err.Error())
  1583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1584. return
  1585. }
  1586. endTime = theTime.Unix()
  1587. }
  1588. adminInfo := c.GetAdminUserInfo()
  1589. order_type, _ := c.GetInt64("order_type")
  1590. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1591. keyword := c.GetString("keyword")
  1592. limit, _ := c.GetInt64("limit")
  1593. page, _ := c.GetInt64("page")
  1594. order, total, err := service.GetDrugOutOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit, storehouse_id)
  1595. houseList, _ := service.GetAllStoreHouseList(adminInfo.CurrentOrgId)
  1596. patientsList, _ := service.GetAllpatient(adminInfo.CurrentOrgId)
  1597. var drugType = "药品类型"
  1598. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  1599. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminInfo.CurrentOrgId)
  1600. if err != nil {
  1601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1602. return
  1603. }
  1604. c.ServeSuccessJSON(map[string]interface{}{
  1605. "order": order,
  1606. "total": total,
  1607. "drugTypeList": drugTypeList,
  1608. "houseList": houseList,
  1609. "patientsList": patientsList,
  1610. })
  1611. }
  1612. func (c *GobalConfigApiController) GetDrugCancelDetail() {
  1613. start_time := c.GetString("start_time")
  1614. end_time := c.GetString("end_time")
  1615. storehouse_id, _ := c.GetInt64("storehouse_id")
  1616. timeLayout := "2006-01-02"
  1617. loc, _ := time.LoadLocation("Local")
  1618. var startTime int64
  1619. if len(start_time) > 0 {
  1620. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1621. if err != nil {
  1622. fmt.Println(err)
  1623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1624. return
  1625. }
  1626. startTime = theTime.Unix()
  1627. }
  1628. var endTime int64
  1629. if len(end_time) > 0 {
  1630. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1631. if err != nil {
  1632. utils.ErrorLog(err.Error())
  1633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1634. return
  1635. }
  1636. endTime = theTime.Unix()
  1637. }
  1638. adminInfo := c.GetAdminUserInfo()
  1639. order_type, _ := c.GetInt64("order_type")
  1640. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1641. keyword := c.GetString("keyword")
  1642. limit, _ := c.GetInt64("limit")
  1643. page, _ := c.GetInt64("page")
  1644. orderPrint, _ := service.GetDrugCancelOrderPrint(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, storehouse_id)
  1645. order, total, err := service.GetDrugCancelOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit, storehouse_id)
  1646. var drugType = "药品类型"
  1647. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  1648. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminInfo.CurrentOrgId)
  1649. houseList, _ := service.GetAllStoreHouseList(adminInfo.CurrentOrgId)
  1650. dealerList, _ := service.GetAllDealerList(adminInfo.CurrentOrgId)
  1651. manufacturerList, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1652. patientsList, _ := service.GetAllpatient(adminInfo.CurrentOrgId)
  1653. if err != nil {
  1654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1655. return
  1656. }
  1657. c.ServeSuccessJSON(map[string]interface{}{
  1658. "order": order,
  1659. "total": total,
  1660. "orderPrint": orderPrint,
  1661. "drugTypeList": drugTypeList,
  1662. "houseList": houseList,
  1663. "dealerList": dealerList,
  1664. "manufacturerList": manufacturerList,
  1665. "patientsList": patientsList,
  1666. })
  1667. }
  1668. func (c *GobalConfigApiController) AddMonitorOpen() {
  1669. is_open, _ := c.GetInt64("is_open")
  1670. fmt.Println("is_open22222222", is_open)
  1671. adminUserInfo := c.GetAdminUserInfo()
  1672. orgId := adminUserInfo.CurrentOrgId
  1673. config := models.XtMonitorConfig{
  1674. IsOpen: is_open,
  1675. UserOrgId: orgId,
  1676. Status: 1,
  1677. Ctime: time.Now().Unix(),
  1678. }
  1679. //查询该机构是否存在
  1680. _, errcode := service.GetMonitorConfigById(orgId)
  1681. if errcode == gorm.ErrRecordNotFound {
  1682. err := service.AddMonitorOpen(&config)
  1683. if err != nil {
  1684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1685. return
  1686. }
  1687. c.ServeSuccessJSON(map[string]interface{}{
  1688. "config": config,
  1689. })
  1690. } else if errcode == nil {
  1691. err := service.UpdateMonitorOpen(orgId, &config)
  1692. fmt.Println("err", err)
  1693. }
  1694. }
  1695. func (c *GobalConfigApiController) GetMonitorConfig() {
  1696. userInfo := c.GetAdminUserInfo()
  1697. orgId := userInfo.CurrentOrgId
  1698. config, err := service.GetMonitorConfig(orgId)
  1699. if err != nil {
  1700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1701. return
  1702. }
  1703. c.ServeSuccessJSON(map[string]interface{}{
  1704. "config": config,
  1705. })
  1706. }
  1707. func (c *GobalConfigApiController) AddOrderConfig() {
  1708. is_open, _ := c.GetInt64("is_open")
  1709. fmt.Println("344555555555555", is_open)
  1710. adminUserInfo := c.GetAdminUserInfo()
  1711. orgId := adminUserInfo.CurrentOrgId
  1712. config := models.XtOrderConfig{
  1713. IsOpen: is_open,
  1714. UserOrgId: orgId,
  1715. Status: 1,
  1716. Ctime: time.Now().Unix(),
  1717. }
  1718. //查询
  1719. _, errcode := service.GetOrderConfigById(orgId)
  1720. if errcode == gorm.ErrRecordNotFound {
  1721. err := service.AddOrderConfig(&config)
  1722. if err != nil {
  1723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1724. return
  1725. }
  1726. c.ServeSuccessJSON(map[string]interface{}{
  1727. "config": config,
  1728. })
  1729. } else if errcode == nil {
  1730. err := service.UpdateOrderConfig(orgId, &config)
  1731. fmt.Println("2222", err)
  1732. }
  1733. }
  1734. func (c *GobalConfigApiController) GetOrderConfig() {
  1735. adminUserInfo := c.GetAdminUserInfo()
  1736. orgId := adminUserInfo.CurrentOrgId
  1737. config, err := service.GetOrderConfig(orgId)
  1738. if err != nil {
  1739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1740. return
  1741. }
  1742. c.ServeSuccessJSON(map[string]interface{}{
  1743. "config": config,
  1744. })
  1745. }
  1746. func (c *GobalConfigApiController) GetDrugAutoMaticList() {
  1747. adminUserInfo := c.GetAdminUserInfo()
  1748. orgId := adminUserInfo.CurrentOrgId
  1749. warehous_out_id, _ := c.GetInt64("warehous_out_id")
  1750. record_time, _ := c.GetInt64("record_time")
  1751. warehouse_out_order_number := c.GetString("warehouse_out_order_number")
  1752. drugConfig, _ := service.GetDrugStockConfig(orgId)
  1753. list, err := service.GetDrugAutoMaticList(orgId, warehous_out_id, record_time, warehouse_out_order_number)
  1754. drugList, err := service.GetAllBaseDrugList(orgId)
  1755. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1756. if err != nil {
  1757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1758. return
  1759. }
  1760. c.ServeSuccessJSON(map[string]interface{}{
  1761. "list": list,
  1762. "drugConfig": drugConfig,
  1763. "drugList": drugList,
  1764. "manufacturerList": manufacturerList,
  1765. })
  1766. }
  1767. func (c *GobalConfigApiController) GetDrugWarehuseOrderInfo() {
  1768. adminUserInfo := c.GetAdminUserInfo()
  1769. orgId := adminUserInfo.CurrentOrgId
  1770. list, _ := service.GetDrugWarehuseOrderInfo(orgId)
  1771. c.ServeSuccessJSON(map[string]interface{}{
  1772. "list": list,
  1773. })
  1774. }
  1775. func (c *GobalConfigApiController) GetDrugStockList() {
  1776. page, _ := c.GetInt64("page", -1)
  1777. limit, _ := c.GetInt64("limit", -1)
  1778. keyword := c.GetString("keyword")
  1779. drug_type, _ := c.GetInt64("drug_type")
  1780. start_time := c.GetString("start_time")
  1781. end_time := c.GetString("end_time")
  1782. timeLayout := "2006-01-02"
  1783. loc, _ := time.LoadLocation("Local")
  1784. storehouse_id, _ := c.GetInt64("storehouse_id")
  1785. drug_id, _ := c.GetInt64("drug_id")
  1786. var startTime int64
  1787. if len(start_time) > 0 {
  1788. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1789. if err != nil {
  1790. fmt.Println(err)
  1791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1792. return
  1793. }
  1794. startTime = theTime.Unix()
  1795. }
  1796. var endTime int64
  1797. if len(end_time) > 0 {
  1798. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1799. if err != nil {
  1800. utils.ErrorLog(err.Error())
  1801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1802. return
  1803. }
  1804. endTime = theTime.Unix()
  1805. }
  1806. adminUserInfo := c.GetAdminUserInfo()
  1807. list, total, err := service.GetAllBaseDurgListCount(page, limit, keyword, drug_type, startTime, endTime, adminUserInfo.CurrentOrgId, storehouse_id, drug_id)
  1808. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  1809. houseList, _ := service.GetAllStoreHouseListOne(adminUserInfo.CurrentOrgId)
  1810. medicalList, _ := service.GetAllBaseDrugStockList(adminUserInfo.CurrentOrgId)
  1811. if err != nil {
  1812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1813. return
  1814. }
  1815. c.ServeSuccessJSON(map[string]interface{}{
  1816. "list": list,
  1817. "total": total,
  1818. "manufacturerList": manufacturerList,
  1819. "houseList": houseList,
  1820. "medicalList": medicalList,
  1821. })
  1822. }
  1823. func (c *GobalConfigApiController) GetDrugStockFllow() {
  1824. drug_id, _ := c.GetInt64("drug_id")
  1825. start_time := c.GetString("start_time")
  1826. end_time := c.GetString("end_time")
  1827. stock_type, _ := c.GetInt64("stock_type")
  1828. page, _ := c.GetInt64("page")
  1829. limit, _ := c.GetInt64("limit")
  1830. timeLayout := "2006-01-02"
  1831. loc, _ := time.LoadLocation("Local")
  1832. var startTime int64
  1833. if len(start_time) > 0 {
  1834. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1835. if err != nil {
  1836. fmt.Println(err)
  1837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1838. return
  1839. }
  1840. startTime = theTime.Unix()
  1841. }
  1842. var endTime int64
  1843. if len(end_time) > 0 {
  1844. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1845. if err != nil {
  1846. utils.ErrorLog(err.Error())
  1847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1848. return
  1849. }
  1850. endTime = theTime.Unix()
  1851. }
  1852. orgId := c.GetAdminUserInfo().CurrentOrgId
  1853. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1854. medical, _ := service.GetBaseDrugMedical(drug_id)
  1855. //查询入库数据
  1856. if stock_type == 3 || stock_type == 0 {
  1857. list, total, err := service.GetDrugStockFlow(drug_id, startTime, endTime, page, limit, orgId)
  1858. if err != nil {
  1859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1860. return
  1861. }
  1862. c.ServeSuccessJSON(map[string]interface{}{
  1863. "list": list,
  1864. "total": total,
  1865. "manufacturerList": manufacturerList,
  1866. "drug": medical,
  1867. })
  1868. }
  1869. }
  1870. func (c *GobalConfigApiController) GetDrugOutStockFlow() {
  1871. drug_id, _ := c.GetInt64("drug_id")
  1872. start_time := c.GetString("start_time")
  1873. end_time := c.GetString("end_time")
  1874. stock_type, _ := c.GetInt64("stock_type")
  1875. page, _ := c.GetInt64("page")
  1876. limit, _ := c.GetInt64("limit")
  1877. timeLayout := "2006-01-02"
  1878. loc, _ := time.LoadLocation("Local")
  1879. var startTime int64
  1880. if len(start_time) > 0 {
  1881. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1882. if err != nil {
  1883. fmt.Println(err)
  1884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1885. return
  1886. }
  1887. startTime = theTime.Unix()
  1888. }
  1889. var endTime int64
  1890. if len(end_time) > 0 {
  1891. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1892. if err != nil {
  1893. utils.ErrorLog(err.Error())
  1894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1895. return
  1896. }
  1897. endTime = theTime.Unix()
  1898. }
  1899. orgId := c.GetAdminUserInfo().CurrentOrgId
  1900. outList, total, err := service.GetDrugStockOutFlow(drug_id, startTime, endTime, page, limit, orgId, stock_type)
  1901. if err != nil {
  1902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1903. return
  1904. }
  1905. c.ServeSuccessJSON(map[string]interface{}{
  1906. "outList": outList,
  1907. "total": total,
  1908. })
  1909. }
  1910. func (c *GobalConfigApiController) GetBatchOrderDetail() {
  1911. drug_id, _ := c.GetInt64("drug_id")
  1912. orgId := c.GetAdminUserInfo().CurrentOrgId
  1913. limit, _ := c.GetInt64("limit")
  1914. page, _ := c.GetInt64("page")
  1915. start_time := c.GetString("start_time")
  1916. end_time := c.GetString("end_time")
  1917. start_first_time := c.GetString("start_first_time")
  1918. end_first_time := c.GetString("end_first_time")
  1919. timeLayout := "2006-01-02"
  1920. loc, _ := time.LoadLocation("Local")
  1921. var startTime int64
  1922. if len(start_time) > 0 {
  1923. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1924. if err != nil {
  1925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1926. return
  1927. }
  1928. startTime = theTime.Unix()
  1929. }
  1930. var endTime int64
  1931. if len(end_time) > 0 {
  1932. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1933. if err != nil {
  1934. utils.ErrorLog(err.Error())
  1935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1936. return
  1937. }
  1938. endTime = theTime.Unix()
  1939. }
  1940. var startFistTime int64
  1941. if len(start_first_time) > 0 {
  1942. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_first_time+" 00:00:00", loc)
  1943. if err != nil {
  1944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1945. return
  1946. }
  1947. startFistTime = theTime.Unix()
  1948. }
  1949. var endFirstTime int64
  1950. if len(end_first_time) > 0 {
  1951. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_first_time+" 23:59:59", loc)
  1952. if err != nil {
  1953. utils.ErrorLog(err.Error())
  1954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1955. return
  1956. }
  1957. endFirstTime = theTime.Unix()
  1958. }
  1959. detail, total, err := service.GetBatchOrderDetail(drug_id, orgId, page, limit, startTime, endTime, startFistTime, endFirstTime)
  1960. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1961. drug, _ := service.GetBaseDrugMedical(drug_id)
  1962. houseList, _ := service.GetAllStoreHouseList(orgId)
  1963. if err != nil {
  1964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1965. return
  1966. }
  1967. c.ServeSuccessJSON(map[string]interface{}{
  1968. "detail": detail,
  1969. "total": total,
  1970. "manufacturerList": manufacturerList,
  1971. "drug": drug,
  1972. "houseList": houseList,
  1973. })
  1974. }
  1975. func (c *GobalConfigApiController) GetDrugCountList() {
  1976. start_time := c.GetString("start_time")
  1977. end_time := c.GetString("end_time")
  1978. timeLayout := "2006-01-02"
  1979. loc, _ := time.LoadLocation("Local")
  1980. var startTime int64
  1981. if len(start_time) > 0 {
  1982. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1983. if err != nil {
  1984. fmt.Println(err)
  1985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1986. return
  1987. }
  1988. startTime = theTime.Unix()
  1989. }
  1990. var endTime int64
  1991. if len(end_time) > 0 {
  1992. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1993. if err != nil {
  1994. utils.ErrorLog(err.Error())
  1995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1996. return
  1997. }
  1998. endTime = theTime.Unix()
  1999. }
  2000. orgId := c.GetAdminUserInfo().CurrentOrgId
  2001. countList, err := service.GetMinCountList(startTime, endTime, orgId)
  2002. outCountList, _ := service.GetOutDrugCountList(startTime, endTime, orgId)
  2003. auCountList, err := service.GetAutoDrugCountList(startTime, endTime, orgId)
  2004. info, _ := service.GetDrugWarehouOrderInfo(startTime, endTime, orgId)
  2005. cancelCountList, _ := service.GetCancelDrugCountList(startTime, endTime, orgId)
  2006. if err != nil {
  2007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2008. return
  2009. }
  2010. c.ServeSuccessJSON(map[string]interface{}{
  2011. "outCountList": outCountList,
  2012. "auCountList": auCountList,
  2013. "minCount": countList,
  2014. "info": info,
  2015. "cancelCountList": cancelCountList,
  2016. })
  2017. }
  2018. func (c *GobalConfigApiController) GetSingleOrderDetail() {
  2019. id, _ := c.GetInt64("id")
  2020. start_time, _ := c.GetInt64("start_time")
  2021. orgId := c.GetAdminUserInfo().CurrentOrgId
  2022. list, err := service.GetSingleOrderDetail(id, orgId)
  2023. drugoutlist, _ := service.GetDrugWarehouseOutDetailNighty(id, orgId)
  2024. dealerList, err := service.GetAllDealerList(orgId)
  2025. manufacturerList, err := service.GetAllManufacturerList(orgId)
  2026. drugFlowList, _ := service.GetDrugStockFlowDetail(start_time, orgId)
  2027. flowlist, _ := service.GetSingeOrderFlow(id, orgId)
  2028. drugList, _ := service.GetDrugFlowList(id, orgId)
  2029. drugListOne, _ := service.GetDrugFlowListGroupByIdOne(id, orgId)
  2030. drugListFlow, err := service.GetDrugFlowListGroupById(id, orgId)
  2031. if err != nil {
  2032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2033. return
  2034. }
  2035. c.ServeSuccessJSON(map[string]interface{}{
  2036. "list": list,
  2037. "dealerList": dealerList,
  2038. "manufacturerList": manufacturerList,
  2039. "drugFlowList": drugFlowList,
  2040. "flowlist": flowlist,
  2041. "drugList": drugList,
  2042. "drugListFlow": drugListFlow,
  2043. "drugListOne": drugListOne,
  2044. "drugoutlist": drugoutlist,
  2045. })
  2046. }
  2047. func (c *GobalConfigApiController) GetAutoDrugDetail() {
  2048. warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
  2049. id, _ := c.GetInt64("drug_id")
  2050. record_time, _ := c.GetInt64("record_time")
  2051. orgId := c.GetAdminUserInfo().CurrentOrgId
  2052. //获取自动出库
  2053. list, err, total := service.FindDrugStockUserDetailByIdThree(id, record_time, orgId)
  2054. //获取手动出库
  2055. outList, err := service.FindeDrugWarehouserInfo(warehouse_out_id, id, orgId)
  2056. batchNumber, err := service.GetDrugFlowBatch(warehouse_out_id, id, orgId)
  2057. if err != nil {
  2058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2059. return
  2060. }
  2061. c.ServeSuccessJSON(map[string]interface{}{
  2062. "list": list,
  2063. "total": total,
  2064. "outList": outList,
  2065. "batchNumber": batchNumber,
  2066. })
  2067. }
  2068. func (c *GobalConfigApiController) GetDrugOrderInPrint() {
  2069. id := c.GetString("id")
  2070. ids := strings.Split(id, ",")
  2071. admin := c.GetAdminUserInfo()
  2072. info, _ := service.FindDrugWarehousingByIdOne(ids, admin.CurrentOrgId)
  2073. manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  2074. warehousingInfo, _ := service.FindDrugWarehousingInfoByIdOne(ids, admin.CurrentOrgId)
  2075. c.ServeSuccessJSON(map[string]interface{}{
  2076. "info": info,
  2077. "warehousing": warehousingInfo,
  2078. "manufacturerList": manufacturerList,
  2079. })
  2080. }
  2081. func (c *GobalConfigApiController) GetDrugOutOrderPrint() {
  2082. id := c.GetString("id")
  2083. ids := strings.Split(id, ",")
  2084. admin := c.GetAdminUserInfo()
  2085. info, _ := service.FindeDrugWarehouseOutOrder(ids, admin.CurrentOrgId)
  2086. manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  2087. warehousing, _ := service.GetExportOutOrderDrugListOne(ids, admin.CurrentOrgId)
  2088. drug_warhouse_out, _ := service.GetDrugWarehouseOutTenty(ids, admin.CurrentOrgId)
  2089. c.ServeSuccessJSON(map[string]interface{}{
  2090. "info": info,
  2091. "warehousing": warehousing,
  2092. "manufacturerList": manufacturerList,
  2093. "drug_warhouse_out": drug_warhouse_out,
  2094. })
  2095. }
  2096. func (c *GobalConfigApiController) GetDrugBatchNumber() {
  2097. id, _ := c.GetInt64("id")
  2098. orgId := c.GetAdminUserInfo().CurrentOrgId
  2099. list, _ := service.GetDrugBatchNumber(id, orgId)
  2100. c.ServeSuccessJSON(map[string]interface{}{
  2101. "list": list,
  2102. })
  2103. }
  2104. func (c *GobalConfigApiController) ExportDrugList() {
  2105. orderId := c.GetString("order_id")
  2106. ids := strings.Split(orderId, ",")
  2107. orgId := c.GetAdminUserInfo().CurrentOrgId
  2108. list, _ := service.ExportDrugList(ids, orgId)
  2109. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2110. dealerList, _ := service.GetAllDealerList(orgId)
  2111. c.ServeSuccessJSON(map[string]interface{}{
  2112. "list": list,
  2113. "manufacturerList": manufacturerList,
  2114. "dealerList": dealerList,
  2115. })
  2116. }
  2117. func (c *GobalConfigApiController) GetExportOutOrderDrugList() {
  2118. orderId := c.GetString("order_id")
  2119. ids := strings.Split(orderId, ",")
  2120. orgId := c.GetAdminUserInfo().CurrentOrgId
  2121. list, _ := service.GetExportOutOrderDrugListOne(ids, orgId)
  2122. outInfoList, _ := service.GetDrugOutListFlow(ids, orgId)
  2123. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2124. dealerList, _ := service.GetAllDealerList(orgId)
  2125. c.ServeSuccessJSON(map[string]interface{}{
  2126. "list": list,
  2127. "manufacturerList": manufacturerList,
  2128. "dealerList": dealerList,
  2129. "outInfoList": outInfoList,
  2130. })
  2131. }
  2132. func (c *GobalConfigApiController) GetDrugFlow() {
  2133. start_time := c.GetString("start_time")
  2134. end_time := c.GetString("end_time")
  2135. timeLayout := "2006-01-02"
  2136. loc, _ := time.LoadLocation("Local")
  2137. var startTime int64
  2138. if len(start_time) > 0 {
  2139. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2140. if err != nil {
  2141. fmt.Println(err)
  2142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2143. return
  2144. }
  2145. startTime = theTime.Unix()
  2146. }
  2147. var endTime int64
  2148. if len(end_time) > 0 {
  2149. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2150. if err != nil {
  2151. utils.ErrorLog(err.Error())
  2152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2153. return
  2154. }
  2155. endTime = theTime.Unix()
  2156. }
  2157. orgId := c.GetAdminUserInfo().CurrentOrgId
  2158. drug_id, _ := c.GetInt64("drug_id")
  2159. page, _ := c.GetInt64("page")
  2160. limit, _ := c.GetInt64("limit")
  2161. stock_type, _ := c.GetInt64("stock_type")
  2162. list, total, _ := service.GetDrugFlow(drug_id, orgId, limit, page, startTime, endTime, stock_type)
  2163. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2164. dealerList, _ := service.GetAllDealerList(orgId)
  2165. medical, _ := service.GetBaseDrugMedical(drug_id)
  2166. houseList, _ := service.GetAllStoreHouseList(orgId)
  2167. patientList, _ := service.GetAllPatientListSix(orgId)
  2168. c.ServeSuccessJSON(map[string]interface{}{
  2169. "list": list,
  2170. "total": total,
  2171. "manufacturerList": manufacturerList,
  2172. "dealerList": dealerList,
  2173. "drug": medical,
  2174. "houseList": houseList,
  2175. "patientList": patientList,
  2176. })
  2177. }
  2178. func (c *GobalConfigApiController) GetCancelStockDetail() {
  2179. id, _ := c.GetInt64("id")
  2180. list, _ := service.GetCancelStockDetail(id)
  2181. c.ServeSuccessJSON(map[string]interface{}{
  2182. "list": list,
  2183. })
  2184. }
  2185. func (c *GobalConfigApiController) ChangeStockSetting() {
  2186. is_type, _ := c.GetInt64("is_type")
  2187. orgId := c.GetAdminUserInfo().CurrentOrgId
  2188. setting := models.XtStockSetting{
  2189. IsType: is_type,
  2190. UserOrgId: orgId,
  2191. Status: 1,
  2192. Ctime: time.Now().Unix(),
  2193. Mtime: 0,
  2194. }
  2195. //查询机该机构是否已经配置
  2196. _, errcode := service.GetStockSettingIsExsit(orgId)
  2197. if errcode == gorm.ErrRecordNotFound {
  2198. service.CreateStockSetting(setting)
  2199. c.ServeSuccessJSON(map[string]interface{}{
  2200. "msg": 1,
  2201. })
  2202. } else if errcode == nil {
  2203. service.UpdateStockSetting(orgId, setting)
  2204. c.ServeSuccessJSON(map[string]interface{}{
  2205. "msg": 1,
  2206. })
  2207. }
  2208. }
  2209. func (c *GobalConfigApiController) ChangeAdviceConfig() {
  2210. is_advice_open, _ := c.GetInt64("is_advice_open")
  2211. orgId := c.GetAdminUserInfo().CurrentOrgId
  2212. setting := models.XtAdviceSetting{
  2213. IsAdviceOpen: is_advice_open,
  2214. UserOrgId: orgId,
  2215. Status: 1,
  2216. Ctime: time.Now().Unix(),
  2217. Mtime: 0,
  2218. }
  2219. //查询是否存在
  2220. _, errcode := service.GetAdviceConfig(orgId)
  2221. if errcode == gorm.ErrRecordNotFound {
  2222. service.CreateAdviceSetting(setting)
  2223. c.ServeSuccessJSON(map[string]interface{}{
  2224. "msg": 1,
  2225. })
  2226. } else if errcode == nil {
  2227. service.UpdateAdviceSetting(orgId, setting)
  2228. c.ServeSuccessJSON(map[string]interface{}{
  2229. "msg": 1,
  2230. })
  2231. }
  2232. }
  2233. func (c *GobalConfigApiController) ChangePrescriptionConfig() {
  2234. is_open_prescription_xt_his, _ := c.GetInt64("is_open_prescription_xt_his")
  2235. orgId := c.GetAdminUserInfo().CurrentOrgId
  2236. _, errcode := service.GetPrescriptionConfig(orgId)
  2237. if errcode == gorm.ErrRecordNotFound {
  2238. config := models.XtPrescriptionConfig{
  2239. UserOrgId: orgId,
  2240. IsOpen: is_open_prescription_xt_his,
  2241. Status: 1,
  2242. Ctime: time.Now().Unix(),
  2243. }
  2244. service.CreatePrescriptionConfig(config)
  2245. c.ServeSuccessJSON(map[string]interface{}{
  2246. "msg": 1,
  2247. })
  2248. } else if errcode == nil {
  2249. config := models.XtPrescriptionConfig{
  2250. UserOrgId: orgId,
  2251. IsOpen: is_open_prescription_xt_his,
  2252. Status: 1,
  2253. Ctime: time.Now().Unix(),
  2254. }
  2255. service.UpdatePrescriptionConfig(orgId, config)
  2256. c.ServeSuccessJSON(map[string]interface{}{
  2257. "msg": 1,
  2258. })
  2259. }
  2260. }
  2261. func (c *GobalConfigApiController) ChangeDrugOpenConfig() {
  2262. drug_out_open, _ := c.GetInt64("drug_out_open")
  2263. orgId := c.GetAdminUserInfo().CurrentOrgId
  2264. if drug_out_open == 1 {
  2265. service.UpdateDrugStockAutomaticReduceRecordOne(orgId, 2)
  2266. service.UpdatePharyConfig(orgId, 2)
  2267. service.UpdateSettleOpenConfigOne(orgId, 2)
  2268. }
  2269. _, errcode := service.GetDrugOpenConfig(orgId)
  2270. if errcode == gorm.ErrRecordNotFound {
  2271. config := models.DrugOutConfig{
  2272. UserOrgId: orgId,
  2273. IsOpen: drug_out_open,
  2274. Status: 1,
  2275. Ctime: time.Now().Unix(),
  2276. }
  2277. service.CreateDrugOutConfig(config)
  2278. c.ServeSuccessJSON(map[string]interface{}{
  2279. "msg": 1,
  2280. })
  2281. } else if errcode == nil {
  2282. service.UpdateDrugOutConfig(orgId, drug_out_open)
  2283. c.ServeSuccessJSON(map[string]interface{}{
  2284. "msg": 1,
  2285. })
  2286. }
  2287. }
  2288. func (this *GobalConfigApiController) ChangeSettleOpenConfig() {
  2289. drug_out_open, _ := this.GetInt64("drug_settle_open")
  2290. orgId := this.GetAdminUserInfo().CurrentOrgId
  2291. config := models.HisSettleStockConfig{
  2292. UserOrgId: orgId,
  2293. Ctime: time.Now().Unix(),
  2294. Mtime: 0,
  2295. Status: 1,
  2296. IsOpen: drug_out_open,
  2297. }
  2298. if drug_out_open == 1 {
  2299. service.UpdateDrugOutConfig(orgId, 2)
  2300. service.UpdateDrugStockAutomaticReduceRecordOne(orgId, 2)
  2301. service.UpdatePharyConfig(orgId, 2)
  2302. service.UpdateGoodAutoConfig(orgId)
  2303. service.UpdateGoodOutConfig(orgId)
  2304. }
  2305. openConfig, errcode := service.GetSettleOpenConfig(orgId)
  2306. if errcode == gorm.ErrRecordNotFound {
  2307. service.CreateSettleOpenConfig(config)
  2308. } else if errcode == nil {
  2309. service.UpdateSettleOpenConfig(openConfig.ID, config)
  2310. }
  2311. this.ServeSuccessJSON(map[string]interface{}{
  2312. "msg": 1,
  2313. })
  2314. }
  2315. func (this *GobalConfigApiController) ChangeGoodOutOpen() {
  2316. good_open, _ := this.GetInt64("good_open")
  2317. orgId := this.GetAdminUserInfo().CurrentOrgId
  2318. config, errcode := service.GetGoodOutOpenConfig(orgId)
  2319. outConfig := models.XtGoodOutConfig{
  2320. UserOrgId: orgId,
  2321. IsOpen: good_open,
  2322. Status: 1,
  2323. Ctime: time.Now().Unix(),
  2324. Mtime: time.Now().Unix(),
  2325. }
  2326. if good_open == 1 {
  2327. service.UpdateGoodAutoConfig(orgId)
  2328. service.UpdateSettleOpenConfigTwo(orgId, 2)
  2329. }
  2330. if errcode == gorm.ErrRecordNotFound {
  2331. service.CreateGoodOutOpenConfig(outConfig)
  2332. } else if errcode == nil {
  2333. service.UpdateGoodOutOpenConfig(config.ID, outConfig)
  2334. }
  2335. this.ServeSuccessJSON(map[string]interface{}{
  2336. "msg": 1,
  2337. })
  2338. }
  2339. func (this *GobalConfigApiController) ChangeSelfPrescriptionOpen() {
  2340. is_open, _ := this.GetInt64("is_open")
  2341. orgId := this.GetAdminUserInfo().CurrentOrgId
  2342. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(orgId)
  2343. config := models.XtSelfDrugInfoConfig{
  2344. ID: selfPrescriptionOpen.ID,
  2345. UserOrgId: orgId,
  2346. Status: 1,
  2347. IsOpen: is_open,
  2348. }
  2349. if selfPrescriptionOpen.ID == 0 {
  2350. service.CreaterSelfConfig(config)
  2351. }
  2352. if selfPrescriptionOpen.ID > 0 {
  2353. service.SaveSelfConfig(config)
  2354. }
  2355. this.ServeSuccessJSON(map[string]interface{}{
  2356. "selfPrescriptionOpen": selfPrescriptionOpen,
  2357. })
  2358. }
  2359. func (this *GobalConfigApiController) ChangeSelfPrescriptionOutOpen() {
  2360. orgId := this.GetAdminUserInfo().CurrentOrgId
  2361. is_open, _ := this.GetInt64("is_open")
  2362. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(orgId)
  2363. config := models.XtSelfDrugOutConfig{
  2364. ID: selfPrescriptionOutOpen.ID,
  2365. UserOrgId: orgId,
  2366. IsOpen: is_open,
  2367. Status: 1,
  2368. }
  2369. if config.ID == 0 {
  2370. service.CreateSelfDrugOutConfig(config)
  2371. }
  2372. if config.ID > 0 {
  2373. service.UpdateSelfDrugOutConfig(config)
  2374. }
  2375. this.ServeSuccessJSON(map[string]interface{}{
  2376. "selfPrescriptionOutOpen": selfPrescriptionOutOpen,
  2377. })
  2378. }
  2379. func (this *GobalConfigApiController) GetSelfPrintList() {
  2380. orgId := this.GetAdminUserInfo().CurrentOrgId
  2381. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(orgId)
  2382. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(orgId)
  2383. this.ServeSuccessJSON(map[string]interface{}{
  2384. "selfPrescriptionOpen": selfPrescriptionOpen,
  2385. "selfPrescriptionOutOpen": selfPrescriptionOutOpen,
  2386. })
  2387. }
  2388. func (this *GobalConfigApiController) ChangeDrugCodeOpen() {
  2389. orgId := this.GetAdminUserInfo().CurrentOrgId
  2390. is_open, _ := this.GetInt64("is_open")
  2391. drugCodeOpen, _ := service.GetDrugCodeOpen(orgId)
  2392. if drugCodeOpen.ID == 0 {
  2393. codeOpen := models.XtDrugCodeOpen{
  2394. UserOrgId: orgId,
  2395. IsOpen: is_open,
  2396. Status: 1,
  2397. Ctime: time.Now().Unix(),
  2398. Mtime: time.Now().Unix(),
  2399. }
  2400. service.CreateDrugOpen(codeOpen)
  2401. }
  2402. if drugCodeOpen.ID == 1 {
  2403. codeOpen := models.XtDrugCodeOpen{
  2404. ID: drugCodeOpen.ID,
  2405. UserOrgId: orgId,
  2406. IsOpen: is_open,
  2407. Status: 1,
  2408. Ctime: time.Now().Unix(),
  2409. Mtime: time.Now().Unix(),
  2410. }
  2411. service.SaveDrugOpen(codeOpen)
  2412. }
  2413. this.ServeSuccessJSON(map[string]interface{}{
  2414. "drugCodeOpen": drugCodeOpen,
  2415. })
  2416. }