gobal_config_api_controller.go 83KB

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