|
@@ -126,7 +126,7 @@ func AddOrderWork(orderType, acceptance_no, nowTime, phone, company string, tx *
|
|
|
dkdeptId := ""
|
|
|
dkPositionId := int64(0)
|
|
|
personMap := map[string]interface{}{}
|
|
|
- personMap = Findcandidate(selectPersonMap.PersonArr, entId, orderType)
|
|
|
+ personMap = FindCandidate(selectPersonMap.PersonArr, entId, orderType)
|
|
|
dkPositionId = gconv.Int64(personMap["positionId"])
|
|
|
dkPerson = gconv.String(personMap["name"])
|
|
|
dkdeptId = gconv.String(personMap["deptId"])
|
|
@@ -172,6 +172,7 @@ func AddOrderWork(orderType, acceptance_no, nowTime, phone, company string, tx *
|
|
|
"is_delete": 1,
|
|
|
"creator_time": nowTime,
|
|
|
}
|
|
|
+ log.Println(approvalRecordMap)
|
|
|
ok4 := WorkOrder.InsertByTx(tx, "approval_record", approvalRecordMap)
|
|
|
if ok4 <= 0 {
|
|
|
log.Println("工单记录保存失败")
|
|
@@ -179,38 +180,37 @@ func AddOrderWork(orderType, acceptance_no, nowTime, phone, company string, tx *
|
|
|
}
|
|
|
log.Println(personMap)
|
|
|
log.Println(GmailAuth, personMap, strings.Join(selectPersonMap.Product, ","), dkPerson, in.EntUserName, nowTime, work_order_no, phone, company)
|
|
|
- WorkMail(GmailAuth, personMap, strings.Join(selectPersonMap.Product, ","), dkPerson, in.EntUserName, nowTime, work_order_no, phone, company)
|
|
|
+ //WorkMail(GmailAuth, personMap, strings.Join(selectPersonMap.Product, ","), dkPerson, in.EntUserName, nowTime, work_order_no, phone, company)
|
|
|
}
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
// 大客人员选择
|
|
|
-func Findcandidate(personArr []Person, entId int64, orderType string) map[string]interface{} {
|
|
|
+func FindCandidate(personArr []config.Person, entId int64, orderType string) map[string]interface{} {
|
|
|
person := map[string]interface{}{}
|
|
|
- positionArr := []string{}
|
|
|
- personMap := map[string]map[string]interface{}{}
|
|
|
- positionId := int64(0)
|
|
|
- phoneArr := []string{}
|
|
|
- personNameArr := []string{}
|
|
|
- for _, v := range personArr {
|
|
|
- phoneArr = append(phoneArr, fmt.Sprintf(`"%s"`, v.Phone))
|
|
|
- personNameArr = append(personNameArr, fmt.Sprintf(`"%s"`, v.Name))
|
|
|
- personMap[gconv.String(v.Phone)] = map[string]interface{}{
|
|
|
+ personEntity := config.Person{}
|
|
|
+ personMap := make(map[string]map[string]interface{})
|
|
|
+ phoneArr := make([]string, len(personArr))
|
|
|
+
|
|
|
+ // Populate phoneArr and personMap
|
|
|
+ for k, v := range personArr {
|
|
|
+ phone := gconv.String(v.Phone)
|
|
|
+ phoneArr[k] = fmt.Sprintf(`"%s"`, phone)
|
|
|
+ personMap[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,c.name as deptName
|
|
|
-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
|
|
|
- inner join entniche_department c on b.dept_id=c.id
|
|
|
-`, entId, fmt.Sprintf("(%s)", strings.Join(phoneArr, ","))))
|
|
|
- if entUserArr != nil && len(*entUserArr) > 0 {
|
|
|
+
|
|
|
+ // Fetch personal email and department information
|
|
|
+ entUserArr := config.JianyuMysql.SelectBySql(fmt.Sprintf(`
|
|
|
+ SELECT a.name, a.mail, b.dept_id AS deptId, a.phone, c.name AS deptName
|
|
|
+ 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
|
|
|
+ INNER JOIN entniche_department c ON b.dept_id = c.id
|
|
|
+ `, entId, fmt.Sprintf("(%s)", strings.Join(phoneArr, ","))))
|
|
|
+
|
|
|
+ if entUserArr != nil {
|
|
|
for _, v := range *entUserArr {
|
|
|
phone := gconv.String(v["phone"])
|
|
|
personMap[phone]["mail"] = gconv.String(v["mail"])
|
|
@@ -218,94 +218,117 @@ FROM
|
|
|
personMap[phone]["deptName"] = gconv.String(v["deptName"])
|
|
|
}
|
|
|
}
|
|
|
- //
|
|
|
- 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 {
|
|
|
+
|
|
|
+ // Fetch position information
|
|
|
+ positionArrMap := config.JianyuMysql.SelectBySql(fmt.Sprintf(`
|
|
|
+ SELECT a.phone, b.id
|
|
|
+ FROM base_service.base_user a
|
|
|
+ INNER JOIN base_service.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 {
|
|
|
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))
|
|
|
- }
|
|
|
- }
|
|
|
+ personMap[phone]["positionId"] = gconv.Int64(v["id"])
|
|
|
}
|
|
|
}
|
|
|
- //查询工单数量
|
|
|
- positionNumberMap := WorkOrder.SelectBySql(`SELECT
|
|
|
- current_position_id,
|
|
|
- COUNT( 1 ) AS count
|
|
|
- FROM
|
|
|
- order_work
|
|
|
- WHERE
|
|
|
- FIND_IN_SET(current_position_id , ?) and two_type=?
|
|
|
- GROUP BY current_position_id
|
|
|
- ORDER BY
|
|
|
- count ,FIELD(current_name,?) asc `, strings.Join(positionArr, ","), orderType, strings.Join(personNameArr, ","))
|
|
|
- if positionNumberMap != nil && len(*positionNumberMap) == len(personArr) {
|
|
|
- positionId = gconv.Int64((*positionNumberMap)[0]["current_position_id"])
|
|
|
- } else if positionNumberMap != nil && len(*positionNumberMap) != len(personArr) {
|
|
|
- for _, v := range positionArr {
|
|
|
- count := int64(0)
|
|
|
- for _, v1 := range *positionNumberMap {
|
|
|
- id := gconv.String(v1["current_position_id"])
|
|
|
- if id == v {
|
|
|
- count = gconv.Int64(v1["count"])
|
|
|
- }
|
|
|
- }
|
|
|
- if count == 0 {
|
|
|
- positionId = gconv.Int64(v)
|
|
|
- break
|
|
|
- }
|
|
|
+
|
|
|
+ // Update personArr with additional information
|
|
|
+ for k, v := range personArr {
|
|
|
+ phone := v.Phone
|
|
|
+ if info, exists := personMap[phone]; exists {
|
|
|
+ personArr[k].Mail = gconv.String(info["mail"])
|
|
|
+ personArr[k].DeptId = gconv.Int64(info["deptId"])
|
|
|
+ personArr[k].DeptName = gconv.String(info["deptName"])
|
|
|
+ personArr[k].PositionId = gconv.String(info["positionId"])
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ // Query the last person who created an order
|
|
|
+ orderWorkMap := config.OrderMysql.SelectBySql(fmt.Sprintf(`
|
|
|
+ SELECT * FROM order_work WHERE two_type = "%s" ORDER BY creator_time DESC LIMIT 1
|
|
|
+ `, orderType))
|
|
|
+
|
|
|
+ var k int
|
|
|
+ if orderWorkMap == nil || len(*orderWorkMap) == 0 {
|
|
|
+ k = findNextPersonIndex(personArr, 0)
|
|
|
} else {
|
|
|
- positionId = gconv.Int64(positionArr[0])
|
|
|
+ currentName := gconv.String((*orderWorkMap)[0]["current_name"])
|
|
|
+ k = findPersonIndexByName(personArr, currentName)
|
|
|
+ k = findNextPersonIndex(personArr, k)
|
|
|
+ }
|
|
|
+
|
|
|
+ personEntity = personArr[k]
|
|
|
+
|
|
|
+ // Set person details
|
|
|
+ person["positionId"] = personEntity.PositionId
|
|
|
+ person["deptName"] = personEntity.DeptName
|
|
|
+ person["deptId"] = personEntity.DeptId
|
|
|
+ person["name"] = personEntity.Name
|
|
|
+
|
|
|
+ // Fetch department admin
|
|
|
+ fetchDeptAdmin(person, personEntity.DeptId)
|
|
|
+
|
|
|
+ // Fetch superior admin
|
|
|
+ fetchSuperiorAdmin(person, personEntity.DeptId)
|
|
|
+
|
|
|
+ return person
|
|
|
+}
|
|
|
+
|
|
|
+// Helper function to find the next person index
|
|
|
+func findNextPersonIndex(personArr []config.Person, startIndex int) int {
|
|
|
+ n := len(personArr)
|
|
|
+ // 如果当前索引是最后一个,则从 0 开始
|
|
|
+ if startIndex >= n-1 {
|
|
|
+ startIndex = -1 // 设置为 -1 以便在下次循环中变为 0
|
|
|
}
|
|
|
- if positionId == 0 {
|
|
|
- positionId = gconv.Int64(positionArr[0])
|
|
|
+ for count := 0; count < n; count++ { // 限制最大循环次数
|
|
|
+ startIndex++ // 先加 1
|
|
|
+ if startIndex >= n {
|
|
|
+ startIndex = 0 // 如果超出范围,则重置为 0
|
|
|
+ }
|
|
|
+ if !personArr[startIndex].IsResign {
|
|
|
+ return startIndex // 找到未辞职的员工,返回索引
|
|
|
+ }
|
|
|
}
|
|
|
- //商机管理员
|
|
|
- deptId := int64(0)
|
|
|
- for _, v := range personMap {
|
|
|
- positionid := gconv.Int64(v["positionId"])
|
|
|
- if positionId == positionid {
|
|
|
- person = v
|
|
|
- deptId = gconv.Int64(v["deptId"])
|
|
|
+ return 0 // 如果没有找到,返回 -1
|
|
|
+}
|
|
|
+
|
|
|
+// Helper function to find a person's index by name
|
|
|
+func findPersonIndexByName(personArr []config.Person, name string) int {
|
|
|
+ for i, v := range personArr {
|
|
|
+ if v.Name == name {
|
|
|
+ return i
|
|
|
}
|
|
|
}
|
|
|
- //本部门管理员查询
|
|
|
- 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 !=""
|
|
|
- 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"])
|
|
|
+ return 0 // Default to the first index if not found
|
|
|
+}
|
|
|
+
|
|
|
+// Fetch department admin details
|
|
|
+func fetchDeptAdmin(person map[string]interface{}, deptId int64) {
|
|
|
+ deptMap := config.JianyuMysql.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 != ""
|
|
|
+ INNER JOIN entniche_user c ON a.user_id = c.id`, deptId)
|
|
|
+
|
|
|
+ if deptMap != nil && len(*deptMap) > 0 {
|
|
|
+ person["deptPersonName"] = gconv.String((*deptMap)[0]["name"])
|
|
|
+ person["deptPersonMail"] = gconv.String((*deptMap)[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 !=""
|
|
|
- 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"])
|
|
|
+}
|
|
|
+
|
|
|
+// Fetch superior admin details
|
|
|
+func fetchSuperiorAdmin(person map[string]interface{}, deptId int64) {
|
|
|
+ superiorMap := config.JianyuMysql.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 != ""
|
|
|
+ INNER JOIN entniche_user c ON a.user_id = c.id`, deptId)
|
|
|
+
|
|
|
+ if superiorMap != nil && len(*superiorMap) > 0 {
|
|
|
+ person["superiorDepthPersonName"] = gconv.String((*superiorMap)[0]["name"])
|
|
|
+ person["superiorDepthPersonMail"] = gconv.String((*superiorMap)[0]["mail"])
|
|
|
}
|
|
|
- return person
|
|
|
}
|
|
|
|
|
|
// 编号查询
|