|
|
@@ -15,6 +15,18 @@ import (
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
+const (
|
|
|
+ OpnCreate = "10" // 创建动态
|
|
|
+ OpnUpdate = "20" // 更新动态
|
|
|
+ OpnTransfer = "30" // 转移动态
|
|
|
+ OpnRise = "40" // 升级动态
|
|
|
+ OpnDrop = "50" // 降级动态
|
|
|
+ OpnPrimacyContact = "60" // 设置首要联系人动态
|
|
|
+ OpnStatus = "70" // 更新项目状态动态
|
|
|
+ OpnAssociation = "80" // 关联联系人动态
|
|
|
+ OpnDisassociation = "90" // 解除关联联系人动态
|
|
|
+)
|
|
|
+
|
|
|
type businessService struct {
|
|
|
*service.ContextService
|
|
|
Dao *projDao.ProjBusinessDao
|
|
|
@@ -104,7 +116,7 @@ func (p *businessService) GetBusinessDynamics(req *model.BusinessReq) (total int
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func (p *businessService) GetBusinessDynamicsList(req *model.BusinessReq) (total int, list []map[string]interface{}, err error) {
|
|
|
+func (p *businessService) GetBusinessDynamicsList(req *model.BusinessDynamicsReq) (total int, list []map[string]interface{}, err error) {
|
|
|
dynamicsDao := projDao.NewProjBusinessDynamicsDao(p.Tenant).ProjBusinessDynamicsDao.Where(projDao.ProjBusinessDynamics.Columns.BusId, req.BusId)
|
|
|
if req.OpnType != "" {
|
|
|
dynamicsDao = dynamicsDao.Where(projDao.ProjBusinessDynamics.Columns.OpnType+" = ?", req.OpnType)
|
|
|
@@ -176,7 +188,7 @@ func (p *businessService) Create(req *model.AddProjBusinessReq) (err error) {
|
|
|
// 添加项目动态
|
|
|
dynamics := model.ProjBusinessDynamics{
|
|
|
BusId: int(lastId),
|
|
|
- OpnType: "10",
|
|
|
+ OpnType: OpnCreate,
|
|
|
Remark: businessData.Remark,
|
|
|
}
|
|
|
err = p.CreateProjBusinessDynamics(tx, dynamics, businessData)
|
|
|
@@ -230,7 +242,7 @@ func (p *businessService) UpdateById(req *model.UpdateProjBusinessReq) error {
|
|
|
// 添加项目动态
|
|
|
dynamics := model.ProjBusinessDynamics{
|
|
|
BusId: req.Id,
|
|
|
- OpnType: "20",
|
|
|
+ OpnType: OpnUpdate,
|
|
|
Remark: req.Remark,
|
|
|
}
|
|
|
err = p.CreateProjBusinessDynamics(tx, dynamics, req)
|
|
|
@@ -272,7 +284,7 @@ func (p *businessService) BusinessTransfer(req *model.BusinessTransferReq) error
|
|
|
// 添加项目动态
|
|
|
dynamics := model.ProjBusinessDynamics{
|
|
|
BusId: req.Id,
|
|
|
- OpnType: "30",
|
|
|
+ OpnType: OpnTransfer,
|
|
|
Remark: req.Remark,
|
|
|
}
|
|
|
err = p.CreateProjBusinessDynamics(tx, dynamics, opnContent)
|
|
|
@@ -293,10 +305,10 @@ func (p *businessService) BusinessGradation(req *model.BusinessGradationReq) err
|
|
|
if business.NboType == req.NboType {
|
|
|
return myerrors.TipsError("同级无法进行调级。")
|
|
|
}
|
|
|
- opnType := "40"
|
|
|
+ opnType := OpnRise
|
|
|
// A < B return -1 项目降级
|
|
|
if strings.Compare(business.NboType, req.NboType) < 0 {
|
|
|
- opnType = "50"
|
|
|
+ opnType = OpnDrop
|
|
|
}
|
|
|
|
|
|
businessMap := g.Map{
|
|
|
@@ -355,7 +367,42 @@ func (p *businessService) SetPrimacyContact(req *model.BusinessPrimacyContactReq
|
|
|
// 添加项目动态
|
|
|
dynamics := model.ProjBusinessDynamics{
|
|
|
BusId: req.Id,
|
|
|
- OpnType: "60",
|
|
|
+ OpnType: OpnPrimacyContact,
|
|
|
+ Remark: req.Remark,
|
|
|
+ }
|
|
|
+ err = p.CreateProjBusinessDynamics(tx, dynamics, opnContent)
|
|
|
+ return err
|
|
|
+ })
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+// UpdateBusinessStatus 更新项目状态
|
|
|
+func (p *businessService) UpdateBusinessStatus(req *model.UpdateBusinessStatusReq) error {
|
|
|
+ business, err := p.Dao.WherePri(req.Id).One()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if business == nil {
|
|
|
+ return myerrors.TipsError("项目不存在。")
|
|
|
+ }
|
|
|
+ businessMap := g.Map{
|
|
|
+ p.Dao.Columns.NboStatus: req.NboStatus,
|
|
|
+ p.Dao.Columns.Remark: req.Remark,
|
|
|
+ }
|
|
|
+ service.SetUpdatedInfo(businessMap, p.GetCxtUserId(), p.GetCxtUserName())
|
|
|
+
|
|
|
+ opnContent := businessMap
|
|
|
+ opnContent["origNboStatus"] = business.NboStatus
|
|
|
+ err = p.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
|
|
|
+ // 更新项目
|
|
|
+ _, err = p.Dao.TX(tx).WherePri(projDao.ProjBusiness.Columns.Id, req.Id).Data(businessMap).Update()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ // 添加项目动态
|
|
|
+ dynamics := model.ProjBusinessDynamics{
|
|
|
+ BusId: req.Id,
|
|
|
+ OpnType: OpnStatus,
|
|
|
Remark: req.Remark,
|
|
|
}
|
|
|
err = p.CreateProjBusinessDynamics(tx, dynamics, opnContent)
|