gobal_config_api_controller.go 68KB

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