ctr_contract_application.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "dashoo.cn/opms_libary/micro_srv"
  6. "dashoo.cn/opms_libary/myerrors"
  7. "dashoo.cn/opms_libary/request"
  8. dao "dashoo.cn/opms_parent/app/dao/contract"
  9. model "dashoo.cn/opms_parent/app/model/contract"
  10. "github.com/gogf/gf/frame/g"
  11. )
  12. type CtrContractApplicationService struct {
  13. Dao *dao.CtrContractApplicationDao
  14. Tenant string
  15. userInfo request.UserInfo
  16. }
  17. func NewCtrContractApplicationService(ctx context.Context) (*CtrContractApplicationService, error) {
  18. tenant, err := micro_srv.GetTenant(ctx)
  19. if err != nil {
  20. err = myerrors.TipsError(fmt.Sprintf("获取租户码异常:%s", err.Error()))
  21. return nil, err
  22. }
  23. userInfo, err := micro_srv.GetUserInfo(ctx)
  24. if err != nil {
  25. err = myerrors.TipsError(fmt.Sprintf("获取用户信息异常:%s", err.Error()))
  26. return nil, err
  27. }
  28. return &CtrContractApplicationService{
  29. Dao: dao.NewCtrContractApplicationDao(tenant),
  30. Tenant: tenant,
  31. userInfo: userInfo,
  32. }, nil
  33. }
  34. func (s *CtrContractApplicationService) CreateFromBusiness(req *model.CreateFromBusinessReq) (int, error) {
  35. exists, err := s.CheckPendingApplication(req.NboId)
  36. if err != nil {
  37. return 0, err
  38. }
  39. if exists {
  40. return 0, myerrors.TipsError("该项目已有待处理的合同申请")
  41. }
  42. data := g.Map{
  43. "nbo_id": req.NboId,
  44. "nbo_name": req.NboName,
  45. "status": "10",
  46. "created_by": s.userInfo.Id,
  47. "created_name": s.userInfo.UserName,
  48. }
  49. result, err := s.Dao.Insert(data)
  50. if err != nil {
  51. return 0, myerrors.CreateError(err, "合同申请")
  52. }
  53. lastId, err := result.LastInsertId()
  54. if err != nil {
  55. return 0, err
  56. }
  57. return int(lastId), nil
  58. }
  59. func (s *CtrContractApplicationService) CheckPendingApplication(nboId int) (bool, error) {
  60. record, err := s.Dao.Where("nbo_id", nboId).
  61. Where("status", "10").
  62. Where("deleted_time IS NULL").
  63. One()
  64. if err != nil {
  65. return false, err
  66. }
  67. return record != nil, nil
  68. }