Преглед изворни кода

feature:工单改期、延期,向支持人员发送提醒

liuyaqi пре 2 година
родитељ
комит
885a312410

+ 12 - 9
opms_parent/app/model/work/work_order.go

@@ -20,15 +20,18 @@ type WorkOrderGetRsp struct {
 }
 
 type WorkOrderSearchReq struct {
-	NboId          int    `json:"nboId"`          // 主键
-	CustId         int    `json:"custId"`         // 主键
-	NboCode        string `json:"nboCode"`        // 项目编码
-	NboName        string `json:"nboName"`        // 项目名称
-	CustName       string `json:"custName"`       // 客户名称
-	Name           string `json:"name"`           //工单
-	OrderTypeName  string `json:"orderTypeName"`  //工单类型
-	OrderStatus    string `json:"orderStatus"`    //工单状态
-	AssignUserName string `json:"assignUserName"` // 分派人员姓名
+	NboId            int         `json:"nboId"`            // 主键
+	CustId           int         `json:"custId"`           // 主键
+	NboCode          string      `json:"nboCode"`          // 项目编码
+	NboName          string      `json:"nboName"`          // 项目名称
+	CustName         string      `json:"custName"`         // 客户名称
+	Name             string      `json:"name"`             //工单
+	OrderTypeName    string      `json:"orderTypeName"`    //工单类型
+	OrderStatus      string      `json:"orderStatus"`      //工单状态
+	AssignUserName   string      `json:"assignUserName"`   // 分派人员姓名
+	UpdatedTimeStart *gtime.Time `json:"updatedTimeStart"` // 更新时间
+	UpdatedTimeEnd   *gtime.Time `json:"updatedTimeEnd"`   // 更新时间
+
 	request.PageReq
 }
 type WorkOrderReq struct {

+ 51 - 28
opms_parent/app/service/work/work_order.go

@@ -100,6 +100,12 @@ func (s *OrderService) GetList(req *model.WorkOrderSearchReq) (total int, orderL
 	if req.OrderStatus != "" {
 		db = db.Where("a."+s.Dao.C.OrderStatus, req.OrderStatus)
 	}
+	if req.UpdatedTimeStart != nil {
+		db = db.Where("a.updated_time >= ?", req.UpdatedTimeStart)
+	}
+	if req.UpdatedTimeEnd != nil {
+		db = db.Where("a.updated_time <= ?", req.UpdatedTimeEnd)
+	}
 	total, err = db.Count()
 	if err != nil {
 		err = myerrors.DbError("获取总行数失败。")
@@ -376,31 +382,7 @@ func (s *OrderService) WorkOrderNotify(flow *workflowModel.PlatWorkflow, msg *me
 	}
 
 	if data[s.Dao.C.OrderStatus] == "30" {
-		recvUserIds := []int{}
-		if workOrder.AssignUserId != 0 {
-			recvUserIds = append(recvUserIds, workOrder.AssignUserId)
-		}
-		if workOrder.SaleId != 0 {
-			recvUserIds = append(recvUserIds, workOrder.SaleId)
-		}
-		recvUserIds = service.SliceIntDeduplication(recvUserIds)
-		if len(recvUserIds) != 0 {
-			recvUserIdString := []string{}
-			for _, uid := range recvUserIds {
-				recvUserIdString = append(recvUserIdString, strconv.Itoa(uid))
-			}
-			msg := g.MapStrStr{
-				"msgTitle":    "支持工单审批通过提醒",
-				"msgContent":  fmt.Sprintf("<p>工单:%s 已审批通过</p>", workOrder.Name),
-				"msgType":     "20",
-				"recvUserIds": strings.Join(recvUserIdString, ","),
-				"msgStatus":   "10",
-				"sendType":    "10",
-			}
-			if err := service.CreateSystemMessage(msg); err != nil {
-				g.Log().Error("支持工单审批通过提醒异常:%s", err)
-			}
-		}
+		s.WorkOrderSendMsg(workOrder, "支持工单审批通过提醒", fmt.Sprintf("<p>工单:%s 已审批通过</p>", workOrder.Name))
 	}
 
 	// 项目修改
@@ -411,6 +393,35 @@ func (s *OrderService) WorkOrderNotify(flow *workflowModel.PlatWorkflow, msg *me
 	return err
 }
 
+func (s *OrderService) WorkOrderSendMsg(workOrder *model.WorkOrder, title, content string) {
+	recvUserIds := []int{}
+	if workOrder.AssignUserId != 0 {
+		recvUserIds = append(recvUserIds, workOrder.AssignUserId)
+	}
+	if workOrder.SaleId != 0 {
+		recvUserIds = append(recvUserIds, workOrder.SaleId)
+	}
+	recvUserIds = service.SliceIntDeduplication(recvUserIds)
+	if len(recvUserIds) == 0 {
+		return
+	}
+	recvUserIdString := []string{}
+	for _, uid := range recvUserIds {
+		recvUserIdString = append(recvUserIdString, strconv.Itoa(uid))
+	}
+	msg := g.MapStrStr{
+		"msgTitle":    title,
+		"msgContent":  content,
+		"msgType":     "20",
+		"recvUserIds": strings.Join(recvUserIdString, ","),
+		"msgStatus":   "10",
+		"sendType":    "10",
+	}
+	if err := service.CreateSystemMessage(msg); err != nil {
+		g.Log().Error("支持工单 %s 提醒异常:%s", title, err)
+	}
+}
+
 // CreateWorkOrderFeedback 创建工单反馈
 func (s *OrderService) CreateWorkOrderFeedback(req *model.WorkOrderFeedbackReq) error {
 	data := new(model.WorkOrderFeedback)
@@ -704,7 +715,7 @@ func (s *OrderService) TimeUpdateExpect(ctx context.Context, req *model.TimeUpda
 		return myerrors.TipsError("当前工单不可修改期望完成时间")
 	}
 
-	return s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
+	txerr := s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
 		_, err = tx.Update("work_order", map[string]interface{}{
 			"expect_time":  req.ExpectTime,
 			"updated_by":   s.CxtUser.Id,
@@ -720,6 +731,10 @@ func (s *OrderService) TimeUpdateExpect(ctx context.Context, req *model.TimeUpda
 		})
 		return err
 	})
+	if txerr == nil {
+		s.WorkOrderSendMsg(ent, "支持工单改期提醒", fmt.Sprintf("<p>工单:%s 期望完成时间已修改为 %s</p>", ent.Name, req.ExpectTime))
+	}
+	return txerr
 }
 
 func (s *OrderService) TimeUpdateSupport(ctx context.Context, req *model.TimeUpdateSupportReq) error {
@@ -734,7 +749,7 @@ func (s *OrderService) TimeUpdateSupport(ctx context.Context, req *model.TimeUpd
 		return myerrors.TipsError("当前工单不可修改支持时间")
 	}
 
-	return s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
+	txerr := s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
 		_, err = tx.Update("work_order", map[string]interface{}{
 			"support_time": req.SupportTime,
 			"updated_by":   s.CxtUser.Id,
@@ -750,6 +765,10 @@ func (s *OrderService) TimeUpdateSupport(ctx context.Context, req *model.TimeUpd
 		})
 		return err
 	})
+	if txerr == nil {
+		s.WorkOrderSendMsg(ent, "支持工单改期提醒", fmt.Sprintf("<p>工单:%s 支持时间已修改为 %s</p>", ent.Name, req.SupportTime))
+	}
+	return txerr
 }
 
 func (s *OrderService) TimeUpdateTrial(ctx context.Context, req *model.TimeUpdateTrialReq) error {
@@ -778,7 +797,7 @@ func (s *OrderService) TimeUpdateTrial(ctx context.Context, req *model.TimeUpdat
 		dynamic = "延期"
 	}
 
-	return s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
+	txerr := s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
 		_, err = tx.Update("work_order", map[string]interface{}{
 			"trial_time_start": req.TrialTimeStart,
 			"trial_time_end":   req.TrialTimeEnd,
@@ -797,6 +816,10 @@ func (s *OrderService) TimeUpdateTrial(ctx context.Context, req *model.TimeUpdat
 		})
 		return err
 	})
+	if txerr == nil {
+		s.WorkOrderSendMsg(ent, fmt.Sprintf("支持工单%s提醒", dynamic), fmt.Sprintf("<p>工单:%s 试用已修改为 %s-%s</p>", ent.Name, ent.TrialTimeStart, ent.TrialTimeEnd))
+	}
+	return txerr
 }
 
 func (s *OrderService) Close(ctx context.Context, req *model.WorkOrderCloseReq) error {

+ 52 - 0
opms_parent/script/main.go

@@ -36,6 +36,58 @@ func main() {
 	// projectRelate()
 	// updateclloect()
 	// updateContractIncharge()
+	// updateDist()
+}
+
+func updateDist() {
+	// select id, nbo_name,nbo_type, distributor_id , distributor_name from proj_business where (distributor_id=0 or distributor_id is null) and distributor_name != '' and distributor_name is not null
+
+	distdao := basedao.NewBaseDistributorDao("prod")
+	dist, err := distdao.All()
+	if err != nil {
+		panic(err)
+	}
+	projao := projao.NewProjBusinessDao("prod")
+	proj, err := projao.All()
+	if err != nil {
+		panic(err)
+	}
+
+	distmap := map[string]*basemodel.BaseDistributor{}
+	for _, d := range dist {
+		distmap[d.DistName] = d
+	}
+
+	txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
+		for _, p := range proj {
+			if p.DistributorName == "" {
+				continue
+			}
+			if p.DistributorId != 0 {
+				continue
+			}
+
+			d := distmap[p.DistributorName]
+			if d == nil {
+				fmt.Println("not found", p.DistributorName)
+				continue
+			}
+			fmt.Println(p.DistributorName, d.Id, d.DistName)
+
+			_, err = tx.Update("proj_business",
+				map[string]interface{}{
+					"distributor_id": d.Id,
+				}, "id = ?", p.Id)
+			if err != nil {
+				return err
+			}
+		}
+		// return fmt.Errorf("测试")
+		return nil
+	})
+	if txerr != nil {
+		panic(txerr)
+	}
 }
 
 func updateContractIncharge() {