english_company_todo.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. // 英文客户Todo状态枚举值
  8. const (
  9. EnglishCompanyTodoStatusDoing = "进行中"
  10. EnglishCompanyTodoStatusCompleted = "已完成"
  11. EnglishCompanyTodoStatusVoided = "已作废"
  12. EnglishCompanyTodoStatusNull = "无任务"
  13. )
  14. // EnglishCompanyTodo 英文客户TODO任务
  15. type EnglishCompanyTodo struct {
  16. Id int `gorm:"column:id;primaryKey" description:"任务ID"`
  17. CompanyId int `gorm:"column:company_id" description:"客户ID"`
  18. Content string `gorm:"column:content" description:"任务描述"`
  19. SellerId int `gorm:"column:seller_id" description:"客户所属销售ID"`
  20. SellerName string `gorm:"column:seller_name" description:"客户所属销售名称"`
  21. CreateUserId int `gorm:"column:create_user_id" description:"创建人用户ID"`
  22. CreateUserName string `gorm:"column:create_user_name" description:"创建人用户姓名"`
  23. ApproveUserId int `gorm:"column:approve_user_id" description:"审批人用户ID"`
  24. ApproveUserName string `gorm:"column:approve_user_name" description:"审批人用户姓名"`
  25. ApprovedSellerId int `gorm:"column:approved_seller_id" description:"审批时,客户所属销售ID"`
  26. ApprovedSellerName string `gorm:"column:approved_seller_name" description:"审批时,客户所属销售名称"`
  27. Status string `gorm:"column:status" description:"任务状态: 枚举值:进行中,已完成,已作废"`
  28. ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
  29. ApproveTime time.Time `gorm:"column:approve_time" description:"审核时间"`
  30. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  31. EndTime time.Time `gorm:"column:end_time" description:"截止时间"`
  32. IsDelete int `gorm:"column:is_delete" json:"-" description:"是否已经删除,0:未删除,1:已删除;默认:0"`
  33. Remark string `gorm:"column:remark" description:"审批备注"`
  34. }
  35. // EnglishCompanyTodoResp 英文客户TODO响应体
  36. type EnglishCompanyTodoResp struct {
  37. Id int `orm:"column(id);pk" gorm:"primaryKey" `
  38. CompanyId int `description:"客户id"`
  39. Content string `description:"任务描述"`
  40. SellerId int `description:"客户所属销售id"`
  41. SellerName string `description:"客户所属销售名称"`
  42. CreateUserId int `description:"创建人用户id"`
  43. CreateUserName string `description:"创建人用户姓名"`
  44. ApproveUserId int `description:"审批人用户id"`
  45. ApproveUserName string `description:"审批人用户姓名"`
  46. Status string `description:"任务状态: 枚举值:进行中,已完成,已作废"`
  47. CreateTime string `description:"创建时间"`
  48. EndTime string `description:"截止时间"`
  49. ApproveTime string `description:"审核时间"`
  50. EndTimeStr string `description:"格式化后的截止时间"`
  51. Remark string `description:"审批备注"`
  52. }
  53. func (item *EnglishCompanyTodo) Create() (err error) {
  54. err = global.DmSQL["rddp"].Create(item).Error
  55. return
  56. }
  57. func (item *EnglishCompanyTodo) Update(cols []string) (err error) {
  58. err = global.DmSQL["rddp"].Select(cols).Updates(item).Error
  59. return
  60. }
  61. // EnglishCompanyTodoAddReq 新增任务请求
  62. type EnglishCompanyTodoAddReq struct {
  63. CompanyId int `description:"客户id"`
  64. Description string `description:"任务描述"`
  65. EndTime string `description:"截止时间"`
  66. }
  67. // EnglishCompanyTodoEditReq 编辑任务请求
  68. type EnglishCompanyTodoEditReq struct {
  69. Id int `description:"客户任务记录id"`
  70. CompanyId int `description:"客户id"`
  71. Description string `description:"任务描述"`
  72. EndTime string `description:"截止时间"`
  73. }
  74. // EnglishCompanyTodoApproveReq 审批任务请求
  75. type EnglishCompanyTodoApproveReq struct {
  76. Id int `description:"客户任务记录id"`
  77. Remark string `description:"审批备注"`
  78. }
  79. // GetEnglishCompanyTodoById 根据任务ID获取客户任务
  80. func GetEnglishCompanyTodoById(id int) (item *EnglishCompanyTodo, err error) {
  81. sql := `SELECT * FROM english_company_todo WHERE id = ? LIMIT 1 `
  82. err = global.DmSQL["rddp"].Raw(sql, id).First(&item).Error
  83. return
  84. }
  85. // GetCountDoingEnglishCompanyTodo 获取正在进行中的任务数量
  86. func GetCountDoingEnglishCompanyTodo(companyId int) (total int, err error) {
  87. sql := `SELECT count(1) AS total FROM english_company_todo WHERE status = "进行中" AND company_id = ? AND is_delete = 0 `
  88. err = global.DmSQL["rddp"].Raw(sql, companyId).Scan(&total).Error
  89. return
  90. }
  91. // GetEnglishCompanyTodoPageListResp 英文客户TODO-分页列表
  92. type GetEnglishCompanyTodoPageListResp struct {
  93. List []*EnglishCompanyTodoResp
  94. Paging *paging.PagingItem `description:"分页数据"`
  95. }
  96. // GetEnglishCompanyTodoList 获取客户任务列表
  97. func GetEnglishCompanyTodoList(companyId, startSize, pageSize int, order string) (total int, items []*EnglishCompanyTodo, err error) {
  98. sql := `SELECT
  99. a.*
  100. FROM
  101. english_company_todo a
  102. JOIN english_company b ON a.company_id = b.company_id
  103. WHERE
  104. a.company_id = ? AND a.status != "已作废" AND a.is_delete = 0 `
  105. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  106. if err = global.DmSQL["rddp"].Raw(totalSQl, companyId).Scan(&total).Error; err != nil {
  107. return
  108. }
  109. if order != `` {
  110. sql += order
  111. } else {
  112. sql += ` ORDER BY a.create_time DESC`
  113. }
  114. sql += ` LIMIT ?,?`
  115. err = global.DmSQL["rddp"].Raw(sql, companyId, startSize, pageSize).Find(&items).Error
  116. return
  117. }
  118. // GetDoingEnglishCompanyTodoList 获取客户的进行中任务列表
  119. func GetDoingEnglishCompanyTodoList(companyId int) (items []*EnglishCompanyTodo, err error) {
  120. sql := `SELECT
  121. a.*
  122. FROM
  123. english_company_todo a
  124. JOIN english_company b ON a.company_id = b.company_id
  125. WHERE
  126. a.company_id = ? AND a.status = "进行中" AND a.is_delete = 0
  127. ORDER BY
  128. a.create_time ASC`
  129. err = global.DmSQL["rddp"].Raw(sql, companyId).Find(&items).Error
  130. return
  131. }
  132. type EnglishCompanyTodoDoing struct {
  133. Id int `description:"待办ID"`
  134. CompanyId int `description:"客户id"`
  135. CompanyName string `description:"客户名称"`
  136. Content string `description:"任务描述"`
  137. SellerId int `description:"客户所属销售id"`
  138. SellerName string `description:"客户所属销售名称"`
  139. CreateUserId int `description:"创建人用户id"`
  140. CreateUserName string `description:"创建人用户姓名"`
  141. ApproveUserId int `description:"审批人用户id"`
  142. ApproveUserName string `description:"审批人用户姓名"`
  143. ApprovedSellerId int `description:"审批时,客户所属销售id"`
  144. ApprovedSellerName string `description:"审批时,客户所属销售名称"`
  145. Status string `description:"任务状态: 枚举值:进行中,已完成,已作废"`
  146. ModifyTime time.Time `description:"修改时间"`
  147. ApproveTime time.Time `description:"审核时间"`
  148. CreateTime time.Time `description:"创建时间"`
  149. EndTime time.Time `description:"截止时间"`
  150. Remark string `description:"审批备注"`
  151. }
  152. type EnglishCompanyTodoDoingResp struct {
  153. Id int `description:"待办ID"`
  154. CompanyId int `description:"客户id"`
  155. CompanyName string `description:"客户名称"`
  156. Content string `description:"任务描述"`
  157. SellerId int `description:"客户所属销售id"`
  158. SellerName string `description:"客户所属销售名称"`
  159. CreateUserId int `description:"创建人用户id"`
  160. CreateUserName string `description:"创建人用户姓名"`
  161. ApproveUserId int `description:"审批人用户id"`
  162. ApproveUserName string `description:"审批人用户姓名"`
  163. Status string `description:"任务状态: 枚举值:进行中,已完成,已作废"`
  164. CreateTime string `description:"创建时间"`
  165. EndTime string `description:"截止时间"`
  166. ApproveTime string `description:"审核时间"`
  167. Remark string `description:"审批备注"`
  168. }
  169. // GetEnglishCompanyTodoDoingPageListResp 英文客户未完成TODO-分页列表
  170. type GetEnglishCompanyTodoDoingPageListResp struct {
  171. List []*EnglishCompanyTodoDoingResp
  172. Paging *paging.PagingItem `description:"分页数据"`
  173. }
  174. // GetEnglishCompanyTodoDoingList 获取客户任务未完成列表
  175. func GetEnglishCompanyTodoDoingList(startSize, pageSize int, order string) (total int, items []*EnglishCompanyTodoDoing, err error) {
  176. sql := `SELECT
  177. a.*,
  178. b.company_name
  179. FROM
  180. english_company_todo a
  181. JOIN english_company b ON a.company_id = b.company_id
  182. WHERE
  183. a.status = "进行中" AND a.is_delete = 0 `
  184. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  185. if err = global.DmSQL["rddp"].Raw(totalSQl).Scan(&total).Error; err != nil {
  186. return
  187. }
  188. if order != `` {
  189. sql += order
  190. } else {
  191. sql += ` ORDER BY a.end_time ASC`
  192. }
  193. sql += ` LIMIT ?,?`
  194. err = global.DmSQL["rddp"].Raw(sql, startSize, pageSize).Find(&items).Error
  195. return
  196. }
  197. // DeleteEnglishCompanyTodoByCompanyId (软)删除英文客户TODO
  198. func DeleteEnglishCompanyTodoByCompanyId(companyId int) (err error) {
  199. sql := `UPDATE english_company_todo SET is_delete = 1 WHERE company_id = ?`
  200. err = global.DmSQL["rddp"].Exec(sql, companyId).Error
  201. return
  202. }