gobal_config_api_controller.go 83KB

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