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.
542 lines
15 KiB
542 lines
15 KiB
package rongXinPage
|
|
|
|
import (
|
|
"appPlatform/models/modelshr"
|
|
personalitycolor "appPlatform/models/personalityColor"
|
|
"appPlatform/overall"
|
|
"appPlatform/overall/publicmethod"
|
|
"encoding/csv"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/url"
|
|
"sort"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-09-13 08:55:14
|
|
@ 功能:下载九型人格测试结果
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) DownLoadNineTestPage(c *gin.Context) {
|
|
|
|
keywords := c.Query("keywords")
|
|
adminorg := c.Query("adminorg")
|
|
emptype := c.Query("emptype")
|
|
|
|
var peopleList []modelshr.PersonArchives
|
|
goormDb := overall.CONSTANT_DB_HrInside.Model(&modelshr.PersonArchives{}).Select("`number`,`name`,`admin_org`").Where("`emp_type` BETWEEN 1 AND 10")
|
|
|
|
if keywords != "undefined" && keywords != "" {
|
|
goormDb = goormDb.Where("`name` LIKE ?", "%"+keywords+"%")
|
|
}
|
|
if adminorg != "undefined" && adminorg != "" {
|
|
adminorgInt, _ := strconv.ParseInt(adminorg, 10, 64)
|
|
var sunOrg publicmethod.GetOrgAllParent
|
|
sunOrg.GetOrgSun(adminorgInt)
|
|
sunOrg.Id = append(sunOrg.Id, adminorgInt)
|
|
if len(sunOrg.Id) > 0 {
|
|
goormDb = goormDb.Where("`admin_org` IN ?", sunOrg.Id)
|
|
}
|
|
}
|
|
var empInt []int
|
|
json.Unmarshal([]byte(emptype), &empInt)
|
|
if len(empInt) > 0 {
|
|
goormDb = goormDb.Where("`emp_type` IN ?", empInt)
|
|
}
|
|
err := goormDb.Find(&peopleList).Error
|
|
if err != nil || len(peopleList) < 1 {
|
|
c.String(c.Writer.Status(), "没有查询到数据")
|
|
return
|
|
}
|
|
// fmt.Printf("%v-%v-%v-%v\n", keywords, adminorg, emptype, peopleList)
|
|
|
|
testPageList := GetPeopleNineData(peopleList)
|
|
// fmt.Printf("testPageList->%v\n", testPageList)
|
|
var builder strings.Builder
|
|
builder.WriteString("\xEF\xBB\xBF") //写入UTF-8 BOM 防止乱码
|
|
writer := csv.NewWriter(&builder)
|
|
writer.Write([]string{"团队角色盘点"})
|
|
writer.Write([]string{"序号", "工号", "姓名", "行政组织", "第一角色", "第二角色", "第三角色", "第四角色"})
|
|
|
|
for i, v := range testPageList {
|
|
var scvBody []string
|
|
xuHao := strconv.Itoa(i + 1)
|
|
scvBody = append(scvBody, xuHao)
|
|
scvBody = append(scvBody, v...)
|
|
writer.Write(scvBody)
|
|
}
|
|
|
|
writer.Flush()
|
|
fileName := fmt.Sprintf("团队角色盘点_%v.csv", publicmethod.GetUUid(1))
|
|
c.Writer.Header().Add("Content-type", "application/octet-stream")
|
|
c.Header("Content-Type", "application/vnd.ms-excel;charset=utf8")
|
|
c.Header("Content-Disposition", "attachment; filename="+url.PathEscape(fileName))
|
|
// c.Header("Content-Disposition", "attachment; filename=团队角色盘点.csv")
|
|
c.Header("Content-Transfer-Encoding", "binary")
|
|
c.Writer.Write([]byte(builder.String()))
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-09-13 10:30:19
|
|
@ 功能: 获取人员九型性格数据
|
|
*/
|
|
func GetPeopleNineData(user []modelshr.PersonArchives) (list [][]string) {
|
|
if len(user) < 1 {
|
|
return
|
|
}
|
|
var numAry []string
|
|
for _, v := range user {
|
|
numAry = append(numAry, v.Number)
|
|
}
|
|
var xgAry []personalitycolor.Charcolortest
|
|
overall.CONSTANT_DB_Color.Model(&personalitycolor.Charcolortest{}).Where("`c_class` = ? AND `c_number` IN ?", 10000003, numAry).Find(&xgAry)
|
|
|
|
for i := 0; i < len(xgAry); i++ {
|
|
|
|
if xgAry[i].TestJson != "" {
|
|
var testPage JieShouDaaning
|
|
err := json.Unmarshal([]byte(xgAry[i].TestJson), &testPage)
|
|
if err == nil {
|
|
scoreForEachItem := CalculateScoresForEachItem(testPage)
|
|
sort.Slice(scoreForEachItem, func(i, j int) bool {
|
|
return scoreForEachItem[i].Value > scoreForEachItem[j].Value
|
|
})
|
|
var itemList []string
|
|
number, name, org := GetUserName(xgAry[i].Number, user)
|
|
itemList = append(itemList, number)
|
|
itemList = append(itemList, name)
|
|
itemList = append(itemList, org)
|
|
for j := 0; j < 4; j++ {
|
|
itemList = append(itemList, scoreForEachItem[j].Attribute)
|
|
}
|
|
list = append(list, itemList)
|
|
}
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-09-13 11:17:14
|
|
@ 功能: 获取人员姓名
|
|
*/
|
|
func GetUserName(num string, user []modelshr.PersonArchives) (number, name, org string) {
|
|
for _, v := range user {
|
|
if v.Number == num {
|
|
number = num
|
|
name = v.Name
|
|
org = GetOrgInfo(v.AdminOrg)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-09-14 10:31:36
|
|
@ 功能: 获取行政组织
|
|
*/
|
|
func GetOrgInfo(orgId int64) string {
|
|
var fatherOrg publicmethod.GetOrgAllParent
|
|
fatherOrg.GetOrgAllFatherId(orgId, 4)
|
|
var orgName []string
|
|
orgIdLen := len(fatherOrg.Id)
|
|
if orgIdLen > 0 {
|
|
for i := orgIdLen - 1; i >= 0; i-- {
|
|
if fatherOrg.Id[i] != 0 {
|
|
var orgInfo modelshr.AdministrativeOrganization
|
|
orgInfo.GetCont(map[string]interface{}{"`id`": fatherOrg.Id[i]}, "`name`")
|
|
if orgInfo.Name != "" {
|
|
orgName = append(orgName, orgInfo.Name)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if len(orgName) > 0 {
|
|
return strings.Join(orgName, "/")
|
|
}
|
|
return ""
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-09-13 10:49:43
|
|
@ 功能: 计算各项得分
|
|
*/
|
|
func CalculateScoresForEachItem(testPage JieShouDaaning) (ScoreForEachItem []Character) {
|
|
PL := 0
|
|
RI := 0
|
|
CO := 0
|
|
SH := 0
|
|
ME := 0
|
|
TW := 0
|
|
IM := 0
|
|
CF := 0
|
|
SP := 0
|
|
DR := 0
|
|
for _, v := range testPage.List {
|
|
|
|
for _, av := range v.Answer {
|
|
// fmt.Printf("PL:%v\n", av.Attribute)
|
|
switch av.Attribute {
|
|
case "PL":
|
|
// fmt.Printf("PL:%v\n", av.Value)
|
|
PL = PL + av.Value
|
|
case "RI":
|
|
RI = RI + av.Value
|
|
case "CO":
|
|
CO = CO + av.Value
|
|
case "SH":
|
|
SH = SH + av.Value
|
|
case "ME":
|
|
ME = ME + av.Value
|
|
case "TW":
|
|
TW = TW + av.Value
|
|
case "IM":
|
|
IM = IM + av.Value
|
|
case "CF":
|
|
CF = CF + av.Value
|
|
case "SP":
|
|
SP = SP + av.Value
|
|
case "DR":
|
|
DR = DR + av.Value
|
|
default:
|
|
}
|
|
}
|
|
}
|
|
var itemScorePL Character
|
|
itemScorePL.Title = "PL"
|
|
itemScorePL.Attribute = "创新智多星"
|
|
itemScorePL.Value = PL
|
|
ScoreForEachItem = append(ScoreForEachItem, itemScorePL)
|
|
|
|
var itemScoreRI Character
|
|
itemScoreRI.Title = "RI"
|
|
itemScoreRI.Attribute = "资源调查员"
|
|
itemScoreRI.Value = RI
|
|
ScoreForEachItem = append(ScoreForEachItem, itemScoreRI)
|
|
|
|
var itemScoreCO Character
|
|
itemScoreCO.Title = "CO"
|
|
itemScoreCO.Attribute = "协调者"
|
|
itemScoreCO.Value = CO
|
|
ScoreForEachItem = append(ScoreForEachItem, itemScoreCO)
|
|
|
|
var itemScoreSH Character
|
|
itemScoreSH.Title = "SH"
|
|
itemScoreSH.Attribute = "鞭策者"
|
|
itemScoreSH.Value = SH
|
|
ScoreForEachItem = append(ScoreForEachItem, itemScoreSH)
|
|
|
|
var itemScoreME Character
|
|
itemScoreME.Title = "ME"
|
|
itemScoreME.Attribute = "监督评论员"
|
|
itemScoreME.Value = ME
|
|
ScoreForEachItem = append(ScoreForEachItem, itemScoreME)
|
|
|
|
var itemScoreTW Character
|
|
itemScoreTW.Title = "TW"
|
|
itemScoreTW.Attribute = "凝聚者"
|
|
itemScoreTW.Value = TW
|
|
ScoreForEachItem = append(ScoreForEachItem, itemScoreTW)
|
|
|
|
var itemScoreIM Character
|
|
itemScoreIM.Title = "IM"
|
|
itemScoreIM.Attribute = "实干家"
|
|
itemScoreIM.Value = IM
|
|
ScoreForEachItem = append(ScoreForEachItem, itemScoreIM)
|
|
|
|
var itemScoreCF Character
|
|
itemScoreCF.Title = "CF"
|
|
itemScoreCF.Attribute = "善始善终者"
|
|
itemScoreCF.Value = CF
|
|
ScoreForEachItem = append(ScoreForEachItem, itemScoreCF)
|
|
|
|
var itemScoreSP Character
|
|
itemScoreSP.Title = "SP"
|
|
itemScoreSP.Attribute = "专家"
|
|
itemScoreSP.Value = SP
|
|
ScoreForEachItem = append(ScoreForEachItem, itemScoreSP)
|
|
|
|
var itemScoreDR Character
|
|
itemScoreDR.Title = "DR"
|
|
itemScoreDR.Attribute = "DR"
|
|
itemScoreDR.Value = DR
|
|
ScoreForEachItem = append(ScoreForEachItem, itemScoreDR)
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-09-19 14:17:00
|
|
@ 功能: 下载人格测试状态
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) StatisticsPersonality(c *gin.Context) {
|
|
var requestData CharacterStatis
|
|
c.ShouldBindJSON(&requestData)
|
|
if requestData.Typekey == "" {
|
|
requestData.Typekey = "10000001"
|
|
}
|
|
|
|
keywords := c.Query("keywords")
|
|
adminorg := c.Query("org")
|
|
typekey := c.Query("typekey")
|
|
types := c.Query("types")
|
|
if typekey != "" {
|
|
requestData.Typekey = typekey
|
|
}
|
|
|
|
typesInt, _ := strconv.Atoi(types)
|
|
|
|
var xgNumber []string
|
|
overall.CONSTANT_DB_Color.Model(&personalitycolor.Charcolortest{}).Distinct("`c_number`").Where("`c_class` = ?", typekey).Find(&xgNumber)
|
|
|
|
var peopleList []modelshr.PersonArchives
|
|
goormDb := overall.CONSTANT_DB_HrInside.Model(&modelshr.PersonArchives{}).Select("`number`,`name`,`company`,`maindeparment`,`admin_org`").Where("`emp_type` BETWEEN 1 AND 10")
|
|
|
|
if keywords != "undefined" && keywords != "" {
|
|
goormDb = goormDb.Where("`name` LIKE ? OR `number` LIKE ?", "%"+keywords+"%", "%"+keywords+"%")
|
|
}
|
|
if adminorg != "undefined" && adminorg != "0" && adminorg != "" {
|
|
adminorgInt, _ := strconv.ParseInt(adminorg, 10, 64)
|
|
var sunOrg publicmethod.GetOrgAllParent
|
|
sunOrg.GetOrgSun(adminorgInt)
|
|
sunOrg.Id = append(sunOrg.Id, adminorgInt)
|
|
if len(sunOrg.Id) > 0 {
|
|
goormDb = goormDb.Where("`admin_org` IN ?", sunOrg.Id)
|
|
}
|
|
}
|
|
err := goormDb.Find(&peopleList).Error
|
|
if err != nil || len(peopleList) < 1 {
|
|
c.String(c.Writer.Status(), "没有查询到数据")
|
|
return
|
|
}
|
|
// return
|
|
var builder strings.Builder
|
|
builder.WriteString("\xEF\xBB\xBF") //写入UTF-8 BOM 防止乱码
|
|
writer := csv.NewWriter(&builder)
|
|
if typesInt == 2 {
|
|
// fmt.Printf("Typekey: %v\n", requestData.Typekey)
|
|
writer.Write([]string{"已完成测试人员名单"})
|
|
switch requestData.Typekey {
|
|
case "10000001": //性格色彩
|
|
writer.Write([]string{"序号", "工号", "姓名", "行政组织", "性格色彩解析"})
|
|
// fmt.Printf("Typekey----1------>: %v\n", requestData.Typekey)
|
|
case "10000002": //DISC性格特质
|
|
writer.Write([]string{"序号", "工号", "姓名", "行政组织", "DISC性格解析"})
|
|
// fmt.Printf("Typekey----2------>: %v\n", requestData.Typekey)
|
|
case "10000003": //九型人格特质
|
|
writer.Write([]string{"序号", "工号", "姓名", "行政组织", "第一角色", "第二角色", "第三角色", "第四角色"})
|
|
// fmt.Printf("Typekey----3------>: %v\n", requestData.Typekey)
|
|
default:
|
|
writer.Write([]string{"序号", "工号", "姓名", "行政组织"})
|
|
// fmt.Printf("Typekey----4------>: %v\n", requestData.Typekey)
|
|
}
|
|
} else {
|
|
writer.Write([]string{"未完成测试人员名单"})
|
|
writer.Write([]string{"序号", "工号", "姓名", "行政组织"})
|
|
}
|
|
|
|
jibuqi := 0
|
|
for _, v := range peopleList {
|
|
if typesInt == 2 {
|
|
if publicmethod.IsInTrue[string](v.Number, xgNumber) {
|
|
var scvBody []string
|
|
jibuqi++
|
|
xuHao := strconv.Itoa(jibuqi)
|
|
scvBody = append(scvBody, xuHao)
|
|
scvBody = append(scvBody, v.Number)
|
|
scvBody = append(scvBody, v.Name)
|
|
scvBody = append(scvBody, jisuanOrg(v.Company, v.MainDeparment, v.AdminOrg))
|
|
switch requestData.Typekey {
|
|
case "10000001": //性格色彩
|
|
scvBody = append(scvBody, TallyColor(v))
|
|
case "10000002": //DISC性格特质
|
|
scvBody = append(scvBody, TallDiscCaput(v))
|
|
case "10000003": //九型人格特质
|
|
scvBody = append(scvBody, TallyNineCaput(v)...)
|
|
default:
|
|
|
|
}
|
|
writer.Write(scvBody)
|
|
}
|
|
} else {
|
|
if !publicmethod.IsInTrue[string](v.Number, xgNumber) {
|
|
var scvBody []string
|
|
jibuqi++
|
|
xuHao := strconv.Itoa(jibuqi)
|
|
scvBody = append(scvBody, xuHao)
|
|
scvBody = append(scvBody, v.Number)
|
|
scvBody = append(scvBody, v.Name)
|
|
scvBody = append(scvBody, jisuanOrg(v.Company, v.MainDeparment, v.AdminOrg))
|
|
writer.Write(scvBody)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
writer.Flush()
|
|
fileName := fmt.Sprintf("未完成测试人员名单_%v.csv", publicmethod.GetUUid(1))
|
|
if typesInt == 2 {
|
|
fileName = fmt.Sprintf("已完成测试人员名单_%v.csv", publicmethod.GetUUid(1))
|
|
}
|
|
// fmt.Printf("fileName: %v\n", fileName)
|
|
c.Writer.Header().Add("Content-type", "application/octet-stream")
|
|
c.Header("Content-Type", "application/vnd.ms-excel;charset=utf8")
|
|
c.Header("Content-Disposition", "attachment; filename="+url.PathEscape(fileName))
|
|
// c.Header("Content-Disposition", "attachment; filename=团队角色盘点.csv")
|
|
c.Header("Content-Transfer-Encoding", "binary")
|
|
c.Writer.Write([]byte(builder.String()))
|
|
|
|
// for _, v := range peopleList {
|
|
|
|
// }
|
|
|
|
// org = GetOrgInfo(v.AdminOrg)
|
|
// publicmethod.Result(0, xgNumber, c)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-09-19 15:20:31
|
|
@ 功能: 计算行政组织关系
|
|
*/
|
|
func jisuanOrg(company, deparment, org int64) string {
|
|
var orgList []string
|
|
if company != 0 {
|
|
var com modelshr.AdministrativeOrganization
|
|
// err := com.GetCont(map[string]interface{}{"`id`": company}, "`name`")
|
|
err := com.RedisCont(company)
|
|
if err == nil {
|
|
orgList = append(orgList, com.Name)
|
|
}
|
|
}
|
|
if deparment != 0 && deparment != company {
|
|
var depam modelshr.AdministrativeOrganization
|
|
// err := depam.GetCont(map[string]interface{}{"`id`": deparment}, "`name`")
|
|
err := depam.RedisCont(deparment)
|
|
if err == nil {
|
|
orgList = append(orgList, depam.Name)
|
|
}
|
|
}
|
|
if org != 0 && org != deparment && org != company {
|
|
var orgInfo modelshr.AdministrativeOrganization
|
|
// err := orgInfo.GetCont(map[string]interface{}{"`id`": org}, "`name`")
|
|
err := orgInfo.RedisCont(org)
|
|
if err == nil {
|
|
orgList = append(orgList, orgInfo.Name)
|
|
}
|
|
}
|
|
if len(orgList) > 0 {
|
|
return strings.Join(orgList, "/")
|
|
}
|
|
return ""
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2025-02-27 11:02:37
|
|
@ 功能: 下载人员班组
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) DownLoadTearms(c *gin.Context) {
|
|
adminorg := c.Query("org")
|
|
if adminorg == "" || adminorg == "0" {
|
|
c.String(c.Writer.Status(), "没有获取到正确的行政组织")
|
|
return
|
|
}
|
|
adminorgInt, _ := strconv.ParseInt(adminorg, 10, 64)
|
|
var sunOrg publicmethod.GetOrgAllParent
|
|
sunOrg.GetOrgSun(adminorgInt)
|
|
sunOrg.Id = append(sunOrg.Id, adminorgInt)
|
|
var peopleList []modelshr.PersonArchives
|
|
overall.CONSTANT_DB_HrInside.Model(&modelshr.PersonArchives{}).Select("`number`,`name`,`admin_org`,`teamid` ").Where("`admin_org` IN ? AND `emp_type` BETWEEN 1 AND 10", sunOrg.Id).Find(&peopleList)
|
|
if len(peopleList) < 1 {
|
|
c.String(c.Writer.Status(), "没有查询到信息")
|
|
return
|
|
}
|
|
var orgInfo modelshr.AdministrativeOrganization
|
|
orgInfo.GetCont(map[string]interface{}{"`id`": adminorg}, "`name`")
|
|
var builder strings.Builder
|
|
builder.WriteString("\xEF\xBB\xBF") //写入UTF-8 BOM 防止乱码
|
|
writer := csv.NewWriter(&builder)
|
|
tableTitle := fmt.Sprintf("%v班组信息列表", orgInfo.Name)
|
|
writer.Write([]string{tableTitle})
|
|
writer.Write([]string{"序号", "工号", "姓名", "班组"})
|
|
for i, v := range peopleList {
|
|
var scvBody []string
|
|
xuHao := strconv.Itoa(i + 1)
|
|
scvBody = append(scvBody, xuHao)
|
|
scvBody = append(scvBody, v.Number)
|
|
scvBody = append(scvBody, v.Name)
|
|
if v.TeamId != 0 {
|
|
var teamsInfo modelshr.TeamGroup
|
|
teamsInfo.GetCont(map[string]interface{}{"`id`": v.TeamId}, "`name`")
|
|
if teamsInfo.Name == "" {
|
|
scvBody = append(scvBody, "未知")
|
|
} else {
|
|
scvBody = append(scvBody, teamsInfo.Name)
|
|
}
|
|
|
|
} else {
|
|
scvBody = append(scvBody, "未知")
|
|
}
|
|
writer.Write(scvBody)
|
|
}
|
|
writer.Flush()
|
|
fileName := fmt.Sprintf("%v_班组信息列表_%v.csv", orgInfo.Name, publicmethod.GetUUid(1))
|
|
c.Writer.Header().Add("Content-type", "application/octet-stream")
|
|
c.Header("Content-Type", "application/vnd.ms-excel;charset=utf8")
|
|
c.Header("Content-Disposition", "attachment; filename="+url.PathEscape(fileName))
|
|
// c.Header("Content-Disposition", "attachment; filename=团队角色盘点.csv")
|
|
c.Header("Content-Transfer-Encoding", "binary")
|
|
c.Writer.Write([]byte(builder.String()))
|
|
}
|
|
|