gobal_config_api_controller.go 87KB

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