feedback.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. package roadshow
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/company"
  7. "hongze/hz_crm_api/models/roadshow"
  8. "hongze/hz_crm_api/utils"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. //路演反馈
  14. // @Title 路演反馈列表
  15. // @Description 路演反馈列表接口
  16. // @Param PageSize query int true "每页数据条数"
  17. // @Param CurrentIndex query int true "当前页页码,从1开始"
  18. // @Param FeedbackType query int true "是否显示已发送反馈请求的路演,0:不显示(默认),1:显示"
  19. // @Param ResearcherId query string true "研究员id,多个用英文逗号隔开"
  20. // @Success 200 {object} roadshow.FeedbackListResp
  21. // @router /feedback/list [get]
  22. func (this *CalendarController) FeedbackList() {
  23. br := new(models.BaseResponse).Init()
  24. defer func() {
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. sysUser := this.SysUser
  29. if sysUser == nil {
  30. br.Msg = "请登录"
  31. br.ErrMsg = "请登录,SysUser Is Empty"
  32. br.Ret = 408
  33. return
  34. }
  35. feedbackType, _ := this.GetInt("FeedbackType")
  36. pageSize, _ := this.GetInt("PageSize")
  37. currentIndex, _ := this.GetInt("CurrentIndex")
  38. researcherId := this.GetString("ResearcherId")
  39. var total int
  40. page := paging.GetPaging(currentIndex, pageSize, total)
  41. var startSize int
  42. if pageSize <= 0 {
  43. pageSize = utils.PageSize10
  44. }
  45. if currentIndex <= 0 {
  46. currentIndex = 1
  47. }
  48. startSize = paging.StartIndex(currentIndex, pageSize)
  49. var condition string
  50. var pars []interface{}
  51. condition += ` AND b.status = 2 `
  52. condition += ` AND a.activity_type = '路演' `
  53. condition += ` AND a.source = 0 `
  54. //结束日期小于当天
  55. endDate := time.Now().Format(utils.FormatDateTime)
  56. startDate := time.Now().AddDate(0, 0, -30).Format(utils.FormatDate)
  57. condition += ` AND b.end_date >= ? `
  58. pars = append(pars, startDate)
  59. condition += ` AND DATE_FORMAT(CONCAT(b.end_date," ",b.end_time),'%Y-%m-%d %H:%i:%S') <= ? `
  60. pars = append(pars, endDate)
  61. if feedbackType == 1 {
  62. condition += ` AND b.feedback_status IN(2,3)`
  63. }
  64. if researcherId != "" {
  65. condition += ` AND b.researcher_id IN(` + researcherId + `)`
  66. }
  67. resp := new(roadshow.FeedbackListResp)
  68. total, err := roadshow.GetFeedbackListCount(condition, pars)
  69. if err != nil && err.Error() != utils.ErrNoRow() {
  70. br.Msg = "获取信息失败"
  71. br.ErrMsg = "获取数据总数失败,GetFeedbackListCount,Err:" + err.Error()
  72. return
  73. }
  74. page = paging.GetPaging(currentIndex, pageSize, total)
  75. dataList, err := roadshow.GetFeedbackList(condition, pars, startSize, pageSize, feedbackType)
  76. if err != nil {
  77. br.Msg = "获取指标信息失败"
  78. br.ErrMsg = "获取数据失败,GetFeedbackList,Err:" + err.Error()
  79. return
  80. }
  81. var companyIdArr []string
  82. companyIdMap := make(map[string]string)
  83. for _, v := range dataList {
  84. if v.CompanyId > 0 {
  85. companyIdStr := strconv.Itoa(v.CompanyId)
  86. if companyIdStr != "" {
  87. if _, ok := companyIdMap[companyIdStr]; !ok {
  88. companyIdArr = append(companyIdArr, companyIdStr)
  89. }
  90. companyIdMap[companyIdStr] = companyIdStr
  91. }
  92. }
  93. }
  94. companyIdArrStr := strings.Join(companyIdArr, ",")
  95. var newCondition string
  96. var newPars []interface{}
  97. newCondition += ` AND product_id=1 `
  98. cp, err := company.GetCompanyProductsByCompanyIds(companyIdArrStr, newCondition, newPars)
  99. if err != nil {
  100. br.Msg = "获取信息失败"
  101. br.ErrMsg = "获取数据失败,GetCompanyProductsByCompanyIds,Err:" + err.Error()
  102. return
  103. }
  104. companyMap := make(map[int]string)
  105. for _, v := range cp {
  106. companyMap[v.CompanyId] = v.Status
  107. }
  108. dataListLen := len(dataList)
  109. for i := 0; i < dataListLen; i++ {
  110. companyId := dataList[i].CompanyId
  111. if findItem, ok := companyMap[companyId]; ok {
  112. dataList[i].CompanyStatus = findItem
  113. }
  114. }
  115. resp.Paging = page
  116. resp.List = dataList
  117. br.Ret = 200
  118. br.Success = true
  119. br.Msg = "获取成功"
  120. br.Data = resp
  121. }
  122. // @Title 请提交路演反馈列表
  123. // @Description 请提交路演反馈列表接口
  124. // @Success 200 {object} roadshow.FeedbackView
  125. // @router /submit/feedback/list [get]
  126. func (this *CalendarController) SubmitFeedbackList() {
  127. br := new(models.BaseResponse).Init()
  128. defer func() {
  129. this.Data["json"] = br
  130. this.ServeJSON()
  131. }()
  132. sysUser := this.SysUser
  133. if sysUser == nil {
  134. br.Msg = "请登录"
  135. br.ErrMsg = "请登录,SysUser Is Empty"
  136. br.Ret = 408
  137. return
  138. }
  139. var condition string
  140. var pars []interface{}
  141. condition += ` AND a.sys_user_id = ? `
  142. pars = append(pars, sysUser.AdminId)
  143. condition += ` AND b.feedback_status = 2 `
  144. dataList, err := roadshow.GetSubmitFeedbackList(condition, pars)
  145. if err != nil {
  146. br.Msg = "获取指标信息失败"
  147. br.ErrMsg = "获取数据失败,GetFeedbackList,Err:" + err.Error()
  148. return
  149. }
  150. br.Ret = 200
  151. br.Success = true
  152. br.Msg = "获取成功"
  153. br.Data = dataList
  154. }
  155. // @Title 填写意见反馈
  156. // @Description 填写意见反馈接口
  157. // @Param request body roadshow.WriteFeedbackReq true "type json string"
  158. // @Success 200
  159. // @router /write/feedback [post]
  160. func (this *CalendarController) WriteFeedback() {
  161. br := new(models.BaseResponse).Init()
  162. defer func() {
  163. this.Data["json"] = br
  164. this.ServeJSON()
  165. }()
  166. sysUser := this.SysUser
  167. if sysUser == nil {
  168. br.Msg = "请登录"
  169. br.ErrMsg = "请登录,SysUser Is Empty"
  170. br.Ret = 408
  171. return
  172. }
  173. var req roadshow.WriteFeedbackReq
  174. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  175. if err != nil {
  176. br.Msg = "参数解析异常!"
  177. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  178. return
  179. }
  180. if req.RsCalendarResearcherId <= 0 {
  181. br.Msg = "参数错误"
  182. br.ErrMsg = "参数错误"
  183. return
  184. }
  185. if req.FeedbackContent == "" {
  186. br.Msg = "反馈内容不能为空"
  187. br.ErrMsg = "反馈内容不能为空"
  188. return
  189. }
  190. err = roadshow.WriteFeedback(&req)
  191. if err != nil {
  192. br.Msg = "保存反馈信息失败"
  193. br.ErrMsg = "保存反馈信息失败,Err:" + err.Error()
  194. return
  195. }
  196. br.Ret = 200
  197. br.Success = true
  198. br.Msg = "保存成功"
  199. }
  200. // @Title 提交路演反馈
  201. // @Description 提交路演反馈接口
  202. // @Param request body roadshow.SubmitFeedbackReq true "type json string"
  203. // @Success 200 {object} roadshow.FeedbackView
  204. // @router /submit/feedback [post]
  205. func (this *CalendarController) SubmitFeedback() {
  206. br := new(models.BaseResponse).Init()
  207. defer func() {
  208. this.Data["json"] = br
  209. this.ServeJSON()
  210. }()
  211. sysUser := this.SysUser
  212. if sysUser == nil {
  213. br.Msg = "请登录"
  214. br.ErrMsg = "请登录,SysUser Is Empty"
  215. br.Ret = 408
  216. return
  217. }
  218. var req roadshow.SubmitFeedbackReq
  219. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  220. if err != nil {
  221. br.Msg = "参数解析异常!"
  222. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  223. return
  224. }
  225. for _, v := range req.List {
  226. err = roadshow.SubmitFeedbackInfo(v.RsCalendarResearcherId)
  227. if err != nil {
  228. br.Msg = "保存失败!"
  229. br.ErrMsg = "保存失败,Err:" + err.Error()
  230. return
  231. }
  232. }
  233. br.Ret = 200
  234. br.Success = true
  235. br.Msg = "保存成功"
  236. }
  237. // @Title 发送路演反馈请求
  238. // @Description 发送路演反馈请求接口
  239. // @Param request body roadshow.SubmitFeedbackReq true "type json string"
  240. // @Success 200 {object} roadshow.FeedbackView
  241. // @router /send/feedback [post]
  242. func (this *CalendarController) SendFeedback() {
  243. br := new(models.BaseResponse).Init()
  244. defer func() {
  245. this.Data["json"] = br
  246. this.ServeJSON()
  247. }()
  248. sysUser := this.SysUser
  249. if sysUser == nil {
  250. br.Msg = "请登录"
  251. br.ErrMsg = "请登录,SysUser Is Empty"
  252. br.Ret = 408
  253. return
  254. }
  255. var req roadshow.SubmitFeedbackReq
  256. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  257. if err != nil {
  258. br.Msg = "参数解析异常!"
  259. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  260. return
  261. }
  262. for _, v := range req.List {
  263. err = roadshow.SendFeedbackInfo(v.RsCalendarResearcherId)
  264. if err != nil {
  265. br.Msg = "保存失败!"
  266. br.ErrMsg = "保存失败,Err:" + err.Error()
  267. return
  268. }
  269. }
  270. br.Ret = 200
  271. br.Success = true
  272. br.Msg = "保存成功"
  273. }