gobal_config_api_controller.go 86KB

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