cust_customer_contact.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package cust
  2. import (
  3. "context"
  4. "dashoo.cn/opms_libary/myerrors"
  5. "github.com/gogf/gf/util/gconv"
  6. "dashoo.cn/micro/app/dao/cust"
  7. model "dashoo.cn/micro/app/model/cust"
  8. "dashoo.cn/micro/app/service"
  9. //serviceLog "dashoo.cn/micro/app/service/cust"
  10. )
  11. type CustomercontactService struct {
  12. *service.ContextService
  13. Dao *cust.CustCustomerContactDao
  14. }
  15. func NewCustomerContactService(ctx context.Context) (svc *CustomercontactService, err error) {
  16. svc = new(CustomercontactService)
  17. if svc.ContextService, err = svc.Init(ctx); err != nil {
  18. return nil, err
  19. }
  20. svc.Dao = cust.NewCustCustomerContactDao(svc.Tenant)
  21. return svc, nil
  22. }
  23. //添加联系人
  24. func (c *CustomercontactService) Create(req *model.CustCustomerContactSeq) (err error) {
  25. contact := new(model.CustCustomerContact)
  26. if err = gconv.Struct(req, contact); err != nil {
  27. err = myerrors.NewMsgError(nil, "添加联系人 验证失败")
  28. return
  29. }
  30. service.SetCreatedInfo(contact, c.GetCxtUserId(), c.GetCxtUserName())
  31. Model := c.Dao
  32. _, err = Model.Insert(contact)
  33. if err != nil {
  34. err = myerrors.New("添加联系人,Create Sql执行异常", err)
  35. return
  36. }
  37. return
  38. }
  39. //修改联系人
  40. func (c *CustomercontactService) UpdateById(req *model.UpdateCustCustomerContactSeq) (err error) {
  41. Model := c.Dao.M
  42. contactCount, err := Model.Count("Id", req.Id)
  43. if err != nil {
  44. err = myerrors.New("修改联系人,FindOne Sql执行异常", err)
  45. return
  46. }
  47. if contactCount == 0 {
  48. err = myerrors.NewMsgError(nil, "修改联系人信息不存在")
  49. return
  50. }
  51. CustomertData := new(model.CustCustomerContact)
  52. if err = gconv.Struct(req, CustomertData); err != nil {
  53. return
  54. }
  55. service.SetUpdatedInfo(CustomertData, c.GetCxtUserId(), c.GetCxtUserName())
  56. _, err = Model.FieldsEx(c.Dao.Columns.CreatedTime, c.Dao.Columns.CreatedBy, c.Dao.Columns.CreatedName, c.Dao.Columns.CustId, c.Dao.Columns.Id).
  57. WherePri(c.Dao.Columns.Id, req.Id).Update(CustomertData)
  58. if err != nil {
  59. err = myerrors.New("修改联系人,UpdateById Sql执行异常", err)
  60. return
  61. }
  62. return
  63. }
  64. //获取联系人信息
  65. func (c *CustomercontactService) GetList(CustId int) (Info []*model.CustCustomerContactInfo, err error) {
  66. Model := c.Dao
  67. err = Model.Where(c.Dao.Columns.CustId, CustId).Where(c.Dao.Columns.DeletedTime + " is null").Scan(&Info)
  68. if err != nil {
  69. err = myerrors.New("获取联系人信息,GetList Sql执行异常", err)
  70. return
  71. }
  72. return
  73. }
  74. //删除联系人
  75. func (c *CustomercontactService) DeleteById(id int) error {
  76. Model := c.Dao
  77. // 删除客户联系人表
  78. _, err := Model.Where(c.Dao.Columns.Id, id).Delete()
  79. if err != nil {
  80. return myerrors.New("删除联系人,DeleteById Sql执行异常", err)
  81. }
  82. return nil
  83. }