|
@@ -23,7 +23,9 @@ type ctrContractEventService struct {
|
|
|
ContractDao *contractdao.CtrContractDao
|
|
ContractDao *contractdao.CtrContractDao
|
|
|
DeliveryEventDao *opsdevdao.OpsDeliveryProjectEventDao
|
|
DeliveryEventDao *opsdevdao.OpsDeliveryProjectEventDao
|
|
|
DeliveryProjectDao *opsdevdao.OpsDeliveryProjectDao
|
|
DeliveryProjectDao *opsdevdao.OpsDeliveryProjectDao
|
|
|
|
|
+ DeliveryRecordDao *opsdevdao.OpsDeliveryProjectEventRecordDao
|
|
|
OperationDao *opsdevdao.OpsOperationEventDao
|
|
OperationDao *opsdevdao.OpsOperationEventDao
|
|
|
|
|
+ OperationRecordDao *opsdevdao.OpsOperationEventRecordDao
|
|
|
DeliveryAttachmentDao *opsdevdao.OpsDeliveryProjectEventAttachmentDao
|
|
DeliveryAttachmentDao *opsdevdao.OpsDeliveryProjectEventAttachmentDao
|
|
|
OperationAttachmentDao *opsdevdao.OpsOperationEventAttachmentDao
|
|
OperationAttachmentDao *opsdevdao.OpsOperationEventAttachmentDao
|
|
|
}
|
|
}
|
|
@@ -38,12 +40,50 @@ func NewCtrContractEventService(ctx context.Context) (*ctrContractEventService,
|
|
|
svc.ContractDao = contractdao.NewCtrContractDao(svc.Tenant)
|
|
svc.ContractDao = contractdao.NewCtrContractDao(svc.Tenant)
|
|
|
svc.DeliveryEventDao = opsdevdao.NewOpsDeliveryProjectEventDao(svc.Tenant)
|
|
svc.DeliveryEventDao = opsdevdao.NewOpsDeliveryProjectEventDao(svc.Tenant)
|
|
|
svc.DeliveryProjectDao = opsdevdao.NewOpsDeliveryProjectDao(svc.Tenant)
|
|
svc.DeliveryProjectDao = opsdevdao.NewOpsDeliveryProjectDao(svc.Tenant)
|
|
|
|
|
+ svc.DeliveryRecordDao = opsdevdao.NewOpsDeliveryProjectEventRecordDao(svc.Tenant)
|
|
|
svc.OperationDao = opsdevdao.NewOpsOperationEventDao(svc.Tenant)
|
|
svc.OperationDao = opsdevdao.NewOpsOperationEventDao(svc.Tenant)
|
|
|
|
|
+ svc.OperationRecordDao = opsdevdao.NewOpsOperationEventRecordDao(svc.Tenant)
|
|
|
svc.DeliveryAttachmentDao = opsdevdao.NewOpsDeliveryProjectEventAttachmentDao(svc.Tenant)
|
|
svc.DeliveryAttachmentDao = opsdevdao.NewOpsDeliveryProjectEventAttachmentDao(svc.Tenant)
|
|
|
svc.OperationAttachmentDao = opsdevdao.NewOpsOperationEventAttachmentDao(svc.Tenant)
|
|
svc.OperationAttachmentDao = opsdevdao.NewOpsOperationEventAttachmentDao(svc.Tenant)
|
|
|
return svc, nil
|
|
return svc, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// buildContractEventPermissionWhere 构建合同事件查询权限条件
|
|
|
|
|
+// 仅能查看自己有权限的合同的事件信息
|
|
|
|
|
+func (s *ctrContractEventService) buildContractEventPermissionWhere() string {
|
|
|
|
|
+ if s.CxtUser == nil {
|
|
|
|
|
+ return ""
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ allVisibleRoles := []string{
|
|
|
|
|
+ "SalesDirector",
|
|
|
|
|
+ "GeneralManager",
|
|
|
|
|
+ "ResearchAndDevelopmentDirector",
|
|
|
|
|
+ "ResearchAndDevelopmentSupervisor",
|
|
|
|
|
+ "PersonnelDirector",
|
|
|
|
|
+ "SysAdmin",
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for _, role := range allVisibleRoles {
|
|
|
|
|
+ if service.StringsContains(s.CxtUser.Roles, role) {
|
|
|
|
|
+ return ""
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ where := "(1=0"
|
|
|
|
|
+
|
|
|
|
|
+ if service.StringsContains(s.CxtUser.Roles, "RegionalManager") {
|
|
|
|
|
+ where += fmt.Sprintf(" OR EXISTS (SELECT 1 FROM base_region_auth WHERE user_id = %d AND deleted_time IS NULL AND city_id = cc.cust_city_id)", s.CxtUser.Id)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if service.StringsContains(s.CxtUser.Roles, "SalesEngineer") {
|
|
|
|
|
+ where += fmt.Sprintf(" OR a.incharge_id = %d", s.CxtUser.Id)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ where += ")"
|
|
|
|
|
+ return where
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func (s *ctrContractEventService) GetProjectByContractId(req *contractmodel.CtrContractEventGetProjectReq) (*contractmodel.CtrContractEventProjectRsp, error) {
|
|
func (s *ctrContractEventService) GetProjectByContractId(req *contractmodel.CtrContractEventGetProjectReq) (*contractmodel.CtrContractEventProjectRsp, error) {
|
|
|
rsp := &contractmodel.CtrContractEventProjectRsp{}
|
|
rsp := &contractmodel.CtrContractEventProjectRsp{}
|
|
|
type projectRow struct {
|
|
type projectRow struct {
|
|
@@ -131,11 +171,17 @@ func (s *ctrContractEventService) CreateProjectForContract(req *contractmodel.Ct
|
|
|
|
|
|
|
|
func (s *ctrContractEventService) GetList(req *contractmodel.CtrContractEventSearchReq) (total int, list []*contractmodel.CtrContractEventRsp, err error) {
|
|
func (s *ctrContractEventService) GetList(req *contractmodel.CtrContractEventSearchReq) (total int, list []*contractmodel.CtrContractEventRsp, err error) {
|
|
|
baseQuery := s.Dao.DB.Model("ctr_contract_event a").
|
|
baseQuery := s.Dao.DB.Model("ctr_contract_event a").
|
|
|
|
|
+ LeftJoin("ctr_contract cc", "a.contract_id = cc.id AND cc.deleted_time IS NULL").
|
|
|
LeftJoin("ops_delivery_project_event b", "a.event_type='10' AND a.event_id = b.id AND b.deleted_time IS NULL").
|
|
LeftJoin("ops_delivery_project_event b", "a.event_type='10' AND a.event_id = b.id AND b.deleted_time IS NULL").
|
|
|
LeftJoin("ops_operation_event c", "a.event_type='20' AND a.event_id = c.id AND c.deleted_time IS NULL").
|
|
LeftJoin("ops_operation_event c", "a.event_type='20' AND a.event_id = c.id AND c.deleted_time IS NULL").
|
|
|
Unscoped().
|
|
Unscoped().
|
|
|
Where("a.deleted_time IS NULL")
|
|
Where("a.deleted_time IS NULL")
|
|
|
|
|
|
|
|
|
|
+ permissionWhere := s.buildContractEventPermissionWhere()
|
|
|
|
|
+ if permissionWhere != "" {
|
|
|
|
|
+ baseQuery = baseQuery.Where(permissionWhere)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if req.ContractId != 0 {
|
|
if req.ContractId != 0 {
|
|
|
baseQuery = baseQuery.Where("a.contract_id = ?", req.ContractId)
|
|
baseQuery = baseQuery.Where("a.contract_id = ?", req.ContractId)
|
|
|
}
|
|
}
|
|
@@ -231,8 +277,8 @@ func (s *ctrContractEventService) Create(req *contractmodel.CtrContractEventAddR
|
|
|
"cust_name": req.CustName,
|
|
"cust_name": req.CustName,
|
|
|
"product_line": req.ProductLine,
|
|
"product_line": req.ProductLine,
|
|
|
"is_big": req.IsBig,
|
|
"is_big": req.IsBig,
|
|
|
- "incharge_id": req.InchargeId,
|
|
|
|
|
- "incharge_name": req.InchargeName,
|
|
|
|
|
|
|
+ "incharge_id": s.GetCxtUserId(),
|
|
|
|
|
+ "incharge_name": s.GetCxtUserName(),
|
|
|
"remark": req.Remark,
|
|
"remark": req.Remark,
|
|
|
}
|
|
}
|
|
|
service.SetCreatedInfo(linkData, s.GetCxtUserId(), s.GetCxtUserName())
|
|
service.SetCreatedInfo(linkData, s.GetCxtUserId(), s.GetCxtUserName())
|
|
@@ -247,6 +293,19 @@ func (s *ctrContractEventService) Create(req *contractmodel.CtrContractEventAddR
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (s *ctrContractEventService) createOperationEvent(tx *gdb.TX, req *contractmodel.CtrContractEventAddReq) (int64, string, error) {
|
|
func (s *ctrContractEventService) createOperationEvent(tx *gdb.TX, req *contractmodel.CtrContractEventAddReq) (int64, string, error) {
|
|
|
|
|
+ var project opsdevmodel.OpsDeliveryProject
|
|
|
|
|
+ err := s.DeliveryProjectDao.
|
|
|
|
|
+ TX(tx).
|
|
|
|
|
+ Fields(s.DeliveryProjectDao.Columns.Attribute4, s.DeliveryProjectDao.Columns.Attribute3).
|
|
|
|
|
+ Where("contract_id = ? AND deleted_time IS NULL", req.ContractId).
|
|
|
|
|
+ OrderDesc(s.DeliveryProjectDao.Columns.Id).
|
|
|
|
|
+ Limit(1).
|
|
|
|
|
+ Scan(&project)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ g.Log().Error(err)
|
|
|
|
|
+ return 0, "", myerrors.DbError("查询交付项目失败")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
data := g.Map{
|
|
data := g.Map{
|
|
|
"event_title": req.EventTitle,
|
|
"event_title": req.EventTitle,
|
|
|
"event_desc": req.EventDesc,
|
|
"event_desc": req.EventDesc,
|
|
@@ -261,11 +320,17 @@ func (s *ctrContractEventService) createOperationEvent(tx *gdb.TX, req *contract
|
|
|
"is_ops": "10",
|
|
"is_ops": "10",
|
|
|
"feedback_reporter": req.FeedbackReporter,
|
|
"feedback_reporter": req.FeedbackReporter,
|
|
|
"feedback_source": req.FeedbackSource,
|
|
"feedback_source": req.FeedbackSource,
|
|
|
- "event_status": opsdevmodel.EventStatusProcessing,
|
|
|
|
|
"event_no": generateOperationEventNo(),
|
|
"event_no": generateOperationEventNo(),
|
|
|
- "ops_user_id": s.GetCxtUserId(),
|
|
|
|
|
- "ops_user_name": s.GetCxtUserName(),
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if project.Attribute4 > 0 {
|
|
|
|
|
+ data["event_status"] = opsdevmodel.EventStatusProcessing
|
|
|
|
|
+ data["ops_user_id"] = int(project.Attribute4)
|
|
|
|
|
+ data["ops_user_name"] = project.Attribute3
|
|
|
|
|
+ } else {
|
|
|
|
|
+ data["event_status"] = opsdevmodel.EventStatusPending
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if req.FeedbackDate == "" {
|
|
if req.FeedbackDate == "" {
|
|
|
data["feedback_date"] = gtime.Now()
|
|
data["feedback_date"] = gtime.Now()
|
|
|
} else {
|
|
} else {
|
|
@@ -300,7 +365,11 @@ func (s *ctrContractEventService) createDeliveryEvent(tx *gdb.TX, req *contractm
|
|
|
var project opsdevmodel.OpsDeliveryProject
|
|
var project opsdevmodel.OpsDeliveryProject
|
|
|
err := s.DeliveryProjectDao.
|
|
err := s.DeliveryProjectDao.
|
|
|
TX(tx).
|
|
TX(tx).
|
|
|
- Fields(s.DeliveryProjectDao.Columns.Id).
|
|
|
|
|
|
|
+ Fields(
|
|
|
|
|
+ s.DeliveryProjectDao.Columns.Id,
|
|
|
|
|
+ s.DeliveryProjectDao.Columns.DeliveryUserId,
|
|
|
|
|
+ s.DeliveryProjectDao.Columns.DeliveryUserName,
|
|
|
|
|
+ ).
|
|
|
Where("contract_id = ? AND deleted_time IS NULL", req.ContractId).
|
|
Where("contract_id = ? AND deleted_time IS NULL", req.ContractId).
|
|
|
OrderDesc(s.DeliveryProjectDao.Columns.Id).
|
|
OrderDesc(s.DeliveryProjectDao.Columns.Id).
|
|
|
Limit(1).
|
|
Limit(1).
|
|
@@ -322,8 +391,14 @@ func (s *ctrContractEventService) createDeliveryEvent(tx *gdb.TX, req *contractm
|
|
|
"feedback_source": req.FeedbackSource,
|
|
"feedback_source": req.FeedbackSource,
|
|
|
"delivery_event_status": opsdevmodel.DeliveryEventStatusProcessing,
|
|
"delivery_event_status": opsdevmodel.DeliveryEventStatusProcessing,
|
|
|
"delivery_event_no": generateDeliveryEventNo(),
|
|
"delivery_event_no": generateDeliveryEventNo(),
|
|
|
- "ops_user_id": s.GetCxtUserId(),
|
|
|
|
|
- "ops_user_name": s.GetCxtUserName(),
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if project.DeliveryUserId > 0 {
|
|
|
|
|
+ data["ops_user_id"] = project.DeliveryUserId
|
|
|
|
|
+ data["ops_user_name"] = project.DeliveryUserName
|
|
|
|
|
+ } else {
|
|
|
|
|
+ data["ops_user_id"] = s.GetCxtUserId()
|
|
|
|
|
+ data["ops_user_name"] = s.GetCxtUserName()
|
|
|
}
|
|
}
|
|
|
if req.FeedbackDate == "" {
|
|
if req.FeedbackDate == "" {
|
|
|
data["feedback_date"] = gtime.Now()
|
|
data["feedback_date"] = gtime.Now()
|
|
@@ -412,6 +487,20 @@ func (s *ctrContractEventService) cancelDeliveryEvent(req *contractmodel.CtrCont
|
|
|
g.Log().Error(err)
|
|
g.Log().Error(err)
|
|
|
return myerrors.DbError("作废交付事件失败")
|
|
return myerrors.DbError("作废交付事件失败")
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ recordData := g.Map{
|
|
|
|
|
+ "delivery_event_id": req.EventId,
|
|
|
|
|
+ "handle_user_id": s.GetCxtUserId(),
|
|
|
|
|
+ "handle_user_name": s.GetCxtUserName(),
|
|
|
|
|
+ "handle_content": "作废事件:" + req.CancelReason,
|
|
|
|
|
+ }
|
|
|
|
|
+ service.SetCreatedInfo(recordData, s.GetCxtUserId(), s.GetCxtUserName())
|
|
|
|
|
+ _, err = s.DeliveryRecordDao.TX(tx).Data(recordData).Insert()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ g.Log().Error(err)
|
|
|
|
|
+ return myerrors.DbError("记录交付事件作废过程失败")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return nil
|
|
return nil
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
@@ -430,16 +519,34 @@ func (s *ctrContractEventService) cancelOperationEvent(req *contractmodel.CtrCon
|
|
|
return myerrors.TipsError("已关闭的事件不能作废")
|
|
return myerrors.TipsError("已关闭的事件不能作废")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- data := g.Map{
|
|
|
|
|
- s.OperationDao.Columns.EventStatus: opsdevmodel.EventStatusClosed,
|
|
|
|
|
- s.OperationDao.Columns.Remark: req.CancelReason,
|
|
|
|
|
- }
|
|
|
|
|
- service.SetUpdatedInfo(data, s.GetCxtUserId(), s.GetCxtUserName())
|
|
|
|
|
|
|
+ return s.OperationDao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
|
|
|
|
|
+ data := g.Map{
|
|
|
|
|
+ s.OperationDao.Columns.EventStatus: opsdevmodel.EventStatusClosed,
|
|
|
|
|
+ s.OperationDao.Columns.Remark: req.CancelReason,
|
|
|
|
|
+ }
|
|
|
|
|
+ service.SetUpdatedInfo(data, s.GetCxtUserId(), s.GetCxtUserName())
|
|
|
|
|
|
|
|
- _, err = s.OperationDao.FieldsEx(service.UpdateFieldEx...).Data(data).WherePri(req.EventId).Update()
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- g.Log().Error(err)
|
|
|
|
|
- return myerrors.DbError("作废运维事件失败")
|
|
|
|
|
- }
|
|
|
|
|
- return nil
|
|
|
|
|
|
|
+ _, err := s.OperationDao.TX(tx).FieldsEx(service.UpdateFieldEx...).Data(data).WherePri(req.EventId).Update()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ g.Log().Error(err)
|
|
|
|
|
+ return myerrors.DbError("作废运维事件失败")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ recordData := g.Map{
|
|
|
|
|
+ "event_id": req.EventId,
|
|
|
|
|
+ "handle_user_id": s.GetCxtUserId(),
|
|
|
|
|
+ "handle_user_name": s.GetCxtUserName(),
|
|
|
|
|
+ "handle_content": "作废事件:" + req.CancelReason,
|
|
|
|
|
+ "operate_type": "90",
|
|
|
|
|
+ "handle_date": gtime.Now(),
|
|
|
|
|
+ }
|
|
|
|
|
+ service.SetCreatedInfo(recordData, s.GetCxtUserId(), s.GetCxtUserName())
|
|
|
|
|
+ _, err = s.OperationRecordDao.TX(tx).Data(recordData).Insert()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ g.Log().Error(err)
|
|
|
|
|
+ return myerrors.DbError("记录运维事件作废过程失败")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return nil
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|