english_company_todo.go 9.7 KB

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