english_company_todo.go 10 KB

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