Illness.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. package controllers
  2. import (
  3. "FollowUp_Notice/conf"
  4. "FollowUp_Notice/http/submail"
  5. "FollowUp_Notice/lib"
  6. "FollowUp_Notice/models/Account"
  7. "FollowUp_Notice/models/Illness"
  8. "FollowUp_Notice/models/Patient"
  9. "FollowUp_Notice/models/System"
  10. beego "github.com/beego/beego/v2/server/web"
  11. "github.com/robfig/cron/v3"
  12. "math"
  13. "strconv"
  14. "strings"
  15. )
  16. type IllnessController struct {
  17. beego.Controller
  18. User Account.User
  19. }
  20. func (c *IllnessController) Prepare() {
  21. c.User = *Account.User_r
  22. }
  23. // 疾病
  24. func (c *IllnessController) Illness_List() {
  25. // 分页参数 初始化
  26. page, _ := c.GetInt("page")
  27. if page < 1 {
  28. page = 1
  29. }
  30. page_z, _ := c.GetInt("page_z")
  31. if page_z < 1 {
  32. page_z = conf.Page_size
  33. }
  34. // 查询
  35. T_name := c.GetString("T_name")
  36. R_List, R_cnt := Illness.Read_Illness_List(c.User.Id, T_name, page, page_z)
  37. var r_jsons lib.R_JSONS
  38. r_jsons.Num = R_cnt
  39. r_jsons.Data = R_List
  40. r_jsons.Page = page
  41. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  42. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  43. c.ServeJSON()
  44. return
  45. }
  46. func (c *IllnessController) Illness_Add() {
  47. T_name := c.GetString("T_name")
  48. T_sort, _ := c.GetInt("T_sort")
  49. var_ := Illness.Illness{
  50. T_name: T_name,
  51. T_sort: T_sort,
  52. T_State: 1,
  53. T_uid: c.User.Id,
  54. }
  55. Id, err := Illness.Add_Illness(var_)
  56. if err != nil {
  57. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败"}
  58. c.ServeJSON()
  59. return
  60. }
  61. System.Add_UserLogs_T(c.User.T_uuid, "疾病", "添加", var_)
  62. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  63. c.ServeJSON()
  64. return
  65. }
  66. func (c *IllnessController) Illness_Edit() {
  67. T_id, _ := c.GetInt("T_id")
  68. T_name := c.GetString("T_name")
  69. T_sort, _ := c.GetInt("T_sort")
  70. Illness_r, err := Illness.Read_Illness_ById(T_id)
  71. if err != nil {
  72. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
  73. c.ServeJSON()
  74. return
  75. }
  76. if len(T_name) > 0 {
  77. Illness_r.T_name = T_name
  78. }
  79. Illness_r.T_sort = T_sort
  80. if err = Illness.Update_Illness(Illness_r, "T_name", "T_sort"); err != nil {
  81. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败"}
  82. c.ServeJSON()
  83. return
  84. }
  85. System.Add_UserLogs_T(c.User.T_uuid, "疾病", "修改", Illness_r)
  86. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  87. c.ServeJSON()
  88. return
  89. }
  90. func (c *IllnessController) Illness_Del() {
  91. T_id, _ := c.GetInt("T_id")
  92. Illness_r, err := Illness.Read_Illness_ById(T_id)
  93. if err != nil {
  94. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
  95. c.ServeJSON()
  96. return
  97. }
  98. if err = Illness.Delete_Illness(Illness_r); err != nil {
  99. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  100. c.ServeJSON()
  101. return
  102. }
  103. System.Add_UserLogs(c.User.T_uuid, "疾病", "删除", strconv.Itoa(T_id))
  104. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  105. c.ServeJSON()
  106. return
  107. }
  108. // 疾病
  109. func (c *IllnessController) IllnessNotice_List() {
  110. // 分页参数 初始化
  111. page, _ := c.GetInt("page")
  112. if page < 1 {
  113. page = 1
  114. }
  115. page_z, _ := c.GetInt("page_z")
  116. if page_z < 1 {
  117. page_z = conf.Page_size
  118. }
  119. T_Illness_id, _ := c.GetInt("T_Illness_id")
  120. // 查询
  121. T_name := c.GetString("T_name")
  122. T_template_status := c.GetString("T_template_status")
  123. R_List, R_cnt := Illness.Read_IllnessNotice_List(T_Illness_id, T_name, T_template_status, page, page_z)
  124. var r_jsons lib.R_JSONS
  125. r_jsons.Num = R_cnt
  126. r_jsons.Data = R_List
  127. r_jsons.Page = page
  128. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  129. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  130. c.ServeJSON()
  131. return
  132. }
  133. func (c *IllnessController) IllnessNotice_Add() {
  134. T_Illness_id, _ := c.GetInt("T_Illness_id") // 疾病id
  135. T_name := c.GetString("T_name") // 名称
  136. T_content := c.GetString("T_content") // 内容
  137. // 向赛邮添加短信模板
  138. template_content := strings.Replace(T_content, "{患者名称}", "@var(name)", -1)
  139. template_content = strings.Replace(template_content, "{复诊时间}", "@var(time)", -1)
  140. temp, err := submail.SmsTemplate_Post(c.User.T_user, template_content)
  141. if err != nil || temp.Status != "success" {
  142. c.Data["json"] = lib.JSONS{Code: 202, Msg: "创建短信模板失败"}
  143. c.ServeJSON()
  144. return
  145. }
  146. var_ := Illness.IllnessNotice{
  147. T_Illness_id: T_Illness_id,
  148. T_name: T_name,
  149. T_content: T_content,
  150. T_State: 1,
  151. T_template_id: temp.Template_id,
  152. T_template_status: "1",
  153. }
  154. Id, err := Illness.Add_IllnessNotice(var_)
  155. if err != nil {
  156. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败"}
  157. c.ServeJSON()
  158. return
  159. }
  160. System.Add_UserLogs_T(c.User.T_uuid, "疾病通知内容", "添加", var_)
  161. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  162. c.ServeJSON()
  163. return
  164. }
  165. func (c *IllnessController) IllnessNotice_Edit() {
  166. T_id, _ := c.GetInt("T_id")
  167. T_name := c.GetString("T_name") // 名称
  168. T_content := c.GetString("T_content") // 内容
  169. IllnessNotice_r, err := Illness.Read_IllnessNotice_ById(T_id)
  170. if err != nil {
  171. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
  172. c.ServeJSON()
  173. return
  174. }
  175. if IllnessNotice_r.T_content != T_content {
  176. // 向赛邮添加短信模板
  177. template_content := strings.Replace(T_content, "{患者名称}", "@var(name)", -1)
  178. template_content = strings.Replace(template_content, "{复诊时间}", "@var(time)", -1)
  179. temp, err := submail.SmsTemplate_Put(IllnessNotice_r.T_template_id, c.User.T_user, template_content)
  180. if err != nil || temp.Status != "success" {
  181. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改短信模板失败"}
  182. c.ServeJSON()
  183. return
  184. }
  185. IllnessNotice_r.T_content = T_content
  186. IllnessNotice_r.T_template_status = "1"
  187. IllnessNotice_r.T_template_status_description = ""
  188. IllnessNotice_r.T_template_reject_reson = ""
  189. }
  190. if len(T_name) > 0 {
  191. IllnessNotice_r.T_name = T_name
  192. }
  193. if err = Illness.Update_IllnessNotice(IllnessNotice_r, "T_name", "T_content", "T_template_status", "T_template_status_description", "T_template_reject_reson"); err != nil {
  194. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败"}
  195. c.ServeJSON()
  196. return
  197. }
  198. System.Add_UserLogs_T(c.User.T_uuid, "疾病通知内容", "修改", IllnessNotice_r)
  199. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  200. c.ServeJSON()
  201. return
  202. }
  203. func (c *IllnessController) IllnessNotice_Del() {
  204. T_id, _ := c.GetInt("T_id")
  205. IllnessNotice_r, err := Illness.Read_IllnessNotice_ById(T_id)
  206. if err != nil {
  207. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
  208. c.ServeJSON()
  209. return
  210. }
  211. count, err := Patient.Read_PatientRevisitRecord_Count_ByT_illness_notice(IllnessNotice_r.T_Illness_id)
  212. if err != nil {
  213. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
  214. c.ServeJSON()
  215. return
  216. }
  217. if count > 0 {
  218. c.Data["json"] = lib.JSONS{Code: 202, Msg: "此内容已关联患者通知信息,禁止删除!"}
  219. c.ServeJSON()
  220. return
  221. }
  222. // 向赛邮删除短信模板
  223. temp, err := submail.SmsTemplate_Delete(IllnessNotice_r.T_template_id)
  224. if err != nil || temp.Status != "success" {
  225. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除短信模板失败"}
  226. c.ServeJSON()
  227. return
  228. }
  229. if err = Illness.Delete_IllnessNotice(IllnessNotice_r); err != nil {
  230. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  231. c.ServeJSON()
  232. return
  233. }
  234. System.Add_UserLogs(c.User.T_uuid, "疾病通知内容", "删除", strconv.Itoa(T_id))
  235. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  236. c.ServeJSON()
  237. return
  238. }
  239. func Cron_Illness() {
  240. //创建一个定时任务对象
  241. c := cron.New(cron.WithSeconds())
  242. //给对象增加定时任务
  243. c.AddFunc("0 */1 * * * ?", Cron_Illness_IllnessNotice)
  244. //启动定时任务
  245. c.Start()
  246. defer c.Stop()
  247. //查询语句,阻塞,让main函数不退出,保持程序运行
  248. select {}
  249. }
  250. // 同步赛邮云的模板审核状态
  251. func Cron_Illness_IllnessNotice() {
  252. list, _ := Illness.Read_IllnessNotice_List(0, "", "1", 0, 9999)
  253. for _, v := range list {
  254. // 查询赛邮审核状态
  255. temp, err := submail.SmsTemplate_Get(v.T_template_id)
  256. if err != nil || temp.Status != "success" {
  257. continue
  258. }
  259. if temp.Template.Template_status != "1" {
  260. var_ := Illness.IllnessNotice{
  261. Id: v.Id,
  262. T_template_status: temp.Template.Template_status,
  263. T_template_status_description: temp.Template.Template_status_description,
  264. T_template_reject_reson: temp.Template.Template_reject_reson,
  265. }
  266. Illness.Update_IllnessNotice(var_, "T_template_status", "T_template_status_description", "T_template_reject_reson")
  267. }
  268. }
  269. }