demand.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package crm
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "server/dao/crm"
  6. "server/global"
  7. "server/model/common/response"
  8. "strconv"
  9. )
  10. type DemandApi struct{}
  11. func (da *DemandApi) QueryDemandsByCustomerId(c *gin.Context) {
  12. id := c.Query("id")
  13. customerId, err := strconv.Atoi(id)
  14. fmt.Print("customerId:", customerId)
  15. demands, err := demandService.QueryDemandsByCustomerId(customerId)
  16. if err != nil {
  17. response.FailWithMessage("查询失败", c)
  18. global.GVA_LOG.Error("QueryDemandsByCustomerId ====== " + err.Error())
  19. return
  20. }
  21. response.OkWithData(demands, c)
  22. }
  23. func (da *DemandApi) CreateDemand(c *gin.Context) {
  24. var demand crm.Demand
  25. err := c.ShouldBindJSON(&demand)
  26. if err != nil {
  27. response.FailWithMessage("参数错误", c)
  28. global.GVA_LOG.Error("CreateDemand ====== " + err.Error())
  29. return
  30. }
  31. err = demandService.CreateDemand(demand)
  32. if err != nil {
  33. response.FailWithMessage("创建失败", c)
  34. global.GVA_LOG.Error("CreateDemand ====== " + err.Error())
  35. return
  36. }
  37. response.OkWithMessage("创建成功", c)
  38. }
  39. func (da *DemandApi) UpdateDemand(c *gin.Context) {
  40. var demand crm.Demand
  41. err := c.ShouldBindJSON(&demand)
  42. fmt.Println(demand)
  43. if err != nil {
  44. response.FailWithMessage("参数错误", c)
  45. global.GVA_LOG.Error("UpdateDemand ====== " + err.Error())
  46. return
  47. }
  48. err = demandService.UpdateDemand(demand)
  49. if err != nil {
  50. response.FailWithMessage("更新失败", c)
  51. global.GVA_LOG.Error("UpdateDemand ====== " + err.Error())
  52. return
  53. }
  54. response.OkWithMessage("更新成功", c)
  55. }
  56. func (da *DemandApi) DeleteDemand(c *gin.Context) {
  57. id := c.Query("id")
  58. demandId, _ := strconv.Atoi(id)
  59. err := demandService.DeleteDemand(demandId)
  60. if err != nil {
  61. response.FailWithMessage("删除失败", c)
  62. global.GVA_LOG.Error("DeleteDemand ====== " + err.Error())
  63. return
  64. }
  65. response.OkWithMessage("删除成功", c)
  66. }