| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package service
- import (
- "context"
- "fmt"
- "dashoo.cn/opms_libary/micro_srv"
- "dashoo.cn/opms_libary/myerrors"
- "dashoo.cn/opms_libary/request"
- dao "dashoo.cn/opms_parent/app/dao/contract"
- model "dashoo.cn/opms_parent/app/model/contract"
- "github.com/gogf/gf/frame/g"
- )
- type CtrContractApplicationService struct {
- Dao *dao.CtrContractApplicationDao
- Tenant string
- userInfo request.UserInfo
- }
- func NewCtrContractApplicationService(ctx context.Context) (*CtrContractApplicationService, error) {
- tenant, err := micro_srv.GetTenant(ctx)
- if err != nil {
- err = myerrors.TipsError(fmt.Sprintf("获取租户码异常:%s", err.Error()))
- return nil, err
- }
- userInfo, err := micro_srv.GetUserInfo(ctx)
- if err != nil {
- err = myerrors.TipsError(fmt.Sprintf("获取用户信息异常:%s", err.Error()))
- return nil, err
- }
- return &CtrContractApplicationService{
- Dao: dao.NewCtrContractApplicationDao(tenant),
- Tenant: tenant,
- userInfo: userInfo,
- }, nil
- }
- func (s *CtrContractApplicationService) CreateFromBusiness(req *model.CreateFromBusinessReq) (int, error) {
- exists, err := s.CheckPendingApplication(req.NboId)
- if err != nil {
- return 0, err
- }
- if exists {
- return 0, myerrors.TipsError("该项目已有待处理的合同申请")
- }
- data := g.Map{
- "nbo_id": req.NboId,
- "nbo_name": req.NboName,
- "status": "10",
- "created_by": s.userInfo.Id,
- "created_name": s.userInfo.UserName,
- }
- result, err := s.Dao.Insert(data)
- if err != nil {
- return 0, myerrors.CreateError(err, "合同申请")
- }
- lastId, err := result.LastInsertId()
- if err != nil {
- return 0, err
- }
- return int(lastId), nil
- }
- func (s *CtrContractApplicationService) CheckPendingApplication(nboId int) (bool, error) {
- record, err := s.Dao.Where("nbo_id", nboId).
- Where("status", "10").
- Where("deleted_time IS NULL").
- One()
- if err != nil {
- return false, err
- }
- return record != nil, nil
- }
|