Selaa lähdekoodia

受理单提交

WH01243 1 vuosi sitten
vanhempi
commit
4519a1d893
1 muutettua tiedostoa jossa 236 lisäystä ja 0 poistoa
  1. 236 0
      service/acceptance.go

+ 236 - 0
service/acceptance.go

@@ -0,0 +1,236 @@
+package service
+
+import (
+	"app.yhyue.com/moapp/jybase/date"
+	"app.yhyue.com/moapp/jybase/redis"
+	. "bp.jydev.jianyu360.cn/BaseService/biService/entity"
+	"bp.jydev.jianyu360.cn/BaseService/biService/rpc/biservice"
+	"database/sql"
+	"fmt"
+	"github.com/gogf/gf/v2/util/gconv"
+	"github.com/zeromicro/go-zero/core/logx"
+	"log"
+	"strings"
+	"time"
+)
+
+func AddAcceptance(in *biservice.AcceptanceReq, DkPersonMap []map[string]interface{}, entId int64, productMap map[string]string) int64 {
+	nowTime := time.Now().Format(date.Date_Full_Layout)
+	//编号处理
+	is_clue := 1
+	acceptance_no := fmt.Sprintf("SLD%s%s", time.Now().Format(date.Date_Short_Layout), FindNumber("sld"))
+	acceptanceMap := map[string]interface{}{
+		"acceptance_no": acceptance_no,
+		"propose_type":  in.ProposeType,
+		//"propose_time":          in.ProposeTime,
+		"channel":               in.Channel,
+		"acceptance_type":       in.AcceptanceType,
+		"status":                in.Status,
+		"initiator_name":        in.EntUserName,
+		"initiator_position_id": in.PositionId,
+		"department_no":         in.DeptId,
+		"remark":                in.Remark,
+		"is_delete":             1,
+		"creator_name":          in.EntUserName,
+		"creator_position_id":   in.PositionId,
+		"creator_time":          nowTime,
+	}
+	ok := int64(0)
+	WorkOrder.ExecTx("受理单处理", func(tx *sql.Tx) bool {
+		//新增受理单子单
+		childMap := gconv.Map(in.ParamData)
+		if childMap != nil && len(childMap) > 0 {
+			innerArr := []interface{}{}
+			innerStr := []string{"acceptance_no", "field_name", "field_value", "creator_name", "creator_position_id", "creator_time"}
+			for k, v := range childMap {
+				innerArr = append(innerArr, acceptance_no)
+				innerArr = append(innerArr, k)
+				innerArr = append(innerArr, v)
+				innerArr = append(innerArr, in.EntUserName)
+				innerArr = append(innerArr, in.PositionId)
+				innerArr = append(innerArr, nowTime)
+			}
+			if len(innerArr) > 0 {
+				ok2, ok3 := WorkOrder.InsertBatchByTx(tx, "order_acceptance_children", innerStr, innerArr)
+				if ok2 <= 0 && ok3 <= 0 {
+					return false
+				}
+			}
+			//判断是否创建工单
+			dkPerson := ""
+			dkProduct := []string{}
+			dkPositionId := int64(0)
+			personMap := map[string]interface{}{}
+			if _, isOk := childMap["product"]; isOk {
+				for _, v := range strings.Split(gconv.String(childMap["product"]), ",") {
+					switch productMap[v] {
+					case "dk":
+						dkProduct = append(dkProduct, v)
+						if dkPositionId == 0 {
+							personMap = Findcandidate(DkPersonMap, entId)
+							dkPositionId = gconv.Int64(personMap["positionId"])
+						}
+						continue
+					default:
+						is_clue = 2
+					}
+
+				}
+			}
+			if dkPositionId != 0 {
+				work_order_no := fmt.Sprintf("SLD%s%s", time.Now().Format(date.Date_Short_Layout), FindNumber("gd"))
+				orderWorkMap := map[string]interface{}{
+					"work_order_no":         work_order_no,
+					"acceptance_no":         acceptance_no,
+					"type":                  strings.Join(dkProduct, ","),
+					"status":                1,
+					"initiator_name":        in.EntUserName,
+					"initiator_position_id": in.PositionId,
+					"current_name":          dkPerson,
+					"current_position_id":   dkPositionId,
+					"is_delete":             1,
+					"creator_name":          in.EntUserName,
+					"creator_position_id":   in.PositionId,
+					"creator_time":          nowTime,
+					"two_type":              "dk",
+					"department_no":         in.DeptId,
+				}
+				ok3 := WorkOrder.InsertByTx(tx, "order_work", orderWorkMap)
+				if ok3 <= 0 {
+					return false
+				}
+				//发送邮件
+				log.Println(personMap)
+
+			}
+		}
+		//先新增受理单主单
+		acceptanceMap["is_clue"] = is_clue
+		ok = WorkOrder.InsertByTx(tx, "order_acceptance", acceptanceMap)
+		if ok <= 0 {
+			logx.Info("受理单创建失败")
+			return false
+		}
+		//工单处理
+		return true
+	})
+	return ok
+
+}
+
+// 大客人员选择
+func Findcandidate(DkPersonMap []map[string]interface{}, entId int64) map[string]interface{} {
+	person := map[string]interface{}{}
+	positionArr := []string{}
+	personMap := map[string]map[string]interface{}{}
+	positionId := int64(0)
+	phoneArr := []string{}
+	for _, v := range DkPersonMap {
+		phoneArr = append(phoneArr, fmt.Sprintf(`"%s"`, gconv.String(v["phone"])))
+		personMap[gconv.String(v["phone"])] = map[string]interface{}{
+			"name": gconv.String(v["name"]),
+		}
+	}
+	//个人邮箱,部门信息获取
+	entUserArr := JyMysql.SelectBySql(fmt.Sprintf(`SELECT
+	a.name as  name,a.mail as mail,b.dept_id as  deptId,a.phone
+FROM
+	entniche_user a
+	INNER JOIN entniche_department_user b ON a.ent_id =%d
+	AND a.phone IN %s
+	and  a.id=b.user_id`, entId, fmt.Sprintf("(%s)", strings.Join(phoneArr, ","))))
+	if entUserArr != nil && len(*entUserArr) > 0 {
+		for _, v := range *entUserArr {
+			phone := gconv.String(v["phone"])
+			personMap[phone]["mail"] = gconv.String(v["mail"])
+			personMap[phone]["deptId"] = gconv.String(v["deptId"])
+		}
+	}
+	//
+	positionArrMap := JyTidb.SelectBySql(fmt.Sprintf(`select  a.phone,b.id from  
+                         base_user  a  
+                             INNER JOIN   base_position  b     
+                                 on     b.ent_id=%d  and a.phone in %s and  b.user_id=a.id and   b.type=1`,
+		entId, fmt.Sprintf("(%s)", strings.Join(phoneArr, ","))))
+	if positionArrMap != nil && len(*positionArrMap) > 0 {
+		for _, v := range *positionArrMap {
+			phone := gconv.String(v["phone"])
+			positionid := gconv.Int64(v["id"])
+			for k := range personMap {
+				if k == phone {
+					personMap[phone]["positionId"] = positionid
+					positionArr = append(positionArr, gconv.String(positionid))
+				}
+			}
+		}
+	}
+	//查询工单数量
+	positionNumberMap := WorkOrder.SelectBySql(`SELECT
+			current_position_id,
+			COUNT( 1 ) AS count 
+		FROM
+			order_work 
+		WHERE
+			current_position_id IN (?) 
+		ORDER BY
+			count`, strings.Join(positionArr, ","))
+	if positionNumberMap != nil && len(*positionNumberMap) > 0 {
+		positionId = gconv.Int64((*positionNumberMap)[0]["current_position_id"])
+	} else {
+		positionId = gconv.Int64(positionArr[0])
+	}
+	if positionId == 0 {
+		positionId = gconv.Int64(positionArr[0])
+	}
+	//商机管理员
+	deptId := int64(0)
+	for _, v := range personMap {
+		positionid := gconv.Int64(v["positionId"])
+		if positionId == positionid {
+			person = v
+			deptId = gconv.Int64(v["deptId"])
+		}
+	}
+	//本部门管理员查询
+	depthMap := JyMysql.SelectBySql(`SELECT
+		c.name as name,c.mail as  mail
+		FROM
+			entniche_department_user a
+			INNER JOIN entniche_user_role b ON a.dept_id = ? 
+			AND a.user_id = b.user_id 
+			AND b.role_id =2
+			INNER JOIN entniche_user c ON a.user_id = c.id`, deptId)
+	if depthMap != nil && len(*depthMap) > 0 {
+		person["deptPersonName"] = gconv.String((*depthMap)[0]["name"])
+		person["deptPersonMail"] = gconv.String((*depthMap)[0]["mail"])
+	}
+	//商机管理员查询
+	superiorDepthMap := JyMysql.SelectBySql(`SELECT
+	c.* 
+FROM
+	entniche_department d
+	INNER JOIN entniche_department_user a ON d.id = ? 
+	AND d.pid = a.dept_id
+	INNER JOIN entniche_user_role b ON a.user_id = b.user_id 
+	AND b.role_id = 1
+	INNER JOIN entniche_user c ON a.user_id = c.id`, deptId)
+	if superiorDepthMap != nil && len(*superiorDepthMap) > 0 {
+		person["superiorDepthPersonName"] = gconv.String((*superiorDepthMap)[0]["name"])
+		person["superiorDepthPersonMail"] = gconv.String((*superiorDepthMap)[0]["mail"])
+	}
+	return person
+}
+
+// 编号查询
+func FindNumber(moudle string) string {
+	today := time.Now().Format("2006-01-02")
+	yesterday := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
+	key := fmt.Sprintf("%s_%s", today, moudle)
+	yesterdayKey := fmt.Sprintf("%s_%s", yesterday, moudle)
+	if ok, _ := redis.Exists("newother", yesterdayKey); ok {
+		//删除之前数据
+		redis.Del("newother", yesterdayKey)
+	}
+	count := redis.Incr("newother", key)
+	return fmt.Sprintf("%04d", count)
+}