gobal_config_api_controller.go 74KB

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