gobal_config_api_controller.go 83KB

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