property_review.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/member/model"
  5. "github.com/pkg/errors"
  6. )
  7. const (
  8. _addUserMonitor = "INSERT INTO user_monitor(mid, operator, remark) VALUES(?,?,?) ON DUPLICATE KEY UPDATE operator=VALUES(operator), remark=VALUES(remark), is_deleted=0"
  9. _isInUserMonitor = "SELECT count(1) FROM user_monitor WHERE mid=? and is_deleted=0"
  10. _addPropertyReview = "INSERT INTO user_property_review(mid, old, new, state, property, is_monitor, extra) VALUES (?,?,?,?,?,?,?)"
  11. _archivePropertyReview = "UPDATE user_property_review SET state=?, operator=?, remark=? WHERE mid=? AND property=? AND state=0"
  12. )
  13. // AddUserMonitor is.
  14. func (d *Dao) AddUserMonitor(ctx context.Context, mid int64, operator, remark string) error {
  15. if _, err := d.db.Exec(ctx, _addUserMonitor, mid, operator, remark); err != nil {
  16. return errors.Wrapf(err, "dao add user monitor")
  17. }
  18. return nil
  19. }
  20. // IsInUserMonitor is.
  21. func (d *Dao) IsInUserMonitor(ctx context.Context, mid int64) (bool, error) {
  22. row := d.db.QueryRow(ctx, _isInUserMonitor, mid)
  23. inMonitor := false
  24. if err := row.Scan(&inMonitor); err != nil {
  25. return false, errors.Wrapf(err, "dao is in user monitor")
  26. }
  27. return inMonitor, nil
  28. }
  29. // AddPropertyReview is.
  30. func (d *Dao) AddPropertyReview(ctx context.Context, r *model.UserPropertyReview) error {
  31. if _, err := d.db.Exec(ctx, _addPropertyReview, r.Mid, r.Old, r.New, r.State, r.Property, r.IsMonitor, r.Extra); err != nil {
  32. return errors.Wrapf(err, "dao add user property review")
  33. }
  34. return nil
  35. }
  36. // ArchivePropertyReview is.
  37. func (d *Dao) ArchivePropertyReview(ctx context.Context, mid int64, property int8) error {
  38. if _, err := d.db.Exec(ctx, _archivePropertyReview, model.ReviewStateArchived, "system", "已存在待审核单,本条归档处理", mid, property); err != nil {
  39. return errors.Wrapf(err, "dao archive property review")
  40. }
  41. return nil
  42. }