应用集成平台服务端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

297 lines
8.2 KiB

package rongXinPage
import (
"appPlatform/models/modelshr"
personalitycolor "appPlatform/models/personalityColor"
"appPlatform/overall"
"appPlatform/overall/publicmethod"
"encoding/json"
"fmt"
"sort"
"strconv"
"strings"
)
/*
*
@ 作者: 秦东
@ 时间: 2024-12-12 10:07:32
@ 功能: TallDisc测试
*/
func TallDiscCaput(user modelshr.PersonArchives) string {
var cesiJieguo []string
var colorInfo personalitycolor.Charcolortest
colorInfo.GetCont(map[string]interface{}{"`c_states`": 1, "`c_number`": user.Number, "`c_class`": 10000002}, "`c_test_json`")
if colorInfo.TestJson != "" {
var testPage JieShouDaan
json.Unmarshal([]byte(colorInfo.TestJson), &testPage)
d := 0
i := 0
s := 0
cVal := 0
for _, v := range testPage.List {
switch v.Pick {
case "D":
d++
case "I":
i++
case "S":
s++
case "C":
cVal++
default:
}
}
// disc := []string{"支配型", "影响型", "稳定型", "服从型"}
discVal := []int{d, i, s, cVal}
maxVal := 0
for _, mv := range discVal {
if maxVal <= mv {
maxVal = mv
}
}
if d == maxVal {
cesiJieguo = append(cesiJieguo, "支配型")
}
if i == maxVal {
cesiJieguo = append(cesiJieguo, "影响型")
}
if s == maxVal {
cesiJieguo = append(cesiJieguo, "稳定型")
}
if cVal == maxVal {
cesiJieguo = append(cesiJieguo, "服从型")
}
}
return strings.Join(cesiJieguo, ",")
}
/*
*
@ 作者: 秦东
@ 时间: 2024-12-12 09:20:36
@ 功能: 计算九型人格
*/
func TallyNineCaput(user modelshr.PersonArchives) []string {
var xgAry personalitycolor.Charcolortest
overall.CONSTANT_DB_Color.Model(&personalitycolor.Charcolortest{}).Where("`c_states` = 1 AND `c_class` = ? AND `c_number` = ?", 10000003, user.Number).First(&xgAry)
var jieguo []string
if xgAry.TestJson != "" {
var testPage JieShouDaaning
err := json.Unmarshal([]byte(xgAry.TestJson), &testPage)
if err == nil {
scoreForEachItem := CalculateScoresForEachItem(testPage)
sort.Slice(scoreForEachItem, func(i, j int) bool {
return scoreForEachItem[i].Value > scoreForEachItem[j].Value
})
for i, v := range scoreForEachItem {
if i < 4 {
jieguo = append(jieguo, v.Attribute)
}
}
}
}
return jieguo
}
/*
*
@ 作者: 秦东
@ 时间: 2024-12-12 09:48:23
@ 功能: 计算性格色彩
*/
func TallyColor(user modelshr.PersonArchives) string {
var colorMax []string
var myColor personalitycolor.Charcolortest
err := myColor.GetCont(map[string]interface{}{"`c_states`": 1, "`c_class`": 10000001, "`c_number`": user.Number})
if err != nil {
return strings.Join(colorMax, ",")
}
GetColorVal := make(map[string]int)
if myColor.TestJson != "" {
var testPage []TestPageColor
errJson := json.Unmarshal([]byte(myColor.TestJson), &testPage)
if errJson != nil {
var testPageStr []TestPageColorStr
json.Unmarshal([]byte(myColor.TestJson), &testPageStr)
GetColorVal = JiSuanColorStr(testPageStr)
} else {
GetColorVal = JiSuanColor(testPage)
}
}
var colorAry []int
colorAry = append(colorAry, GetColorVal["RedColor"])
colorAry = append(colorAry, GetColorVal["BlueColor"])
colorAry = append(colorAry, GetColorVal["YellowColor"])
colorAry = append(colorAry, GetColorVal["GreenColor"])
MaxColor := publicmethod.GetMaxNum[int](colorAry)
if GetColorVal["RedColor"] == MaxColor {
colorMax = append(colorMax, "红色")
}
if GetColorVal["BlueColor"] == MaxColor {
colorMax = append(colorMax, "蓝色")
}
if GetColorVal["YellowColor"] == MaxColor {
colorMax = append(colorMax, "黄色")
}
if GetColorVal["GreenColor"] == MaxColor {
colorMax = append(colorMax, "绿色")
}
return strings.Join(colorMax, ",")
}
// 计算颜色
func JiSuanColor(testPage []TestPageColor) map[string]int {
if len(testPage) < 1 {
sendDataw := make(map[string]int)
sendDataw["RedColor"] = 0
sendDataw["BlueColor"] = 0
sendDataw["YellowColor"] = 0
sendDataw["GreenColor"] = 0
return sendDataw
}
A_front_count := 0
B_front_count := 0
C_front_count := 0
D_front_count := 0
A_after_count := 0
B_after_count := 0
C_after_count := 0
D_after_count := 0
// fmt.Printf("testPage:%v\n", testPage)
for _, v := range testPage {
// testNumInt, _ := strconv.Atoi(v.TestNumber)
// checkedValInt, _ := strconv.Atoi(v.CheckedVal)
testNumInt := v.TestNumber
checkedValInt := v.CheckedVal
if testNumInt <= 15 {
switch checkedValInt {
case 2:
B_front_count++
case 3:
C_front_count++
case 4:
D_front_count++
default:
A_front_count++
}
} else {
switch checkedValInt {
case 2:
B_after_count++
case 3:
C_after_count++
case 4:
D_after_count++
default:
A_after_count++
}
}
}
fmt.Printf("A_front_count: %v, B_front_count: %v, C_front_count: %v, D_front_count: %v\n", A_front_count, B_front_count, C_front_count, D_front_count)
fmt.Printf("A_after_count: %v, B_after_count: %v, C_after_count: %v, D_after_count: %v\n", A_after_count, B_after_count, C_after_count, D_after_count)
RedColor := A_front_count + D_after_count
BlueColor := B_front_count + C_after_count
YellowColor := C_front_count + B_after_count
GreenColor := D_front_count + A_after_count
// fmt.Printf("A_front_count: %v, D_after_count: %v, B_front_count: %v, BlueColor: %v\n", A_front_count, D_after_count, B_front_count, C_after_count)
// fmt.Printf("RedColor: %v, GreenColor: %v, YellowColor: %v, BlueColor: %v\n", RedColor, GreenColor, YellowColor, BlueColor)
sendData := make(map[string]int)
sendData["RedColor"] = RedColor
sendData["BlueColor"] = BlueColor
sendData["YellowColor"] = YellowColor
sendData["GreenColor"] = GreenColor
sendData["A_front_count"] = A_front_count
sendData["B_front_count"] = B_front_count
sendData["C_front_count"] = C_front_count
sendData["D_front_count"] = D_front_count
sendData["A_after_count"] = A_after_count
sendData["B_after_count"] = B_after_count
sendData["C_after_count"] = C_after_count
sendData["D_after_count"] = D_after_count
return sendData
}
// 计算颜色
func JiSuanColorStr(testPage []TestPageColorStr) map[string]int {
if len(testPage) < 1 {
sendDataw := make(map[string]int)
sendDataw["RedColor"] = 0
sendDataw["BlueColor"] = 0
sendDataw["YellowColor"] = 0
sendDataw["GreenColor"] = 0
return sendDataw
}
A_front_count := 0
B_front_count := 0
C_front_count := 0
D_front_count := 0
A_after_count := 0
B_after_count := 0
C_after_count := 0
D_after_count := 0
// fmt.Printf("testPage:%v\n", testPage)
for _, v := range testPage {
testNumInt, _ := strconv.Atoi(v.TestNumber)
checkedValInt, _ := strconv.Atoi(v.CheckedVal)
// testNumInt := v.TestNumber
// checkedValInt := v.CheckedVal
if testNumInt <= 15 {
switch checkedValInt {
case 2:
B_front_count++
case 3:
C_front_count++
case 4:
D_front_count++
default:
A_front_count++
}
} else {
switch checkedValInt {
case 2:
B_after_count++
case 3:
C_after_count++
case 4:
D_after_count++
default:
A_after_count++
}
}
}
fmt.Printf("A_front_count: %v, B_front_count: %v, C_front_count: %v, D_front_count: %v\n", A_front_count, B_front_count, C_front_count, D_front_count)
fmt.Printf("A_after_count: %v, B_after_count: %v, C_after_count: %v, D_after_count: %v\n", A_after_count, B_after_count, C_after_count, D_after_count)
RedColor := A_front_count + D_after_count
BlueColor := B_front_count + C_after_count
YellowColor := C_front_count + B_after_count
GreenColor := D_front_count + A_after_count
// fmt.Printf("A_front_count: %v, D_after_count: %v, B_front_count: %v, BlueColor: %v\n", A_front_count, D_after_count, B_front_count, C_after_count)
// fmt.Printf("RedColor: %v, GreenColor: %v, YellowColor: %v, BlueColor: %v\n", RedColor, GreenColor, YellowColor, BlueColor)
sendData := make(map[string]int)
sendData["RedColor"] = RedColor
sendData["BlueColor"] = BlueColor
sendData["YellowColor"] = YellowColor
sendData["GreenColor"] = GreenColor
sendData["A_front_count"] = A_front_count
sendData["B_front_count"] = B_front_count
sendData["C_front_count"] = C_front_count
sendData["D_front_count"] = D_front_count
sendData["A_after_count"] = A_after_count
sendData["B_after_count"] = B_after_count
sendData["C_after_count"] = C_after_count
sendData["D_after_count"] = D_after_count
return sendData
}