gobal_config_api_controller.go 82KB

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