gobal_config_api_controller.go 83KB

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