package jurisdictionpc import ( "key_performance_indicators/models/modelshr" "key_performance_indicators/overall" "key_performance_indicators/overall/publicmethod" "strconv" "github.com/gin-gonic/gin" ) /* * @ 作者: 秦东 @ 时间: 2023-03-21 11:06:07 @ 功能: 搜索人员 @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) SearchPeople(c *gin.Context) { var receivedValue FlowGetRoleList err := c.ShouldBindJSON(&receivedValue) if err != nil { publicmethod.Result(100, err, c) return } if receivedValue.Name == "" { publicmethod.Result(101, receivedValue, c) return } if receivedValue.Page == 0 { receivedValue.Page = 1 } if receivedValue.PageSize == 0 { receivedValue.PageSize = 20 } var listCont []modelshr.PersonArchives gormDb := overall.CONSTANT_DB_HR.Model(&modelshr.PersonArchives{}).Where("`emp_type` BETWEEN ? AND ?", 1, 10) if receivedValue.Name != "" { gormDb = gormDb.Where("`name` LIKE ?", "%"+receivedValue.Name+"%") } var total int64 gormDbTotal := gormDb totalErr := gormDbTotal.Count(&total).Error if totalErr != nil { total = 0 } gormDb = publicmethod.PageTurningSettings(gormDb, receivedValue.Page, receivedValue.PageSize) err = gormDb.Find(&listCont).Error if err != nil { publicmethod.Result(107, err, c) return } var sendContList []EmployeesCont for _, v := range listCont { var sendCont EmployeesCont sendCont.Id = strconv.FormatInt(v.Key, 10) //`json:"id"` sendCont.EmployeeName = v.Name //`json:"employeeName"` //人员名称 sendCont.IsLeave = "0" //`json:"isLeave"` //行政组织名称 sendCont.Open = "false" //`json:"open"` //上级ID sendCont.Icon = v.Icon //`json:"icon"` //头像 sendCont.IconToBase64 = v.IconPhoto //`json:"iconToBase64"` //头像 sendCont.Wechat = v.Wechat //微信Openid if v.WorkWechat != "" { sendCont.Wechat = v.WorkWechat //微信Openid } _, companyId, _, _, _ := publicmethod.GetOrgStructurees(v.AdminOrg) if companyId != 0 { var orgCont modelshr.AdministrativeOrganization orgCont.GetCont(map[string]interface{}{"`id`": companyId}, "`name`") sendCont.Departmentid = companyId //分厂Id sendCont.DepartmentName = orgCont.Name //分厂名称 } //获取岗位 if v.Position != 0 { var postCont modelshr.Position postCont.GetCont(map[string]interface{}{"`id`": v.Position}, "`name`") sendCont.Postid = v.Position //职务Id sendCont.PostName = postCont.Name //职务名称 } if v.TeamId != 0 { var teamCont modelshr.TeamGroup teamCont.GetCont(map[string]interface{}{"`id`": v.TeamId}, "`name`") sendCont.Tema = v.TeamId //班组Id sendCont.TemaName = teamCont.Name //班组名称 } sendContList = append(sendContList, sendCont) } publicmethod.ResultList(0, receivedValue.Page, receivedValue.PageSize, total, int64(len(sendContList)), sendContList, c) }