| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package proj
- import (
- "context"
- custDao "dashoo.cn/micro/app/dao/cust"
- projDao "dashoo.cn/micro/app/dao/proj"
- projModel "dashoo.cn/micro/app/model/proj"
- "dashoo.cn/micro/app/service"
- "dashoo.cn/opms_libary/myerrors"
- "github.com/gogf/gf/database/gdb"
- "github.com/gogf/gf/frame/g"
- )
- type businessContactService struct {
- *service.ContextService
- Dao *projDao.ProjBusinessContactDao
- }
- func NewBusinessContactService(ctx context.Context) (svc *businessContactService, err error) {
- svc = new(businessContactService)
- if svc.ContextService, err = svc.Init(ctx); err != nil {
- return nil, err
- }
- svc.Dao = projDao.NewProjBusinessContactDao(svc.Tenant)
- return svc, nil
- }
- func (p *businessContactService) GetList(req *projModel.BusinessReq) (total int, contactList []*projModel.BusinessContact, err error) {
- db := p.Dao.As("bus").LeftJoin(custDao.CustCustomerContact.Table, "contact", "bus.contact_id=contact.id").
- Where("bus."+p.Dao.Columns.BusId, req.BusId)
- if req.CuctId != 0 {
- db = db.Where("contact.cuct_id", req.CuctId)
- }
- if req.CuctName != "" {
- db = db.Where("contact.cuct_name", req.BusId)
- }
- total, err = db.Count()
- if err != nil {
- g.Log().Error(err)
- return
- }
- err = db.Fields("bus.*, contact.*,bus.id AS id").Page(req.GetPage()).Order("bus.id desc").Scan(&contactList)
- return
- }
- func (p *businessContactService) Create(req *projModel.BusinessContactReq) (err error) {
- contactList := make([]*projModel.ProjBusinessContact, 0)
- for _, v := range req.ContactIds {
- data := new(projModel.ProjBusinessContact)
- data.BusId = req.BusId
- data.ContactId = v
- data.Remark = req.Remark
- service.SetCreatedInfo(data, p.GetCxtUserId(), p.GetCxtUserName())
- contactList = append(contactList, data)
- }
- b, _ := NewBusinessService(p.Ctx)
- err = p.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- _, err = p.Dao.Insert(&contactList)
- if err != nil {
- return err
- }
- // 添加项目动态
- dynamics := projModel.ProjBusinessDynamics{
- BusId: req.BusId,
- OpnType: "70",
- }
- err = b.CreateProjBusinessDynamics(tx, dynamics, nil)
- return err
- })
- return
- }
- func (p *businessContactService) DeleteByIds(ids []int64) (err error) {
- result, err := p.Dao.Where(projDao.ProjBusinessContact.Columns.Id+" IN(?)", ids).One()
- if err != nil {
- return err
- }
- if result == nil {
- return myerrors.NewMsgError(nil, "联系人不存在")
- }
- b, _ := NewBusinessService(p.Ctx)
- err = p.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- _, err = p.Dao.WhereIn(projDao.ProjBusinessContact.Columns.Id, ids).Delete()
- if err != nil {
- return err
- }
- // 添加项目动态
- dynamics := projModel.ProjBusinessDynamics{
- BusId: result.BusId,
- OpnType: "80",
- }
- err = b.CreateProjBusinessDynamics(tx, dynamics, nil)
- return err
- })
- return
- }
|