company_todo.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hz_crm_api/models"
  5. "hongze/hz_crm_api/models/company_todo"
  6. "hongze/hz_crm_api/services"
  7. "hongze/hz_crm_api/utils"
  8. "time"
  9. )
  10. // CompanyTodoController 客户任务列表
  11. type CompanyTodoController struct {
  12. BaseAuthController
  13. }
  14. // Add
  15. // @Title 新增任务
  16. // @Description 新增任务接口
  17. // @Param request body company_todo.CompanyTodoAddReq true "type json string"
  18. // @Success 200 新增成功
  19. // @router /company_todo/add [post]
  20. func (this *CompanyTodoController) Add() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. this.Data["json"] = br
  24. this.ServeJSON()
  25. }()
  26. var req company_todo.CompanyTodoAddReq
  27. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  28. if err != nil {
  29. br.Msg = "参数解析异常!"
  30. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  31. return
  32. }
  33. if req.CompanyId <= 0 {
  34. br.Msg = "请选择客户"
  35. br.ErrMsg = "客户ID不能为空"
  36. return
  37. }
  38. if req.Description == "" {
  39. br.Msg = "任务描述不能为空"
  40. return
  41. }
  42. if req.EndTime == "" {
  43. br.Msg = "请输入截止日期"
  44. return
  45. }
  46. endTime, err := time.ParseInLocation(utils.FormatDate, req.EndTime, time.Local)
  47. if err != nil {
  48. br.Msg = "截止日期格式错误"
  49. return
  50. }
  51. description := utils.TrimStr(req.Description)
  52. productId := services.GetProductId(this.SysUser.RoleTypeCode)
  53. if productId == 0 {
  54. if this.SysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  55. productId = req.ProductId
  56. } else {
  57. br.Msg = "账号角色异常,不允许添加任务"
  58. return
  59. }
  60. }
  61. // 新增任务
  62. errMsg, err := services.AddCompanyTodo(req.CompanyId, productId, description, endTime, this.SysUser)
  63. if err != nil {
  64. br.Msg = errMsg
  65. br.ErrMsg = "添加任务失败,err:" + err.Error()
  66. return
  67. }
  68. br.Ret = 200
  69. br.Success = true
  70. br.Msg = "提交成功"
  71. }
  72. // EditList
  73. // @Title 获取客户待操作任务列表
  74. // @Description 获取客户待操作任务列表接口
  75. // @Param CompanyId query int true "客户id"
  76. // @Success 200 {object} []company_todo.CompanyTodo
  77. // @router /company_todo/edit_list [get]
  78. func (this *CompanyTodoController) EditList() {
  79. br := new(models.BaseResponse).Init()
  80. defer func() {
  81. this.Data["json"] = br
  82. this.ServeJSON()
  83. }()
  84. companyId, _ := this.GetInt("CompanyId")
  85. if companyId <= 0 {
  86. br.Msg = "请选择客户"
  87. return
  88. }
  89. productId := services.GetProductId(this.SysUser.RoleTypeCode)
  90. if productId == 0 && this.SysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  91. br.Msg = "账号角色异常"
  92. return
  93. }
  94. // 获取进行中的任务信息
  95. todoList, err := company_todo.GetDoingCompanyTodoList(companyId, productId)
  96. if err != nil {
  97. br.Msg = "获取任务信息失败"
  98. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  99. return
  100. }
  101. var list []*company_todo.CompanyTodoListItem
  102. for _, v := range todoList {
  103. temp := &company_todo.CompanyTodoListItem{
  104. CompanyTodo: v,
  105. }
  106. temp.EndTimeStr = temp.EndTime.Format(utils.FormatDate)
  107. if temp.EndTimeStr == "0001-01-01" {
  108. temp.EndTimeStr = ""
  109. }
  110. list = append(list, temp)
  111. }
  112. br.Ret = 200
  113. br.Success = true
  114. br.Msg = "获取成功"
  115. br.Data = list
  116. }
  117. // List
  118. // @Title 任务列表
  119. // @Description 客户任务列表接口
  120. // @Param CompanyId query int true "客户id"
  121. // @Success 200 {object} []company_todo.CompanyTodo
  122. // @router /company_todo/list [get]
  123. func (this *CompanyTodoController) List() {
  124. br := new(models.BaseResponse).Init()
  125. defer func() {
  126. this.Data["json"] = br
  127. this.ServeJSON()
  128. }()
  129. companyId, _ := this.GetInt("CompanyId")
  130. if companyId <= 0 {
  131. br.Msg = "请选择客户"
  132. return
  133. }
  134. productId := services.GetProductId(this.SysUser.RoleTypeCode)
  135. if productId == 0 && this.SysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  136. br.Msg = "账号角色异常"
  137. return
  138. }
  139. // 获取任务信息
  140. todos, err := company_todo.GetCompanyTodoList(companyId, productId)
  141. if err != nil {
  142. br.Msg = "获取任务信息失败"
  143. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  144. return
  145. }
  146. var list []*company_todo.CompanyTodoListItem
  147. for _, v := range todos {
  148. temp := &company_todo.CompanyTodoListItem{
  149. CompanyTodo: v,
  150. }
  151. temp.EndTimeStr = temp.EndTime.Format(utils.FormatDate)
  152. if temp.EndTimeStr == "0001-01-01" {
  153. temp.EndTimeStr = ""
  154. }
  155. list = append(list, temp)
  156. }
  157. br.Ret = 200
  158. br.Success = true
  159. br.Msg = "获取成功"
  160. br.Data = list
  161. }
  162. // Edit
  163. // @Title 修改分组
  164. // @Description 修改分组接口
  165. // @Param request body system.SysTeamEditReq true "type json string"
  166. // @Success 200 修改成功
  167. // @router /company_todo/edit [post]
  168. func (this *CompanyTodoController) Edit() {
  169. br := new(models.BaseResponse).Init()
  170. defer func() {
  171. this.Data["json"] = br
  172. this.ServeJSON()
  173. }()
  174. var req company_todo.CompanyTodoEditReq
  175. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  176. if err != nil {
  177. br.Msg = "参数解析异常!"
  178. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  179. return
  180. }
  181. if req.Id <= 0 {
  182. br.Msg = "请选择客户"
  183. br.ErrMsg = "客户ID不能为空"
  184. return
  185. }
  186. if req.Description == "" {
  187. br.Msg = "任务描述不能为空"
  188. return
  189. }
  190. if req.EndTime == "" {
  191. br.Msg = "请输入截止日期"
  192. return
  193. }
  194. endTime, err := time.ParseInLocation(utils.FormatDate, req.EndTime, time.Local)
  195. if err != nil {
  196. br.Msg = "截止日期格式错误"
  197. return
  198. }
  199. description := utils.TrimStr(req.Description)
  200. errMsg, err := services.EditCompanyTodo(req.Id, description, endTime, this.SysUser)
  201. if err != nil {
  202. br.Msg = errMsg
  203. br.ErrMsg = errMsg + ",Err:" + err.Error()
  204. return
  205. }
  206. br.Ret = 200
  207. br.Success = true
  208. br.Msg = "保存成功"
  209. }
  210. // Approve
  211. // @Title 审批任务
  212. // @Description 审批任务接口
  213. // @Param request body company_todo.ApproveCompanyTodoReq true "type json string"
  214. // @Success 200 审批通过
  215. // @router /company_todo/approve [post]
  216. func (this *CompanyTodoController) Approve() {
  217. br := new(models.BaseResponse).Init()
  218. defer func() {
  219. this.Data["json"] = br
  220. this.ServeJSON()
  221. }()
  222. var req company_todo.ApproveCompanyTodoReq
  223. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  224. if err != nil {
  225. br.Msg = "参数解析异常!"
  226. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  227. return
  228. }
  229. if req.Id <= 0 {
  230. br.Msg = "参数错误"
  231. br.ErrMsg = "参数错误,任务编号必传 "
  232. return
  233. }
  234. errMsg, err := services.ApproveCompanyTodo(req.Id, req.Remark, this.SysUser)
  235. if err != nil {
  236. br.Msg = errMsg
  237. br.ErrMsg = errMsg + ",Err:" + err.Error()
  238. return
  239. }
  240. br.Ret = 200
  241. br.Success = true
  242. br.Msg = "审核完成"
  243. }