123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- package controllers
- import (
- "FollowUp_Notice/conf"
- "FollowUp_Notice/http/submail"
- "FollowUp_Notice/lib"
- "FollowUp_Notice/models/Account"
- "FollowUp_Notice/models/Illness"
- "FollowUp_Notice/models/Patient"
- "FollowUp_Notice/models/System"
- beego "github.com/beego/beego/v2/server/web"
- "github.com/robfig/cron/v3"
- "math"
- "strconv"
- "strings"
- )
- type IllnessController struct {
- beego.Controller
- User Account.User
- }
- func (c *IllnessController) Prepare() {
- c.User = *Account.User_r
- }
- // 疾病
- func (c *IllnessController) Illness_List() {
- // 分页参数 初始化
- page, _ := c.GetInt("page")
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- // 查询
- T_name := c.GetString("T_name")
- R_List, R_cnt := Illness.Read_Illness_List(c.User.Id, T_name, page, page_z)
- var r_jsons lib.R_JSONS
- r_jsons.Num = R_cnt
- r_jsons.Data = R_List
- r_jsons.Page = page
- r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *IllnessController) Illness_Add() {
- T_name := c.GetString("T_name")
- T_sort, _ := c.GetInt("T_sort")
- var_ := Illness.Illness{
- T_name: T_name,
- T_sort: T_sort,
- T_State: 1,
- T_uid: c.User.Id,
- }
- Id, err := Illness.Add_Illness(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(c.User.T_uuid, "疾病", "添加", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
- c.ServeJSON()
- return
- }
- func (c *IllnessController) Illness_Edit() {
- T_id, _ := c.GetInt("T_id")
- T_name := c.GetString("T_name")
- T_sort, _ := c.GetInt("T_sort")
- Illness_r, err := Illness.Read_Illness_ById(T_id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
- c.ServeJSON()
- return
- }
- if len(T_name) > 0 {
- Illness_r.T_name = T_name
- }
- Illness_r.T_sort = T_sort
- if err = Illness.Update_Illness(Illness_r, "T_name", "T_sort"); err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(c.User.T_uuid, "疾病", "修改", Illness_r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *IllnessController) Illness_Del() {
- T_id, _ := c.GetInt("T_id")
- Illness_r, err := Illness.Read_Illness_ById(T_id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
- c.ServeJSON()
- return
- }
- if err = Illness.Delete_Illness(Illness_r); err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs(c.User.T_uuid, "疾病", "删除", strconv.Itoa(T_id))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 疾病
- func (c *IllnessController) IllnessNotice_List() {
- // 分页参数 初始化
- page, _ := c.GetInt("page")
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- T_Illness_id, _ := c.GetInt("T_Illness_id")
- // 查询
- T_name := c.GetString("T_name")
- T_template_status := c.GetString("T_template_status")
- R_List, R_cnt := Illness.Read_IllnessNotice_List(T_Illness_id, T_name, T_template_status, page, page_z)
- var r_jsons lib.R_JSONS
- r_jsons.Num = R_cnt
- r_jsons.Data = R_List
- r_jsons.Page = page
- r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *IllnessController) IllnessNotice_Add() {
- T_Illness_id, _ := c.GetInt("T_Illness_id") // 疾病id
- T_name := c.GetString("T_name") // 名称
- T_content := c.GetString("T_content") // 内容
- // 向赛邮添加短信模板
- template_content := strings.Replace(T_content, "{患者名称}", "@var(name)", -1)
- template_content = strings.Replace(template_content, "{复诊时间}", "@var(time)", -1)
- temp, err := submail.SmsTemplate_Post(c.User.T_user, template_content)
- if err != nil || temp.Status != "success" {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "创建短信模板失败"}
- c.ServeJSON()
- return
- }
- var_ := Illness.IllnessNotice{
- T_Illness_id: T_Illness_id,
- T_name: T_name,
- T_content: T_content,
- T_State: 1,
- T_template_id: temp.Template_id,
- T_template_status: "1",
- }
- Id, err := Illness.Add_IllnessNotice(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(c.User.T_uuid, "疾病通知内容", "添加", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
- c.ServeJSON()
- return
- }
- func (c *IllnessController) IllnessNotice_Edit() {
- T_id, _ := c.GetInt("T_id")
- T_name := c.GetString("T_name") // 名称
- T_content := c.GetString("T_content") // 内容
- IllnessNotice_r, err := Illness.Read_IllnessNotice_ById(T_id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
- c.ServeJSON()
- return
- }
- if IllnessNotice_r.T_content != T_content {
- // 向赛邮添加短信模板
- template_content := strings.Replace(T_content, "{患者名称}", "@var(name)", -1)
- template_content = strings.Replace(template_content, "{复诊时间}", "@var(time)", -1)
- temp, err := submail.SmsTemplate_Put(IllnessNotice_r.T_template_id, c.User.T_user, template_content)
- if err != nil || temp.Status != "success" {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改短信模板失败"}
- c.ServeJSON()
- return
- }
- IllnessNotice_r.T_content = T_content
- IllnessNotice_r.T_template_status = "1"
- IllnessNotice_r.T_template_status_description = ""
- IllnessNotice_r.T_template_reject_reson = ""
- }
- if len(T_name) > 0 {
- IllnessNotice_r.T_name = T_name
- }
- if err = Illness.Update_IllnessNotice(IllnessNotice_r, "T_name", "T_content", "T_template_status", "T_template_status_description", "T_template_reject_reson"); err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(c.User.T_uuid, "疾病通知内容", "修改", IllnessNotice_r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *IllnessController) IllnessNotice_Del() {
- T_id, _ := c.GetInt("T_id")
- IllnessNotice_r, err := Illness.Read_IllnessNotice_ById(T_id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
- c.ServeJSON()
- return
- }
- count, err := Patient.Read_PatientRevisitRecord_Count_ByT_illness_notice(IllnessNotice_r.T_Illness_id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
- c.ServeJSON()
- return
- }
- if count > 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "此内容已关联患者通知信息,禁止删除!"}
- c.ServeJSON()
- return
- }
- // 向赛邮删除短信模板
- temp, err := submail.SmsTemplate_Delete(IllnessNotice_r.T_template_id)
- if err != nil || temp.Status != "success" {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除短信模板失败"}
- c.ServeJSON()
- return
- }
- if err = Illness.Delete_IllnessNotice(IllnessNotice_r); err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs(c.User.T_uuid, "疾病通知内容", "删除", strconv.Itoa(T_id))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func Cron_Illness() {
- //创建一个定时任务对象
- c := cron.New(cron.WithSeconds())
- //给对象增加定时任务
- c.AddFunc("0 */1 * * * ?", Cron_Illness_IllnessNotice)
- //启动定时任务
- c.Start()
- defer c.Stop()
- //查询语句,阻塞,让main函数不退出,保持程序运行
- select {}
- }
- // 同步赛邮云的模板审核状态
- func Cron_Illness_IllnessNotice() {
- list, _ := Illness.Read_IllnessNotice_List(0, "", "1", 0, 9999)
- for _, v := range list {
- // 查询赛邮审核状态
- temp, err := submail.SmsTemplate_Get(v.T_template_id)
- if err != nil || temp.Status != "success" {
- continue
- }
- if temp.Template.Template_status != "1" {
- var_ := Illness.IllnessNotice{
- Id: v.Id,
- T_template_status: temp.Template.Template_status,
- T_template_status_description: temp.Template.Template_status_description,
- T_template_reject_reson: temp.Template.Template_reject_reson,
- }
- Illness.Update_IllnessNotice(var_, "T_template_status", "T_template_status_description", "T_template_reject_reson")
- }
- }
- }
|