Просмотр исходного кода

feature(系统管理): 项目代码优化

ZZH-wl 3 лет назад
Родитель
Сommit
03a1cbc0b6

+ 18 - 1
opms_parent/app/handler/proj/business.go

@@ -75,7 +75,7 @@ func (p *BusinessHandler) GetBusinessDynamics(ctx context.Context, req *projMode
 	return nil
 }
 
-func (p *BusinessHandler) GetBusinessDynamicsList(ctx context.Context, req *projModel.BusinessReq, rsp *comm_def.CommonMsg) error {
+func (p *BusinessHandler) GetBusinessDynamicsList(ctx context.Context, req *projModel.BusinessDynamicsReq, rsp *comm_def.CommonMsg) error {
 	if req.BusId == 0 {
 		return myerrors.ValidError("项目参数有误!")
 	}
@@ -195,3 +195,20 @@ func (p *BusinessHandler) SetPrimacyContact(ctx context.Context, req *projModel.
 	}
 	return nil
 }
+
+// UpdateBusinessStatus 更新项目状态
+func (p *BusinessHandler) UpdateBusinessStatus(ctx context.Context, req *projModel.UpdateBusinessStatusReq, rsp *comm_def.CommonMsg) error {
+	// 参数校验
+	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
+		return myerrors.ValidError(err.Error())
+	}
+	businessService, err := projSrv.NewBusinessService(ctx)
+	if err != nil {
+		return err
+	}
+	err = businessService.UpdateBusinessStatus(req)
+	if err != nil {
+		return err
+	}
+	return nil
+}

+ 1 - 1
opms_parent/app/handler/proj/business_contact.go

@@ -13,7 +13,7 @@ import (
 
 type BusinessContactHandler struct{}
 
-func (p *BusinessContactHandler) GetList(ctx context.Context, req *projModel.BusinessReq, rsp *comm_def.CommonMsg) error {
+func (p *BusinessContactHandler) GetList(ctx context.Context, req *projModel.BusinessContactSearchReq, rsp *comm_def.CommonMsg) error {
 	if req.BusId == 0 {
 		return myerrors.ValidError("项目参数有误!")
 	}

+ 15 - 4
opms_parent/app/model/proj/proj_business.go

@@ -104,11 +104,22 @@ type BusinessPrimacyContactReq struct {
 	Remark           string `json:"remark"`                                    // 备注
 }
 
+// UpdateBusinessStatusReq 更新项目状态请求
+type UpdateBusinessStatusReq struct {
+	Id        int    `json:"id"        v:"required# id不能为空"`                              // 主键
+	NboStatus string `json:"nboStatus"        v:"required|in:10,20,30# 项目状态不能为空|项目状态不存在"` // 项目状态
+	Remark    string `json:"remark"`                                                      // 备注
+}
+
 // BusinessReq 获取项目关联信息
 type BusinessReq struct {
-	BusId    int64  `json:"busId"        v:"required# 关联项目不能为空"` // 主键
-	CuctId   int    `json:"cuctId"`                              // 客户联系人
-	CuctName string `json:"cuctName"`                            // 客户联系人姓名
-	OpnType  string `json:"opnType"`                             // 操作类型
+	BusId int64 `json:"busId"        v:"required# 关联项目不能为空"` // 主键
+	request.PageReq
+}
+
+// BusinessDynamicsReq 获取项目关联信息
+type BusinessDynamicsReq struct {
+	BusId   int64  `json:"busId"        v:"required# 关联项目不能为空"` // 主键
+	OpnType string `json:"opnType"`                             // 操作类型
 	request.PageReq
 }

+ 9 - 0
opms_parent/app/model/proj/proj_business_contact.go

@@ -6,6 +6,7 @@ package model
 
 import (
 	"dashoo.cn/micro/app/model/proj/internal"
+	"dashoo.cn/opms_libary/request"
 )
 
 // ProjBusinessContact is the golang structure for table proj_business_contact.
@@ -27,6 +28,14 @@ type BusinessContact struct {
 	Policy     int    `json:"policy"`     //是否决策
 }
 
+// BusinessContactSearchReq 获取项目关联联系人信息
+type BusinessContactSearchReq struct {
+	BusId    int64  `json:"busId"        v:"required# 关联项目不能为空"` // 主键
+	CuctId   int    `json:"cuctId"`                              // 客户联系人
+	CuctName string `json:"cuctName"`                            // 客户联系人姓名
+	request.PageReq
+}
+
 type BusinessContactReq struct {
 	BusId      int    `json:"busId"        v:"required#关联项目不能为空"`     // 关联项目
 	ContactIds []int  `json:"contactIds"        v:"required#联系人不能为空"` // 联系人主键

+ 54 - 7
opms_parent/app/service/proj/business.go

@@ -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)

+ 3 - 3
opms_parent/app/service/proj/business_contact.go

@@ -25,7 +25,7 @@ func NewBusinessContactService(ctx context.Context) (svc *businessContactService
 	return svc, nil
 }
 
-func (p *businessContactService) GetList(req *projModel.BusinessReq) (total int, contactList []*projModel.BusinessContact, err error) {
+func (p *businessContactService) GetList(req *projModel.BusinessContactSearchReq) (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 {
@@ -63,7 +63,7 @@ func (p *businessContactService) Create(req *projModel.BusinessContactReq) (err
 		// 添加项目动态
 		dynamics := projModel.ProjBusinessDynamics{
 			BusId:   req.BusId,
-			OpnType: "70",
+			OpnType: OpnAssociation,
 		}
 		err = b.CreateProjBusinessDynamics(tx, dynamics, nil)
 		return err
@@ -88,7 +88,7 @@ func (p *businessContactService) DeleteByIds(ids []int64) (err error) {
 		// 添加项目动态
 		dynamics := projModel.ProjBusinessDynamics{
 			BusId:   result.BusId,
-			OpnType: "80",
+			OpnType: OpnDisassociation,
 		}
 		err = b.CreateProjBusinessDynamics(tx, dynamics, nil)
 		return err