gobal_config_api_controller.go 83KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692
  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. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  956. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  957. solution.BloodAccessPartId = blood_access_part_id
  958. }
  959. return
  960. }
  961. func (c *GobalConfigApiController) GetPrintInfo() {
  962. adminUserInfo := c.GetAdminUserInfo()
  963. OrgID := adminUserInfo.CurrentOrgId
  964. dataBody := make(map[string]interface{}, 0)
  965. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  966. idsInters := dataBody["ids"].([]interface{})
  967. advice_type, _ := c.GetInt64("advice_type")
  968. stop_type, _ := c.GetInt64("stop_type")
  969. if len(idsInters) == 0 {
  970. if err != nil {
  971. c.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  972. return
  973. }
  974. }
  975. ids := make([]int64, 0)
  976. for _, idsInter := range idsInters {
  977. id := int64(idsInter.(float64))
  978. ids = append(ids, id)
  979. }
  980. getPrint, err := service.GetPrint(ids, OrgID, advice_type, stop_type)
  981. c.ServeSuccessJSON(map[string]interface{}{
  982. "doctoradvice": getPrint,
  983. })
  984. }
  985. func (c *GobalConfigApiController) GetOrgs() {
  986. adminUserInfo := c.GetAdminUserInfo()
  987. //获取当前人姓名
  988. var id = adminUserInfo.AdminUser.Id
  989. orgId := adminUserInfo.CurrentOrgId
  990. var orgs []*models.Org
  991. adminUser, err := service.GetHomeData(adminUserInfo.AdminUser.Id)
  992. creator, err := service.GetCreator(id, orgId)
  993. admin, err := service.GetSuperAdmin(id)
  994. if err != nil {
  995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  996. return
  997. }
  998. for _, item := range adminUser.Org {
  999. orgs = append(orgs, item)
  1000. }
  1001. for _, item := range adminUser.VMApp_Role {
  1002. for _, subItem := range item.Org {
  1003. orgs = append(orgs, subItem)
  1004. }
  1005. }
  1006. orgs = RemoveRepeatedOrgElement(orgs)
  1007. fmt.Println("~~~~")
  1008. role, _ := service.GetAdminUserInfoByID(orgId, id)
  1009. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  1010. c.ServeSuccessJSON(map[string]interface{}{
  1011. "orgs": orgs,
  1012. "adminUser": adminUser,
  1013. "creator": creator,
  1014. "admin": admin,
  1015. "role": role,
  1016. "org_config": miConfig,
  1017. })
  1018. }
  1019. func (this *GobalConfigApiController) ChangeOrg() {
  1020. org_id, _ := this.GetInt64("org_id")
  1021. adminUserInfo := this.GetAdminUserInfo()
  1022. tempOrg, err := service.GetOrgById(org_id)
  1023. if err != nil {
  1024. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1025. return
  1026. }
  1027. if tempOrg == nil {
  1028. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrgNoExist)
  1029. return
  1030. }
  1031. mobile := adminUserInfo.AdminUser.Mobile
  1032. // 只取最近被创建的 admin_role
  1033. adminUser, getAdminErr := service.GetValidAdminUserByMobileReturnErr(mobile) //账号信息唯一值
  1034. if getAdminErr != nil {
  1035. utils.ErrorLog("获取管理员失败:%v", getAdminErr)
  1036. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1037. this.ServeJSON()
  1038. return
  1039. } else if adminUser == nil {
  1040. utils.ErrorLog("查找不到 mobile = %v 的用户", mobile)
  1041. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
  1042. this.ServeJSON()
  1043. return
  1044. } else {
  1045. adminUserInfo.CurrentOrgId = tempOrg.Id
  1046. orgApp, _ := service.GetOrgApp(tempOrg.Id, 3)
  1047. subscibe, _ := service.GetOrgSubscibe(tempOrg.Id)
  1048. adminUserInfo.CurrentAppId = orgApp.Id
  1049. appRole, _ := service.GetAppRole(tempOrg.Id, orgApp.Id, adminUserInfo.AdminUser.Id)
  1050. var FiledList []*models.FiledConfig
  1051. FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
  1052. if len(FiledList) == 0 {
  1053. err := service.BatchInsertFiledConfig(tempOrg.Id)
  1054. if err == nil {
  1055. FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
  1056. } else {
  1057. utils.ErrorLog("字段批量插入失败:%v", err)
  1058. }
  1059. }
  1060. //产寻该机构是否有收缩压和舒张压
  1061. pressure, err := service.GetDefaultSystolicPressure(tempOrg.Id)
  1062. fmt.Println(err)
  1063. if len(pressure) == 0 {
  1064. err = service.BathInsertQualityControlTwo(tempOrg.Id)
  1065. } else {
  1066. utils.ErrorLog("字段批量插入失败:%v", err)
  1067. }
  1068. major, err := service.GetInspectionMajor(tempOrg.Id)
  1069. if len(major) == 0 {
  1070. QualityeList, err := service.FindQualityByOrgId(tempOrg.Id)
  1071. if len(QualityeList) == 0 {
  1072. err = service.BatchInsertQualityControl(tempOrg.Id)
  1073. } else {
  1074. utils.ErrorLog("字段批量插入失败:%v", err)
  1075. }
  1076. InspectionList, err := service.FindeInspectionByOrgId(tempOrg.Id)
  1077. if len(InspectionList) == 0 {
  1078. err = service.BatchInspectionConfiguration(tempOrg.Id)
  1079. } else {
  1080. utils.ErrorLog("字段批量插入失败:%v", err)
  1081. }
  1082. } else {
  1083. utils.ErrorLog("字段批量插入失败:%v", err)
  1084. }
  1085. //查询该机构是否存在医护排班
  1086. _, errcode := service.GetDoctorScheduleByOrgId(tempOrg.Id)
  1087. //如果没有就插入
  1088. if errcode == gorm.ErrRecordNotFound {
  1089. err = service.BatchInsertDoctorSchedule(tempOrg.Id)
  1090. } else {
  1091. utils.ErrorLog("医护排班默认数据插入失败:%v", err)
  1092. }
  1093. var didRegistedForSCRM bool = false
  1094. var didRegistedForCDM bool = false
  1095. var didRegistedForMall bool = false
  1096. var curAppUrlfors []string
  1097. var pruviews []*models.Purview
  1098. if len(curAppUrlfors) == 0 {
  1099. if adminUser.Id == tempOrg.Creator {
  1100. urlfors_xt, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(3)
  1101. urlfors_cdm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(4)
  1102. urlfors_scrm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(6)
  1103. urlfors_mall, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(7)
  1104. curAppUrlfors = append(curAppUrlfors, urlfors_xt...)
  1105. curAppUrlfors = append(curAppUrlfors, urlfors_scrm...)
  1106. curAppUrlfors = append(curAppUrlfors, urlfors_cdm...)
  1107. curAppUrlfors = append(curAppUrlfors, urlfors_mall...)
  1108. didRegistedForSCRM = true
  1109. didRegistedForCDM = true
  1110. didRegistedForMall = true
  1111. } else {
  1112. appRole, _ := service.FindAdminUserIDA(appRole.Id)
  1113. if appRole.Id > 0 && len(appRole.RoleIds) > 0 {
  1114. role_arr := strings.Split(appRole.RoleIds, ",")
  1115. var ids string
  1116. for _, role_id := range role_arr {
  1117. id, _ := strconv.ParseInt(role_id, 10, 64)
  1118. purview_ids, _ := service.GetRolePurviewIds(id)
  1119. if len(ids) == 0 {
  1120. ids = purview_ids
  1121. } else {
  1122. ids = ids + "," + purview_ids
  1123. }
  1124. }
  1125. if len(ids) != 0 {
  1126. pruviews, _ = service.GetPurviewById(ids)
  1127. for _, item := range pruviews {
  1128. if item.Module == 3 && item.Parentid > 0 {
  1129. fmt.Println(item.Urlfor)
  1130. curAppUrlfors = append(curAppUrlfors, item.Urlfor)
  1131. }
  1132. }
  1133. } else {
  1134. curAppUrlfors = append(curAppUrlfors, "")
  1135. }
  1136. } else {
  1137. curAppUrlfors = append(curAppUrlfors, "")
  1138. }
  1139. for _, item := range pruviews {
  1140. if item.Module == 6 {
  1141. didRegistedForSCRM = true
  1142. }
  1143. if item.Module == 4 {
  1144. didRegistedForCDM = true
  1145. }
  1146. if item.Module == 7 {
  1147. didRegistedForMall = true
  1148. }
  1149. }
  1150. }
  1151. }
  1152. userInfo := map[string]interface{}{
  1153. "id": adminUser.Id,
  1154. "mobile": adminUser.Mobile,
  1155. "user_name": appRole.UserName,
  1156. "avatar": appRole.Avatar,
  1157. "intro": appRole.Intro,
  1158. "user_type": appRole.UserType,
  1159. "user_title": appRole.UserTitle,
  1160. }
  1161. org := map[string]interface{}{
  1162. "id": tempOrg.Id,
  1163. "org_name": tempOrg.OrgName,
  1164. "org_short_name": tempOrg.OrgShortName,
  1165. "org_intro": tempOrg.OrgIntroduction,
  1166. "org_logo": tempOrg.OrgLogo,
  1167. "province": tempOrg.Province,
  1168. "city": tempOrg.City,
  1169. "district": tempOrg.District,
  1170. "address": tempOrg.Address,
  1171. }
  1172. tempInfo, _ := service.GetOrgInfoTemplate(tempOrg.Id)
  1173. template_info := map[string]interface{}{
  1174. "id": tempInfo.ID,
  1175. "org_id": tempInfo.OrgId,
  1176. "template_id": tempInfo.TemplateId,
  1177. }
  1178. if tempOrg != nil && appRole != nil {
  1179. // 插入一条登录记录
  1180. ip := this.GetString("ip")
  1181. loginLog := &models.AdminUserLoginLog{
  1182. AdminUserId: adminUser.Id,
  1183. OrgId: tempOrg.Id,
  1184. AppId: appRole.AppId,
  1185. IP: ip,
  1186. OperateType: 3,
  1187. AppType: 3,
  1188. CreateTime: time.Now().Unix(),
  1189. }
  1190. if insertErr := service.InsertLoginLog(loginLog); insertErr != nil {
  1191. utils.ErrorLog("为手机号为%v的用户插入一条登录记录失败:%v", mobile, insertErr)
  1192. }
  1193. }
  1194. this.SetSession("admin_user_info", adminUserInfo)
  1195. this.ServeSuccessJSON(map[string]interface{}{
  1196. "user": userInfo,
  1197. "org": org,
  1198. "urlfors": curAppUrlfors,
  1199. "current_org_id": adminUserInfo.CurrentOrgId,
  1200. "current_app_id": adminUserInfo.CurrentAppId,
  1201. "subscibe": subscibe,
  1202. "template_info": template_info,
  1203. "fileds": FiledList,
  1204. "scrm_role_exist": didRegistedForSCRM,
  1205. "cdm_role_exist": didRegistedForCDM,
  1206. "mall_role_exist": didRegistedForMall,
  1207. })
  1208. }
  1209. }
  1210. func RemoveRepeatedOrgElement(orgs []*models.Org) (newOrgs []*models.Org) {
  1211. newOrgs = make([]*models.Org, 0)
  1212. for i := 0; i < len(orgs); i++ {
  1213. repeat := false
  1214. for j := i + 1; j < len(orgs); j++ {
  1215. if orgs[i].Id == orgs[j].Id {
  1216. repeat = true
  1217. break
  1218. }
  1219. }
  1220. if !repeat {
  1221. newOrgs = append(newOrgs, orgs[i])
  1222. }
  1223. }
  1224. return
  1225. }
  1226. func (this *GobalConfigApiController) GenerateLog() {
  1227. log_type, _ := this.GetInt64("log_type", 0)
  1228. logs, err := service.GetExportLogByType(this.GetAdminUserInfo().CurrentOrgId, log_type)
  1229. if err != nil {
  1230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1231. return
  1232. }
  1233. this.ServeSuccessJSON(map[string]interface{}{
  1234. "logs": logs,
  1235. })
  1236. }
  1237. func (this *GobalConfigApiController) GetPatientsByKeyWord() {
  1238. keyWord := this.GetString("keyword")
  1239. adminUserInfo := this.GetAdminUserInfo()
  1240. patient, err := service.GetPatientsByKey(adminUserInfo.CurrentOrgId, keyWord)
  1241. if err != nil {
  1242. utils.ErrorLog(err.Error())
  1243. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1244. return
  1245. }
  1246. this.ServeSuccessJSON(map[string]interface{}{
  1247. "patient": patient,
  1248. })
  1249. }
  1250. func (c *GobalConfigApiController) PostXTHisConfig() {
  1251. is_open, _ := c.GetBool("is_open", false)
  1252. adminUserInfo := c.GetAdminUserInfo()
  1253. org_id := adminUserInfo.CurrentOrgId
  1254. isOpen := 0
  1255. if is_open {
  1256. isOpen = 1
  1257. } else {
  1258. isOpen = 2
  1259. }
  1260. config := models.XtHisConfig{
  1261. UserOrgId: org_id,
  1262. IsOpen: int64(isOpen),
  1263. Status: 1,
  1264. Ctime: time.Now().Unix(),
  1265. Mtime: time.Now().Unix(),
  1266. }
  1267. errs, configs := service.FindXTHisRecordByOrgId(org_id)
  1268. if errs == gorm.ErrRecordNotFound {
  1269. err := service.CreateXTHisRecord(&config)
  1270. if err != nil {
  1271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1272. return
  1273. }
  1274. } else if errs == nil {
  1275. modifyConfig := models.XtHisConfig{
  1276. ID: configs.ID,
  1277. UserOrgId: org_id,
  1278. Status: 1,
  1279. Ctime: time.Now().Unix(),
  1280. Mtime: time.Now().Unix(),
  1281. IsOpen: int64(isOpen),
  1282. }
  1283. err := service.UpdateXTHisRecord(&modifyConfig)
  1284. redis := service.RedisClient()
  1285. defer redis.Close()
  1286. key := strconv.FormatInt(org_id, 10) + ":" + ":his_config"
  1287. redis.Set(key, "", time.Second)
  1288. if err != nil {
  1289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1290. return
  1291. }
  1292. }
  1293. c.ServeSuccessJSON(map[string]interface{}{
  1294. "is_open": is_open,
  1295. })
  1296. return
  1297. }
  1298. func (c *GobalConfigApiController) PostHisStockPriceConfig() {
  1299. is_open, _ := c.GetBool("is_open", false)
  1300. adminUserInfo := c.GetAdminUserInfo()
  1301. org_id := adminUserInfo.CurrentOrgId
  1302. isOpen := 0
  1303. if is_open {
  1304. isOpen = 1
  1305. } else {
  1306. isOpen = 2
  1307. }
  1308. config := models.HisStockPriceConfig{
  1309. UserOrgId: org_id,
  1310. IsOpen: int64(isOpen),
  1311. Status: 1,
  1312. Ctime: time.Now().Unix(),
  1313. Mtime: time.Now().Unix(),
  1314. }
  1315. errs, configs := service.FindHisStockPriceRecordByOrgId(org_id)
  1316. if errs == gorm.ErrRecordNotFound {
  1317. err := service.CreateHisStockPriceRecord(&config)
  1318. if err != nil {
  1319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1320. return
  1321. }
  1322. } else if errs == nil {
  1323. modifyConfig := models.HisStockPriceConfig{
  1324. ID: configs.ID,
  1325. UserOrgId: org_id,
  1326. Status: 1,
  1327. Ctime: time.Now().Unix(),
  1328. Mtime: time.Now().Unix(),
  1329. IsOpen: int64(isOpen),
  1330. }
  1331. err := service.UpdateHisStockPriceRecord(&modifyConfig)
  1332. if err != nil {
  1333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1334. return
  1335. }
  1336. }
  1337. c.ServeSuccessJSON(map[string]interface{}{
  1338. "is_open": is_open,
  1339. })
  1340. return
  1341. }
  1342. func (c *GobalConfigApiController) PostXTHisProjectConfig() {
  1343. is_open, _ := c.GetBool("is_open", false)
  1344. adminUserInfo := c.GetAdminUserInfo()
  1345. org_id := adminUserInfo.CurrentOrgId
  1346. isOpen := 0
  1347. if is_open {
  1348. isOpen = 1
  1349. } else {
  1350. isOpen = 2
  1351. }
  1352. config := models.XtHisProjectConfig{
  1353. UserOrgId: org_id,
  1354. IsOpen: int64(isOpen),
  1355. Status: 1,
  1356. Ctime: time.Now().Unix(),
  1357. Mtime: time.Now().Unix(),
  1358. }
  1359. errs, configs := service.FindXTHisProjectByOrgId(org_id)
  1360. if errs == gorm.ErrRecordNotFound {
  1361. err := service.CreateXTHisProjectRecord(&config)
  1362. redis := service.RedisClient()
  1363. key := strconv.FormatInt(org_id, 10) + ":his_project_config"
  1364. redis.Set(key, "", time.Second)
  1365. defer redis.Close()
  1366. if err != nil {
  1367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1368. return
  1369. }
  1370. } else if errs == nil {
  1371. modifyConfig := models.XtHisProjectConfig{
  1372. ID: configs.ID,
  1373. UserOrgId: org_id,
  1374. Status: 1,
  1375. Ctime: time.Now().Unix(),
  1376. Mtime: time.Now().Unix(),
  1377. IsOpen: int64(isOpen),
  1378. }
  1379. err := service.UpdateXTHisProjectRecord(&modifyConfig)
  1380. if err != nil {
  1381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1382. return
  1383. }
  1384. }
  1385. c.ServeSuccessJSON(map[string]interface{}{
  1386. "is_open": is_open,
  1387. })
  1388. return
  1389. }
  1390. func (c *GobalConfigApiController) GetXTHisConfig() {
  1391. adminUserInfo := c.GetAdminUserInfo()
  1392. _, config := service.FindXTHisRecordByOrgId(adminUserInfo.CurrentOrgId)
  1393. _, project_config := service.FindXTHisProjectByOrgId(adminUserInfo.CurrentOrgId)
  1394. c.ServeSuccessJSON(map[string]interface{}{
  1395. "config": config,
  1396. "project_config": project_config,
  1397. })
  1398. }
  1399. func (c *GobalConfigApiController) GetHisStockPriceConfig() {
  1400. adminUserInfo := c.GetAdminUserInfo()
  1401. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1402. c.ServeSuccessJSON(map[string]interface{}{
  1403. "config": config,
  1404. })
  1405. }
  1406. func (c *GobalConfigApiController) GetAllIsOpenConfig() {
  1407. adminUserInfo := c.GetAdminUserInfo()
  1408. _, config := service.FindXTHisRecordByOrgId(adminUserInfo.CurrentOrgId)
  1409. _, project_config := service.FindXTHisProjectByOrgIdOne(adminUserInfo.CurrentOrgId)
  1410. stockSetting, _ := service.FindStockSettingById(adminUserInfo.CurrentOrgId)
  1411. adviceSetting, _ := service.FindAdviceSettingById(adminUserInfo.CurrentOrgId)
  1412. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminUserInfo.CurrentOrgId)
  1413. drugOutConfig, _ := service.FindDrugOutConfigById(adminUserInfo.CurrentOrgId)
  1414. drugSettleConfig, _ := service.FindeDrugSettleConfigById(adminUserInfo.CurrentOrgId)
  1415. goodOutConfig, _ := service.FindGoodOutConfigById(adminUserInfo.CurrentOrgId)
  1416. c.ServeSuccessJSON(map[string]interface{}{
  1417. "is_open_xt_his": config.IsOpen,
  1418. "is_open_xt_his_project": project_config.IsOpen,
  1419. "is_open_stock": stockSetting.IsType,
  1420. "is_open_advice": adviceSetting.IsAdviceOpen,
  1421. "is_prescription_advice": prescriptionConfig.IsOpen,
  1422. "is_open": drugOutConfig.IsOpen,
  1423. "is_seetle_open": drugSettleConfig.IsOpen,
  1424. "is_out_open": goodOutConfig.IsOpen,
  1425. })
  1426. }
  1427. func (c *GobalConfigApiController) GetPassExportData() {
  1428. }
  1429. func (c *GobalConfigApiController) GetExportData() {
  1430. start_time := c.GetString("start_time")
  1431. end_time := c.GetString("end_time")
  1432. p_type, _ := c.GetInt64("p_type")
  1433. timeLayout := "2006-01-02"
  1434. loc, _ := time.LoadLocation("Local")
  1435. var startTime int64
  1436. if len(start_time) > 0 {
  1437. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1438. if err != nil {
  1439. fmt.Println(err)
  1440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1441. return
  1442. }
  1443. startTime = theTime.Unix()
  1444. }
  1445. var endTime int64
  1446. if len(end_time) > 0 {
  1447. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1448. if err != nil {
  1449. utils.ErrorLog(err.Error())
  1450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1451. return
  1452. }
  1453. endTime = theTime.Unix()
  1454. }
  1455. adminInfo := c.GetAdminUserInfo()
  1456. order, _ := service.GetExportHisOrderList(adminInfo.CurrentOrgId, startTime, endTime, p_type)
  1457. c.ServeSuccessJSON(map[string]interface{}{
  1458. "order": order,
  1459. })
  1460. }
  1461. func (c *GobalConfigApiController) GetDrugInDetail() {
  1462. start_time := c.GetString("start_time")
  1463. end_time := c.GetString("end_time")
  1464. storehouse_id, _ := c.GetInt64("storehouse_id")
  1465. timeLayout := "2006-01-02"
  1466. loc, _ := time.LoadLocation("Local")
  1467. var startTime int64
  1468. if len(start_time) > 0 {
  1469. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1470. if err != nil {
  1471. fmt.Println(err)
  1472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1473. return
  1474. }
  1475. startTime = theTime.Unix()
  1476. }
  1477. var endTime int64
  1478. if len(end_time) > 0 {
  1479. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1480. if err != nil {
  1481. utils.ErrorLog(err.Error())
  1482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1483. return
  1484. }
  1485. endTime = theTime.Unix()
  1486. }
  1487. adminInfo := c.GetAdminUserInfo()
  1488. order_type, _ := c.GetInt64("order_type")
  1489. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1490. keyword := c.GetString("keyword")
  1491. page, _ := c.GetInt64("page")
  1492. limit, _ := c.GetInt64("limit")
  1493. detail, total, err := service.GetDrugInOrderDetail(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit, storehouse_id)
  1494. var drugType = "药品类型"
  1495. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  1496. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminInfo.CurrentOrgId)
  1497. houseList, _ := service.GetAllStorehouseName(adminInfo.CurrentOrgId)
  1498. if err != nil {
  1499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1500. return
  1501. }
  1502. c.ServeSuccessJSON(map[string]interface{}{
  1503. "detail": detail,
  1504. "total": total,
  1505. "drugTypeParent": drugTypeList,
  1506. "houseList": houseList,
  1507. })
  1508. }
  1509. func (c *GobalConfigApiController) GetDrugCancelOrder() {
  1510. start_time := c.GetString("start_time")
  1511. end_time := c.GetString("end_time")
  1512. timeLayout := "2006-01-02"
  1513. loc, _ := time.LoadLocation("Local")
  1514. var startTime int64
  1515. if len(start_time) > 0 {
  1516. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1517. if err != nil {
  1518. fmt.Println(err)
  1519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1520. return
  1521. }
  1522. startTime = theTime.Unix()
  1523. }
  1524. var endTime int64
  1525. if len(end_time) > 0 {
  1526. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1527. if err != nil {
  1528. utils.ErrorLog(err.Error())
  1529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1530. return
  1531. }
  1532. endTime = theTime.Unix()
  1533. }
  1534. adminInfo := c.GetAdminUserInfo()
  1535. order_type, _ := c.GetInt64("order_type")
  1536. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1537. keyword := c.GetString("keyword")
  1538. limit, _ := c.GetInt64("limit")
  1539. page, _ := c.GetInt64("page")
  1540. order, total, err := service.GetDrugReturnOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, limit, page)
  1541. if err != nil {
  1542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1543. return
  1544. }
  1545. c.ServeSuccessJSON(map[string]interface{}{
  1546. "order": order,
  1547. "total": total,
  1548. })
  1549. }
  1550. func (c *GobalConfigApiController) GetDrugOutDetail() {
  1551. start_time := c.GetString("start_time")
  1552. end_time := c.GetString("end_time")
  1553. storehouse_id, _ := c.GetInt64("storehouse_id")
  1554. timeLayout := "2006-01-02"
  1555. loc, _ := time.LoadLocation("Local")
  1556. var startTime int64
  1557. if len(start_time) > 0 {
  1558. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1559. if err != nil {
  1560. fmt.Println(err)
  1561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1562. return
  1563. }
  1564. startTime = theTime.Unix()
  1565. }
  1566. var endTime int64
  1567. if len(end_time) > 0 {
  1568. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1569. if err != nil {
  1570. utils.ErrorLog(err.Error())
  1571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1572. return
  1573. }
  1574. endTime = theTime.Unix()
  1575. }
  1576. adminInfo := c.GetAdminUserInfo()
  1577. order_type, _ := c.GetInt64("order_type")
  1578. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1579. keyword := c.GetString("keyword")
  1580. limit, _ := c.GetInt64("limit")
  1581. page, _ := c.GetInt64("page")
  1582. order, total, err := service.GetDrugOutOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit, storehouse_id)
  1583. houseList, _ := service.GetAllStoreHouseList(adminInfo.CurrentOrgId)
  1584. patientsList, _ := service.GetAllpatient(adminInfo.CurrentOrgId)
  1585. var drugType = "药品类型"
  1586. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  1587. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminInfo.CurrentOrgId)
  1588. if err != nil {
  1589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1590. return
  1591. }
  1592. c.ServeSuccessJSON(map[string]interface{}{
  1593. "order": order,
  1594. "total": total,
  1595. "drugTypeList": drugTypeList,
  1596. "houseList": houseList,
  1597. "patientsList": patientsList,
  1598. })
  1599. }
  1600. func (c *GobalConfigApiController) GetDrugCancelDetail() {
  1601. start_time := c.GetString("start_time")
  1602. end_time := c.GetString("end_time")
  1603. storehouse_id, _ := c.GetInt64("storehouse_id")
  1604. timeLayout := "2006-01-02"
  1605. loc, _ := time.LoadLocation("Local")
  1606. var startTime int64
  1607. if len(start_time) > 0 {
  1608. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1609. if err != nil {
  1610. fmt.Println(err)
  1611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1612. return
  1613. }
  1614. startTime = theTime.Unix()
  1615. }
  1616. var endTime int64
  1617. if len(end_time) > 0 {
  1618. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1619. if err != nil {
  1620. utils.ErrorLog(err.Error())
  1621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1622. return
  1623. }
  1624. endTime = theTime.Unix()
  1625. }
  1626. adminInfo := c.GetAdminUserInfo()
  1627. order_type, _ := c.GetInt64("order_type")
  1628. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1629. keyword := c.GetString("keyword")
  1630. limit, _ := c.GetInt64("limit")
  1631. page, _ := c.GetInt64("page")
  1632. orderPrint, _ := service.GetDrugCancelOrderPrint(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, storehouse_id)
  1633. order, total, err := service.GetDrugCancelOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit, storehouse_id)
  1634. var drugType = "药品类型"
  1635. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  1636. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminInfo.CurrentOrgId)
  1637. houseList, _ := service.GetAllStoreHouseList(adminInfo.CurrentOrgId)
  1638. dealerList, _ := service.GetAllDealerList(adminInfo.CurrentOrgId)
  1639. manufacturerList, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1640. patientsList, _ := service.GetAllpatient(adminInfo.CurrentOrgId)
  1641. if err != nil {
  1642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1643. return
  1644. }
  1645. c.ServeSuccessJSON(map[string]interface{}{
  1646. "order": order,
  1647. "total": total,
  1648. "orderPrint": orderPrint,
  1649. "drugTypeList": drugTypeList,
  1650. "houseList": houseList,
  1651. "dealerList": dealerList,
  1652. "manufacturerList": manufacturerList,
  1653. "patientsList": patientsList,
  1654. })
  1655. }
  1656. func (c *GobalConfigApiController) AddMonitorOpen() {
  1657. is_open, _ := c.GetInt64("is_open")
  1658. fmt.Println("is_open22222222", is_open)
  1659. adminUserInfo := c.GetAdminUserInfo()
  1660. orgId := adminUserInfo.CurrentOrgId
  1661. config := models.XtMonitorConfig{
  1662. IsOpen: is_open,
  1663. UserOrgId: orgId,
  1664. Status: 1,
  1665. Ctime: time.Now().Unix(),
  1666. }
  1667. //查询该机构是否存在
  1668. _, errcode := service.GetMonitorConfigById(orgId)
  1669. if errcode == gorm.ErrRecordNotFound {
  1670. err := service.AddMonitorOpen(&config)
  1671. if err != nil {
  1672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1673. return
  1674. }
  1675. c.ServeSuccessJSON(map[string]interface{}{
  1676. "config": config,
  1677. })
  1678. } else if errcode == nil {
  1679. err := service.UpdateMonitorOpen(orgId, &config)
  1680. fmt.Println("err", err)
  1681. }
  1682. }
  1683. func (c *GobalConfigApiController) GetMonitorConfig() {
  1684. userInfo := c.GetAdminUserInfo()
  1685. orgId := userInfo.CurrentOrgId
  1686. config, err := service.GetMonitorConfig(orgId)
  1687. if err != nil {
  1688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1689. return
  1690. }
  1691. c.ServeSuccessJSON(map[string]interface{}{
  1692. "config": config,
  1693. })
  1694. }
  1695. func (c *GobalConfigApiController) AddOrderConfig() {
  1696. is_open, _ := c.GetInt64("is_open")
  1697. fmt.Println("344555555555555", is_open)
  1698. adminUserInfo := c.GetAdminUserInfo()
  1699. orgId := adminUserInfo.CurrentOrgId
  1700. config := models.XtOrderConfig{
  1701. IsOpen: is_open,
  1702. UserOrgId: orgId,
  1703. Status: 1,
  1704. Ctime: time.Now().Unix(),
  1705. }
  1706. //查询
  1707. _, errcode := service.GetOrderConfigById(orgId)
  1708. if errcode == gorm.ErrRecordNotFound {
  1709. err := service.AddOrderConfig(&config)
  1710. if err != nil {
  1711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1712. return
  1713. }
  1714. c.ServeSuccessJSON(map[string]interface{}{
  1715. "config": config,
  1716. })
  1717. } else if errcode == nil {
  1718. err := service.UpdateOrderConfig(orgId, &config)
  1719. fmt.Println("2222", err)
  1720. }
  1721. }
  1722. func (c *GobalConfigApiController) GetOrderConfig() {
  1723. adminUserInfo := c.GetAdminUserInfo()
  1724. orgId := adminUserInfo.CurrentOrgId
  1725. config, err := service.GetOrderConfig(orgId)
  1726. if err != nil {
  1727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1728. return
  1729. }
  1730. c.ServeSuccessJSON(map[string]interface{}{
  1731. "config": config,
  1732. })
  1733. }
  1734. func (c *GobalConfigApiController) GetDrugAutoMaticList() {
  1735. adminUserInfo := c.GetAdminUserInfo()
  1736. orgId := adminUserInfo.CurrentOrgId
  1737. warehous_out_id, _ := c.GetInt64("warehous_out_id")
  1738. record_time, _ := c.GetInt64("record_time")
  1739. warehouse_out_order_number := c.GetString("warehouse_out_order_number")
  1740. drugConfig, _ := service.GetDrugStockConfig(orgId)
  1741. list, err := service.GetDrugAutoMaticList(orgId, warehous_out_id, record_time, warehouse_out_order_number)
  1742. drugList, err := service.GetAllBaseDrugList(orgId)
  1743. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1744. if err != nil {
  1745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1746. return
  1747. }
  1748. c.ServeSuccessJSON(map[string]interface{}{
  1749. "list": list,
  1750. "drugConfig": drugConfig,
  1751. "drugList": drugList,
  1752. "manufacturerList": manufacturerList,
  1753. })
  1754. }
  1755. func (c *GobalConfigApiController) GetDrugWarehuseOrderInfo() {
  1756. adminUserInfo := c.GetAdminUserInfo()
  1757. orgId := adminUserInfo.CurrentOrgId
  1758. list, _ := service.GetDrugWarehuseOrderInfo(orgId)
  1759. c.ServeSuccessJSON(map[string]interface{}{
  1760. "list": list,
  1761. })
  1762. }
  1763. func (c *GobalConfigApiController) GetDrugStockList() {
  1764. page, _ := c.GetInt64("page", -1)
  1765. limit, _ := c.GetInt64("limit", -1)
  1766. keyword := c.GetString("keyword")
  1767. drug_type, _ := c.GetInt64("drug_type")
  1768. start_time := c.GetString("start_time")
  1769. end_time := c.GetString("end_time")
  1770. timeLayout := "2006-01-02"
  1771. loc, _ := time.LoadLocation("Local")
  1772. storehouse_id, _ := c.GetInt64("storehouse_id")
  1773. drug_id, _ := c.GetInt64("drug_id")
  1774. var startTime int64
  1775. if len(start_time) > 0 {
  1776. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1777. if err != nil {
  1778. fmt.Println(err)
  1779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1780. return
  1781. }
  1782. startTime = theTime.Unix()
  1783. }
  1784. var endTime int64
  1785. if len(end_time) > 0 {
  1786. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1787. if err != nil {
  1788. utils.ErrorLog(err.Error())
  1789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1790. return
  1791. }
  1792. endTime = theTime.Unix()
  1793. }
  1794. adminUserInfo := c.GetAdminUserInfo()
  1795. list, total, err := service.GetAllBaseDurgListCount(page, limit, keyword, drug_type, startTime, endTime, adminUserInfo.CurrentOrgId, storehouse_id, drug_id)
  1796. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  1797. houseList, _ := service.GetAllStoreHouseListOne(adminUserInfo.CurrentOrgId)
  1798. medicalList, _ := service.GetAllBaseDrugStockList(adminUserInfo.CurrentOrgId)
  1799. if err != nil {
  1800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1801. return
  1802. }
  1803. c.ServeSuccessJSON(map[string]interface{}{
  1804. "list": list,
  1805. "total": total,
  1806. "manufacturerList": manufacturerList,
  1807. "houseList": houseList,
  1808. "medicalList": medicalList,
  1809. })
  1810. }
  1811. func (c *GobalConfigApiController) GetDrugStockFllow() {
  1812. drug_id, _ := c.GetInt64("drug_id")
  1813. start_time := c.GetString("start_time")
  1814. end_time := c.GetString("end_time")
  1815. stock_type, _ := c.GetInt64("stock_type")
  1816. page, _ := c.GetInt64("page")
  1817. limit, _ := c.GetInt64("limit")
  1818. timeLayout := "2006-01-02"
  1819. loc, _ := time.LoadLocation("Local")
  1820. var startTime int64
  1821. if len(start_time) > 0 {
  1822. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1823. if err != nil {
  1824. fmt.Println(err)
  1825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1826. return
  1827. }
  1828. startTime = theTime.Unix()
  1829. }
  1830. var endTime int64
  1831. if len(end_time) > 0 {
  1832. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1833. if err != nil {
  1834. utils.ErrorLog(err.Error())
  1835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1836. return
  1837. }
  1838. endTime = theTime.Unix()
  1839. }
  1840. orgId := c.GetAdminUserInfo().CurrentOrgId
  1841. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1842. medical, _ := service.GetBaseDrugMedical(drug_id)
  1843. //查询入库数据
  1844. if stock_type == 3 || stock_type == 0 {
  1845. list, total, err := service.GetDrugStockFlow(drug_id, startTime, endTime, page, limit, orgId)
  1846. if err != nil {
  1847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1848. return
  1849. }
  1850. c.ServeSuccessJSON(map[string]interface{}{
  1851. "list": list,
  1852. "total": total,
  1853. "manufacturerList": manufacturerList,
  1854. "drug": medical,
  1855. })
  1856. }
  1857. }
  1858. func (c *GobalConfigApiController) GetDrugOutStockFlow() {
  1859. drug_id, _ := c.GetInt64("drug_id")
  1860. start_time := c.GetString("start_time")
  1861. end_time := c.GetString("end_time")
  1862. stock_type, _ := c.GetInt64("stock_type")
  1863. page, _ := c.GetInt64("page")
  1864. limit, _ := c.GetInt64("limit")
  1865. timeLayout := "2006-01-02"
  1866. loc, _ := time.LoadLocation("Local")
  1867. var startTime int64
  1868. if len(start_time) > 0 {
  1869. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1870. if err != nil {
  1871. fmt.Println(err)
  1872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1873. return
  1874. }
  1875. startTime = theTime.Unix()
  1876. }
  1877. var endTime int64
  1878. if len(end_time) > 0 {
  1879. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1880. if err != nil {
  1881. utils.ErrorLog(err.Error())
  1882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1883. return
  1884. }
  1885. endTime = theTime.Unix()
  1886. }
  1887. orgId := c.GetAdminUserInfo().CurrentOrgId
  1888. outList, total, err := service.GetDrugStockOutFlow(drug_id, startTime, endTime, page, limit, orgId, stock_type)
  1889. if err != nil {
  1890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1891. return
  1892. }
  1893. c.ServeSuccessJSON(map[string]interface{}{
  1894. "outList": outList,
  1895. "total": total,
  1896. })
  1897. }
  1898. func (c *GobalConfigApiController) GetBatchOrderDetail() {
  1899. drug_id, _ := c.GetInt64("drug_id")
  1900. orgId := c.GetAdminUserInfo().CurrentOrgId
  1901. limit, _ := c.GetInt64("limit")
  1902. page, _ := c.GetInt64("page")
  1903. start_time := c.GetString("start_time")
  1904. end_time := c.GetString("end_time")
  1905. start_first_time := c.GetString("start_first_time")
  1906. end_first_time := c.GetString("end_first_time")
  1907. timeLayout := "2006-01-02"
  1908. loc, _ := time.LoadLocation("Local")
  1909. var startTime int64
  1910. if len(start_time) > 0 {
  1911. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1912. if err != nil {
  1913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1914. return
  1915. }
  1916. startTime = theTime.Unix()
  1917. }
  1918. var endTime int64
  1919. if len(end_time) > 0 {
  1920. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1921. if err != nil {
  1922. utils.ErrorLog(err.Error())
  1923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1924. return
  1925. }
  1926. endTime = theTime.Unix()
  1927. }
  1928. var startFistTime int64
  1929. if len(start_first_time) > 0 {
  1930. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_first_time+" 00:00:00", loc)
  1931. if err != nil {
  1932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1933. return
  1934. }
  1935. startFistTime = theTime.Unix()
  1936. }
  1937. var endFirstTime int64
  1938. if len(end_first_time) > 0 {
  1939. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_first_time+" 23:59:59", loc)
  1940. if err != nil {
  1941. utils.ErrorLog(err.Error())
  1942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1943. return
  1944. }
  1945. endFirstTime = theTime.Unix()
  1946. }
  1947. detail, total, err := service.GetBatchOrderDetail(drug_id, orgId, page, limit, startTime, endTime, startFistTime, endFirstTime)
  1948. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1949. drug, _ := service.GetBaseDrugMedical(drug_id)
  1950. houseList, _ := service.GetAllStoreHouseList(orgId)
  1951. if err != nil {
  1952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1953. return
  1954. }
  1955. c.ServeSuccessJSON(map[string]interface{}{
  1956. "detail": detail,
  1957. "total": total,
  1958. "manufacturerList": manufacturerList,
  1959. "drug": drug,
  1960. "houseList": houseList,
  1961. })
  1962. }
  1963. func (c *GobalConfigApiController) GetDrugCountList() {
  1964. start_time := c.GetString("start_time")
  1965. end_time := c.GetString("end_time")
  1966. timeLayout := "2006-01-02"
  1967. loc, _ := time.LoadLocation("Local")
  1968. var startTime int64
  1969. if len(start_time) > 0 {
  1970. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1971. if err != nil {
  1972. fmt.Println(err)
  1973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1974. return
  1975. }
  1976. startTime = theTime.Unix()
  1977. }
  1978. var endTime int64
  1979. if len(end_time) > 0 {
  1980. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1981. if err != nil {
  1982. utils.ErrorLog(err.Error())
  1983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1984. return
  1985. }
  1986. endTime = theTime.Unix()
  1987. }
  1988. orgId := c.GetAdminUserInfo().CurrentOrgId
  1989. countList, err := service.GetMinCountList(startTime, endTime, orgId)
  1990. outCountList, _ := service.GetOutDrugCountList(startTime, endTime, orgId)
  1991. auCountList, err := service.GetAutoDrugCountList(startTime, endTime, orgId)
  1992. info, _ := service.GetDrugWarehouOrderInfo(startTime, endTime, orgId)
  1993. cancelCountList, _ := service.GetCancelDrugCountList(startTime, endTime, orgId)
  1994. if err != nil {
  1995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1996. return
  1997. }
  1998. c.ServeSuccessJSON(map[string]interface{}{
  1999. "outCountList": outCountList,
  2000. "auCountList": auCountList,
  2001. "minCount": countList,
  2002. "info": info,
  2003. "cancelCountList": cancelCountList,
  2004. })
  2005. }
  2006. func (c *GobalConfigApiController) GetSingleOrderDetail() {
  2007. id, _ := c.GetInt64("id")
  2008. start_time, _ := c.GetInt64("start_time")
  2009. orgId := c.GetAdminUserInfo().CurrentOrgId
  2010. list, err := service.GetSingleOrderDetail(id, orgId)
  2011. drugoutlist, _ := service.GetDrugWarehouseOutDetailNighty(id, orgId)
  2012. dealerList, err := service.GetAllDealerList(orgId)
  2013. manufacturerList, err := service.GetAllManufacturerList(orgId)
  2014. drugFlowList, _ := service.GetDrugStockFlowDetail(start_time, orgId)
  2015. flowlist, _ := service.GetSingeOrderFlow(id, orgId)
  2016. drugList, _ := service.GetDrugFlowList(id, orgId)
  2017. drugListOne, _ := service.GetDrugFlowListGroupByIdOne(id, orgId)
  2018. drugListFlow, err := service.GetDrugFlowListGroupById(id, orgId)
  2019. if err != nil {
  2020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2021. return
  2022. }
  2023. c.ServeSuccessJSON(map[string]interface{}{
  2024. "list": list,
  2025. "dealerList": dealerList,
  2026. "manufacturerList": manufacturerList,
  2027. "drugFlowList": drugFlowList,
  2028. "flowlist": flowlist,
  2029. "drugList": drugList,
  2030. "drugListFlow": drugListFlow,
  2031. "drugListOne": drugListOne,
  2032. "drugoutlist": drugoutlist,
  2033. })
  2034. }
  2035. func (c *GobalConfigApiController) GetAutoDrugDetail() {
  2036. warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
  2037. id, _ := c.GetInt64("drug_id")
  2038. record_time, _ := c.GetInt64("record_time")
  2039. orgId := c.GetAdminUserInfo().CurrentOrgId
  2040. //获取自动出库
  2041. list, err, total := service.FindDrugStockUserDetailByIdThree(id, record_time, orgId)
  2042. //获取手动出库
  2043. outList, err := service.FindeDrugWarehouserInfo(warehouse_out_id, id, orgId)
  2044. batchNumber, err := service.GetDrugFlowBatch(warehouse_out_id, id, orgId)
  2045. if err != nil {
  2046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2047. return
  2048. }
  2049. c.ServeSuccessJSON(map[string]interface{}{
  2050. "list": list,
  2051. "total": total,
  2052. "outList": outList,
  2053. "batchNumber": batchNumber,
  2054. })
  2055. }
  2056. func (c *GobalConfigApiController) GetDrugOrderInPrint() {
  2057. id := c.GetString("id")
  2058. ids := strings.Split(id, ",")
  2059. admin := c.GetAdminUserInfo()
  2060. info, _ := service.FindDrugWarehousingByIdOne(ids, admin.CurrentOrgId)
  2061. manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  2062. warehousingInfo, _ := service.FindDrugWarehousingInfoByIdOne(ids, admin.CurrentOrgId)
  2063. c.ServeSuccessJSON(map[string]interface{}{
  2064. "info": info,
  2065. "warehousing": warehousingInfo,
  2066. "manufacturerList": manufacturerList,
  2067. })
  2068. }
  2069. func (c *GobalConfigApiController) GetDrugOutOrderPrint() {
  2070. id := c.GetString("id")
  2071. ids := strings.Split(id, ",")
  2072. admin := c.GetAdminUserInfo()
  2073. info, _ := service.FindeDrugWarehouseOutOrder(ids, admin.CurrentOrgId)
  2074. manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  2075. warehousing, _ := service.GetExportOutOrderDrugListOne(ids)
  2076. drug_warhouse_out, _ := service.GetDrugWarehouseOutTenty(ids, admin.CurrentOrgId)
  2077. c.ServeSuccessJSON(map[string]interface{}{
  2078. "info": info,
  2079. "warehousing": warehousing,
  2080. "manufacturerList": manufacturerList,
  2081. "drug_warhouse_out": drug_warhouse_out,
  2082. })
  2083. }
  2084. func (c *GobalConfigApiController) GetDrugBatchNumber() {
  2085. id, _ := c.GetInt64("id")
  2086. orgId := c.GetAdminUserInfo().CurrentOrgId
  2087. list, _ := service.GetDrugBatchNumber(id, orgId)
  2088. c.ServeSuccessJSON(map[string]interface{}{
  2089. "list": list,
  2090. })
  2091. }
  2092. func (c *GobalConfigApiController) ExportDrugList() {
  2093. orderId := c.GetString("order_id")
  2094. ids := strings.Split(orderId, ",")
  2095. list, _ := service.ExportDrugList(ids)
  2096. orgId := c.GetAdminUserInfo().CurrentOrgId
  2097. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2098. dealerList, _ := service.GetAllDealerList(orgId)
  2099. c.ServeSuccessJSON(map[string]interface{}{
  2100. "list": list,
  2101. "manufacturerList": manufacturerList,
  2102. "dealerList": dealerList,
  2103. })
  2104. }
  2105. func (c *GobalConfigApiController) GetExportOutOrderDrugList() {
  2106. orderId := c.GetString("order_id")
  2107. ids := strings.Split(orderId, ",")
  2108. orgId := c.GetAdminUserInfo().CurrentOrgId
  2109. list, _ := service.GetExportOutOrderDrugListOne(ids)
  2110. outInfoList, _ := service.GetDrugOutListFlow(ids, orgId)
  2111. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2112. dealerList, _ := service.GetAllDealerList(orgId)
  2113. c.ServeSuccessJSON(map[string]interface{}{
  2114. "list": list,
  2115. "manufacturerList": manufacturerList,
  2116. "dealerList": dealerList,
  2117. "outInfoList": outInfoList,
  2118. })
  2119. }
  2120. func (c *GobalConfigApiController) GetDrugFlow() {
  2121. start_time := c.GetString("start_time")
  2122. end_time := c.GetString("end_time")
  2123. timeLayout := "2006-01-02"
  2124. loc, _ := time.LoadLocation("Local")
  2125. var startTime int64
  2126. if len(start_time) > 0 {
  2127. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2128. if err != nil {
  2129. fmt.Println(err)
  2130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2131. return
  2132. }
  2133. startTime = theTime.Unix()
  2134. }
  2135. var endTime int64
  2136. if len(end_time) > 0 {
  2137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2138. if err != nil {
  2139. utils.ErrorLog(err.Error())
  2140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2141. return
  2142. }
  2143. endTime = theTime.Unix()
  2144. }
  2145. orgId := c.GetAdminUserInfo().CurrentOrgId
  2146. drug_id, _ := c.GetInt64("drug_id")
  2147. page, _ := c.GetInt64("page")
  2148. limit, _ := c.GetInt64("limit")
  2149. stock_type, _ := c.GetInt64("stock_type")
  2150. list, total, _ := service.GetDrugFlow(drug_id, orgId, limit, page, startTime, endTime, stock_type)
  2151. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2152. dealerList, _ := service.GetAllDealerList(orgId)
  2153. medical, _ := service.GetBaseDrugMedical(drug_id)
  2154. houseList, _ := service.GetAllStoreHouseList(orgId)
  2155. patientList, _ := service.GetAllPatientListSix(orgId)
  2156. c.ServeSuccessJSON(map[string]interface{}{
  2157. "list": list,
  2158. "total": total,
  2159. "manufacturerList": manufacturerList,
  2160. "dealerList": dealerList,
  2161. "drug": medical,
  2162. "houseList": houseList,
  2163. "patientList": patientList,
  2164. })
  2165. }
  2166. func (c *GobalConfigApiController) GetCancelStockDetail() {
  2167. id, _ := c.GetInt64("id")
  2168. list, _ := service.GetCancelStockDetail(id)
  2169. c.ServeSuccessJSON(map[string]interface{}{
  2170. "list": list,
  2171. })
  2172. }
  2173. func (c *GobalConfigApiController) ChangeStockSetting() {
  2174. is_type, _ := c.GetInt64("is_type")
  2175. orgId := c.GetAdminUserInfo().CurrentOrgId
  2176. setting := models.XtStockSetting{
  2177. IsType: is_type,
  2178. UserOrgId: orgId,
  2179. Status: 1,
  2180. Ctime: time.Now().Unix(),
  2181. Mtime: 0,
  2182. }
  2183. //查询机该机构是否已经配置
  2184. _, errcode := service.GetStockSettingIsExsit(orgId)
  2185. if errcode == gorm.ErrRecordNotFound {
  2186. service.CreateStockSetting(setting)
  2187. c.ServeSuccessJSON(map[string]interface{}{
  2188. "msg": 1,
  2189. })
  2190. } else if errcode == nil {
  2191. service.UpdateStockSetting(orgId, setting)
  2192. c.ServeSuccessJSON(map[string]interface{}{
  2193. "msg": 1,
  2194. })
  2195. }
  2196. }
  2197. func (c *GobalConfigApiController) ChangeAdviceConfig() {
  2198. is_advice_open, _ := c.GetInt64("is_advice_open")
  2199. orgId := c.GetAdminUserInfo().CurrentOrgId
  2200. setting := models.XtAdviceSetting{
  2201. IsAdviceOpen: is_advice_open,
  2202. UserOrgId: orgId,
  2203. Status: 1,
  2204. Ctime: time.Now().Unix(),
  2205. Mtime: 0,
  2206. }
  2207. //查询是否存在
  2208. _, errcode := service.GetAdviceConfig(orgId)
  2209. if errcode == gorm.ErrRecordNotFound {
  2210. service.CreateAdviceSetting(setting)
  2211. c.ServeSuccessJSON(map[string]interface{}{
  2212. "msg": 1,
  2213. })
  2214. } else if errcode == nil {
  2215. service.UpdateAdviceSetting(orgId, setting)
  2216. c.ServeSuccessJSON(map[string]interface{}{
  2217. "msg": 1,
  2218. })
  2219. }
  2220. }
  2221. func (c *GobalConfigApiController) ChangePrescriptionConfig() {
  2222. is_open_prescription_xt_his, _ := c.GetInt64("is_open_prescription_xt_his")
  2223. orgId := c.GetAdminUserInfo().CurrentOrgId
  2224. _, errcode := service.GetPrescriptionConfig(orgId)
  2225. if errcode == gorm.ErrRecordNotFound {
  2226. config := models.XtPrescriptionConfig{
  2227. UserOrgId: orgId,
  2228. IsOpen: is_open_prescription_xt_his,
  2229. Status: 1,
  2230. Ctime: time.Now().Unix(),
  2231. }
  2232. service.CreatePrescriptionConfig(config)
  2233. c.ServeSuccessJSON(map[string]interface{}{
  2234. "msg": 1,
  2235. })
  2236. } else if errcode == nil {
  2237. config := models.XtPrescriptionConfig{
  2238. UserOrgId: orgId,
  2239. IsOpen: is_open_prescription_xt_his,
  2240. Status: 1,
  2241. Ctime: time.Now().Unix(),
  2242. }
  2243. service.UpdatePrescriptionConfig(orgId, config)
  2244. c.ServeSuccessJSON(map[string]interface{}{
  2245. "msg": 1,
  2246. })
  2247. }
  2248. }
  2249. func (c *GobalConfigApiController) ChangeDrugOpenConfig() {
  2250. drug_out_open, _ := c.GetInt64("drug_out_open")
  2251. orgId := c.GetAdminUserInfo().CurrentOrgId
  2252. if drug_out_open == 1 {
  2253. service.UpdateDrugStockAutomaticReduceRecordOne(orgId, 2)
  2254. service.UpdatePharyConfig(orgId, 2)
  2255. service.UpdateSettleOpenConfigOne(orgId, 2)
  2256. }
  2257. _, errcode := service.GetDrugOpenConfig(orgId)
  2258. if errcode == gorm.ErrRecordNotFound {
  2259. config := models.DrugOutConfig{
  2260. UserOrgId: orgId,
  2261. IsOpen: drug_out_open,
  2262. Status: 1,
  2263. Ctime: time.Now().Unix(),
  2264. }
  2265. service.CreateDrugOutConfig(config)
  2266. c.ServeSuccessJSON(map[string]interface{}{
  2267. "msg": 1,
  2268. })
  2269. } else if errcode == nil {
  2270. service.UpdateDrugOutConfig(orgId, drug_out_open)
  2271. c.ServeSuccessJSON(map[string]interface{}{
  2272. "msg": 1,
  2273. })
  2274. }
  2275. }
  2276. func (this *GobalConfigApiController) ChangeSettleOpenConfig() {
  2277. drug_out_open, _ := this.GetInt64("drug_settle_open")
  2278. orgId := this.GetAdminUserInfo().CurrentOrgId
  2279. config := models.HisSettleStockConfig{
  2280. UserOrgId: orgId,
  2281. Ctime: time.Now().Unix(),
  2282. Mtime: 0,
  2283. Status: 1,
  2284. IsOpen: drug_out_open,
  2285. }
  2286. if drug_out_open == 1 {
  2287. service.UpdateDrugOutConfig(orgId, 2)
  2288. service.UpdateDrugStockAutomaticReduceRecordOne(orgId, 2)
  2289. service.UpdatePharyConfig(orgId, 2)
  2290. service.UpdateGoodAutoConfig(orgId)
  2291. service.UpdateGoodOutConfig(orgId)
  2292. }
  2293. openConfig, errcode := service.GetSettleOpenConfig(orgId)
  2294. if errcode == gorm.ErrRecordNotFound {
  2295. service.CreateSettleOpenConfig(config)
  2296. } else if errcode == nil {
  2297. service.UpdateSettleOpenConfig(openConfig.ID, config)
  2298. }
  2299. this.ServeSuccessJSON(map[string]interface{}{
  2300. "msg": 1,
  2301. })
  2302. }
  2303. func (this *GobalConfigApiController) ChangeGoodOutOpen() {
  2304. good_open, _ := this.GetInt64("good_open")
  2305. orgId := this.GetAdminUserInfo().CurrentOrgId
  2306. config, errcode := service.GetGoodOutOpenConfig(orgId)
  2307. outConfig := models.XtGoodOutConfig{
  2308. UserOrgId: orgId,
  2309. IsOpen: good_open,
  2310. Status: 1,
  2311. Ctime: time.Now().Unix(),
  2312. Mtime: time.Now().Unix(),
  2313. }
  2314. if good_open == 1 {
  2315. service.UpdateGoodAutoConfig(orgId)
  2316. service.UpdateSettleOpenConfigTwo(orgId, 2)
  2317. }
  2318. if errcode == gorm.ErrRecordNotFound {
  2319. service.CreateGoodOutOpenConfig(outConfig)
  2320. } else if errcode == nil {
  2321. service.UpdateGoodOutOpenConfig(config.ID, outConfig)
  2322. }
  2323. this.ServeSuccessJSON(map[string]interface{}{
  2324. "msg": 1,
  2325. })
  2326. }