作者 tangxvhui

Merge branch 'dev-tangxvhui' into test

package query
type ListAssessContentCycleDay struct {
CompanyId int `json:"companyId"`
OperaterId int `json:"operaterId"`
CycleId int `json:"cycleId,string"`
BeginDay string `json:"beginDay"`
TargetUserName string `json:"targetUserName"`
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
}
... ...
package query
type ListAssessCycleDay struct {
CompanyId int `json:"companyId"`
CycleId int `json:"cycleId,string"`
}
... ...
... ... @@ -1726,12 +1726,11 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
continue
}
v.Value = item.Value
//填入评估值描述
reteResult, err := v.Rule.ScoreOrRating(&v.Value)
//转换填入的评估值
err = v.TransformValue()
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
v.ReteResult = reteResult
for ii := range v.Remark {
for _, vvv := range item.Remark {
if v.Remark[ii].Title == vvv.Title {
... ... @@ -1740,7 +1739,6 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
}
}
}
}
//保存信息
for i := range assessContentList {
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
)
//员工绩效-项目管理
//获取已被执行的周期列表
func (srv StaffAssessServeice) GetAllAssessCycleName() {
func (srv StaffAssessServeice) ListAllAssessCycle(companyid int) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
assessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
cycleList, err := assessDao.AllAssessCycleList(companyid)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取周期列表"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
result := map[string]interface{}{
"list": cycleList,
}
return result, nil
}
//获取周期内的考核日期
func (srv StaffAssessServeice) ListAllAssessCycleDay(param *query.ListAssessCycleDay) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
assessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
cycleDayList, err := assessDao.AllAssessCycleDayList(param.CompanyId, param.CycleId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取周期列表"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
result := map[string]interface{}{
"list": cycleDayList,
}
return result, nil
}
//根据周期id和日期获取 员工填写评估内容
// 有过滤查看权限
func (srv StaffAssessServeice) ListAllAssessContentCycleDay(param *query.ListAssessContentCycleDay) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// assessDao := dao.NewStaffAssessDao(map[string]interface{}{
// "transactionContext": transactionContext,
// })
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil, nil
}
... ...
package domain
import (
"errors"
"fmt"
"strconv"
"time"
)
... ... @@ -58,54 +55,54 @@ type EvaluationRule struct {
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
}
// 根据评估填写的值,得出等级名称
// 如果 评估方式是评分,对评估填写的值的小数点后的位数进行处理,
// value 根据评估填写的值
func (rule *EvaluationRule) ScoreOrRating(value *string) (string, error) {
switch rule.Type {
case EvaluationTypeRating:
return rule.RatingValue(value)
case EvaluationTypeScore:
return rule.ScoreValue(value)
}
return "", errors.New("rule.Type 错误")
}
//根据评估填写的值,得出等级名称,
func (rule *EvaluationRule) ScoreValue(value *string) (string, error) {
valueFloat, err := strconv.ParseFloat(*value, 64)
if err != nil {
return "", errors.New("评分填写的值错误")
}
if valueFloat < rule.Score.Min || valueFloat > rule.Score.Max {
return "", fmt.Errorf("评分填写的值超出限制,>=%f且<=%f", rule.Score.Min, rule.Score.Max)
}
//保留小数处理
fStr := fmt.Sprintf("%%.%df", rule.Score.DecimalPlaces)
valueStr := fmt.Sprintf(fStr, valueFloat)
*value = valueStr
if rule.Score.IntervalState == 0 {
// 未开启按分数子区间匹配等级
return "", nil
}
valueDescrip := ""
for _, v := range rule.Score.Levels {
if valueFloat >= v.Start && valueFloat <= v.End {
valueDescrip = v.Name
}
}
return valueDescrip, nil
}
//根据评估填写的值,得出等级名称,
func (rule *EvaluationRule) RatingValue(value *string) (string, error) {
for _, v := range rule.Rating.Levels {
if v.Code == *value {
return v.Name, nil
}
}
return "", errors.New("评估填写的值错误")
}
// // 根据评估填写的值,得出等级名称和填写的值量化值
// // 如果 评估方式是评分,对评估填写的值的小数点后的位数进行处理,
// // value 根据评估填写的值
// func (rule *EvaluationRule) ScoreOrRating(value *string) (string, error) {
// switch rule.Type {
// case EvaluationTypeRating:
// return rule.RatingValue(value)
// case EvaluationTypeScore:
// return rule.ScoreValue(value)
// }
// return "", errors.New("rule.Type 错误")
// }
// //根据评估填写的值,得出等级名称和填写的值量化值
// func (rule *EvaluationRule) ScoreValue(value *string) (string, error) {
// valueFloat, err := strconv.ParseFloat(*value, 64)
// if err != nil {
// return "", errors.New("评分填写的值错误")
// }
// if valueFloat < rule.Score.Min || valueFloat > rule.Score.Max {
// return "", fmt.Errorf("评分填写的值超出限制,>=%f且<=%f", rule.Score.Min, rule.Score.Max)
// }
// //保留小数处理
// fStr := fmt.Sprintf("%%.%df", rule.Score.DecimalPlaces)
// valueStr := fmt.Sprintf(fStr, valueFloat)
// *value = valueStr
// if rule.Score.IntervalState == 0 {
// // 未开启按分数子区间匹配等级
// return "", nil
// }
// valueDescrip := ""
// for _, v := range rule.Score.Levels {
// if valueFloat >= v.Start && valueFloat <= v.End {
// valueDescrip = v.Name
// }
// }
// return valueDescrip, nil
// }
// //根据评估填写的值,得出等级名称,
// func (rule *EvaluationRule) RatingValue(value *string) (string, error) {
// for _, v := range rule.Rating.Levels {
// if v.Code == *value {
// return v.Name, nil
// }
// }
// return "", errors.New("评估填写的值错误")
// }
// GenerateSysRule 当前公司下的生成默认规则
func GenerateSysRule(companyId int64) *EvaluationRule {
... ...
package domain
import "time"
import (
"errors"
"fmt"
"strconv"
"time"
)
//填写的评估内容
type StaffAssessContent struct {
... ... @@ -13,6 +18,8 @@ type StaffAssessContent struct {
PromptText string `json:"promptText"` //提示项正文
Remark []AssessContemtRemark `json:"remark"` //填写的反馈
Value string `json:"value"` //评估填写的值
ScoreValue float64 `json:"scoreValue"` // 填写值按规则Rule转换为相应的量化值
LevelValue string `json:"levelValue"` // 填写值按规则Rule转换为相应的等级值
ReteResult string `json:"reteResult"` //评估的结果
Rule EvaluationRule `json:"rule"` //评估的选项规则
Weight int `json:"weight" ` //"权重"
... ... @@ -28,6 +35,63 @@ type AssessContemtRemark struct {
RemarkText string `json:"remarkText"` // comment:"填写文本内容"
}
//TransformValue
//根据规则 rule 转换评填写的值
func (content *StaffAssessContent) TransformValue() error {
switch content.Rule.Type {
case EvaluationTypeRating:
return content.ratingValue()
case EvaluationTypeScore:
return content.scoreValue()
}
return nil
}
// 规则是评级方式
func (content *StaffAssessContent) ratingValue() error {
levels := content.Rule.Rating.Levels
for _, v := range levels {
if v.Code != content.Value {
continue
}
content.LevelValue = v.Code
content.ScoreValue = v.QuantizedValue
content.ReteResult = v.Name
return nil
}
return errors.New("评级填写的值错误")
}
// 规则是评分方式
func (content *StaffAssessContent) scoreValue() error {
valueFloat, err := strconv.ParseFloat(content.Value, 64)
if err != nil {
return errors.New("评分填写的值错误")
}
rule := &content.Rule
if valueFloat < rule.Score.Min || valueFloat > rule.Score.Max {
return fmt.Errorf("评分填写的值超出限制,>=%f且<=%f", rule.Score.Min, rule.Score.Max)
}
//保留小数处理
fStr := fmt.Sprintf("%%.%df", rule.Score.DecimalPlaces)
valueStr := fmt.Sprintf(fStr, valueFloat)
content.Value = valueStr
if rule.Score.IntervalState == 0 {
// 未开启按分数子区间匹配等级
return nil
}
for _, v := range rule.Score.Levels {
if valueFloat < v.Start || valueFloat > v.End {
continue
}
content.LevelValue = v.Code
content.ScoreValue = valueFloat
content.ReteResult = v.Name
return nil
}
return errors.New("评分填写的值错误")
}
type StaffAssessContentRepository interface {
Save(param *StaffAssessContent) (*StaffAssessContent, error)
Remove(id int) error
... ...
package dao
import (
"fmt"
"strconv"
"github.com/go-pg/pg/v10"
... ... @@ -152,4 +153,173 @@ func (d *StaffAssessDao) AllAssessCycleDayList(companyId int, cycleId int) ([]As
return result, err
}
//获取员工填写评估内容
type UserAssessContent struct {
TargetUserId string `json:"targetUserId"` //被评估人的id
TargetUserName string `json:"targetUserName"` //被评估人的名称
BeginDay string `json:"beginDay"` //评估的日期
EvaluationProjectId string `json:"evaluationProjectId"` //项目id
Value string `json:"value"` //评估填写的值
SortBy int `json:"sortBy"` //评估项顺序
Category string `json:"category"` //评估项分类
ContentName string `json:"contentName"` //评估项名称
Weight int `json:"weight"` //权重
}
type SearchConditin1 struct {
CompanyId int //公司id
CycleId int //周期id
BeginDay string //评估的日期
TargetUserName string //被评估人的名称
Limit int //分页
Offset int //分页
OperaterId int //用户的id是谁在搜索数据
Hrbp int //
}
//根据周期的id和日期获取员工填写的评估内容
//companyId int 公司id
//cycleId int, 评估周期id
//userId int, 用户id,谁要查看数据
//beginDay string, 周期中执行项目的时间
//hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
//limit int, 分页条数
//offset int 分页偏移
func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserAssessContent, error) {
sqlStr := ` select
t_staff_assess_1.target_user_id,t_staff_assess_1.target_user_name,t_staff_assess_1.begin_day,
staff_assess_content.value ,staff_assess_content.sort_by ,
staff_assess_content.category ,staff_assess_content."name" as content_name ,
staff_assess_content.weight
from t_staff_assess_1
left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
`
condition := []interface{}{}
if len(param.TargetUserName) > 0 {
sqlStr += ` where t_staff_assess_1.target_user_name like ? `
condition = append(condition, param.TargetUserName)
}
//加入排序
sqlStr += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'),staff_assess_content.sort_by `
//获取前置sql语句
sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, param.Limit, param.Offset)
sqlStr = sqlStr0 + sqlStr
tx := d.transactionContext.PgTx
var result []UserAssessContent
_, err := tx.QueryOne(&result, sqlStr, condition...)
return result, err
}
//根据周期的id和日期获取员工填写的评估内容,数量统计
//companyId int 公司id
//cycleId int, 评估周期id
//userId int, 用户id,谁要查看数据
//beginDay string, 周期中执行项目的时间
//hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
//limit int, 分页条数
//offset int 分页偏移
func (d *StaffAssessDao) CountUserAssess(param SearchConditin1) ([]UserAssessContent, error) {
sqlStr := ` select
t_staff_assess_1.target_user_id,t_staff_assess_1.target_user_name,t_staff_assess_1.begin_day,
staff_assess_content.value ,staff_assess_content.sort_by ,
staff_assess_content.category ,staff_assess_content."name" as content_name ,
staff_assess_content.weight
from t_staff_assess_1
left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
`
condition := []interface{}{}
if len(param.TargetUserName) > 0 {
sqlStr += ` where t_staff_assess_1.target_user_name like ? `
condition = append(condition, param.TargetUserName)
}
//加入排序
sqlStr += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'),staff_assess_content.sort_by `
//获取前置sql语句
sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, param.Limit, param.Offset)
sqlStr = sqlStr0 + sqlStr
tx := d.transactionContext.PgTx
var result []UserAssessContent
_, err := tx.QueryOne(&result, sqlStr, condition...)
return result, err
}
//生成的sql 根据用户的查看权限 ,获取可查看的评估任务,
//companyId int 公司id
//cycleId int, 评估周期id
//userId int, 用户id,谁要查看数据
//beginDay string, 周期中执行项目的时间
//hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
//limit int, 分页条数
//offset int 分页偏移
func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int, beginDay string, hrbp int, limit int, offset int) string {
sqlstr := `
with t_user_department as (
select "user".id as user_id ,jsonb_array_elements_text ("user".department_id) as depart_id from "user"
where "user".company_id= %d
),
t_department as (
select department.id::text as depart_id from department where charge_user_ids @>'[%d]'
),
-- 如果是部门管理员 获取用户列表
t_user_1 as (
select t_user_department.user_id::text from t_user_department
join t_department on t_user_department.depart_id = t_department.depart_id
),
-- 如果是hrbp
t_project_1 as(
select evaluation_project.id as project_id
from evaluation_project
where evaluation_project.cycle_id =%d
and evaluation_project.hr_bp = %d
),
-- 如果是项目管理员
t_project_2 as(
select evaluation_project.id as project_id
from evaluation_project
where evaluation_project.cycle_id =%d
and evaluation_project.pmp =1
and evaluation_project.pmp_ids @>'["%d"]'
),
-- 合并数据
t_project_3 as (
select t_project_2.project_id from t_project_2
union
select t_project_1.project_id from t_project_1
),
-- 初步过滤评估列表数据
t_staff_assess_0 as (
select staff_assess.id as assess_id,
staff_assess.target_user->>'userId' as target_user_id,
staff_assess.target_user->>'userName' as target_user_name,
to_char(staff_assess.begin_time,'YYYY-MM-DD') as begin_day,
staff_assess.evaluation_project_id
from staff_assess
where staff_assess.cycle_id = %d
and to_char(staff_assess.begin_time,'YYYY-MM-DD')='%s'
and staff_assess."types" ='self'
),
-- 合并根据权限过滤后的数据
t_staff_assess_1 as (
(select t_staff_assess_0.assess_id,
t_staff_assess_0.target_user_id,
t_staff_assess_0.target_user_name,
t_staff_assess_0.begin_day
from t_staff_assess_0
join t_project_3 on t_staff_assess_0.evaluation_project_id = t_project_3.project_id
) union (select t_staff_assess_0.assess_id,
t_staff_assess_0.target_user_id,
t_staff_assess_0.target_user_name,
t_staff_assess_0.begin_day
from t_staff_assess_0
join t_user_1 on t_staff_assess_0.target_user_id=t_user_1.user_id
)
limit %d offset %d
)
`
params := []interface{}{
companyId, userId, cycleId, hrbp, cycleId, userId, cycleId, beginDay, limit, offset,
}
sqlstr = fmt.Sprintf(sqlstr, params...)
return sqlstr
}
... ...
... ... @@ -14,6 +14,8 @@ type StaffAssessContent struct {
SortBy int //排序
Category string //类别
Name string //名称
ScoreValue float64 // 填写值按规则Rule转换为相应的量化值
LevelValue string // 填写值按规则Rule转换为相应的等级值
PromptTitle string //问题标题
PromptText string //提示项正文
Value string //评估填写的值
... ...
... ... @@ -32,6 +32,8 @@ func (repo *StaffAssessContentRepository) TransformToDomain(d *models.StaffAsses
PromptText: d.PromptText,
Remark: d.Remark,
Value: d.Value,
ScoreValue: d.ScoreValue,
LevelValue: d.LevelValue,
ReteResult: d.ReteResult,
Rule: d.Rule,
Weight: d.Weight,
... ... @@ -48,15 +50,17 @@ func (repo *StaffAssessContentRepository) Save(d *domain.StaffAssessContent) (*d
SortBy: d.SortBy,
Category: d.Category,
Name: d.Name,
ScoreValue: d.ScoreValue,
LevelValue: d.LevelValue,
PromptTitle: d.PromptTitle,
PromptText: d.PromptText,
Remark: d.Remark,
Value: d.Value,
ReteResult: d.ReteResult,
Rule: d.Rule,
Remark: d.Remark,
Weight: d.Weight,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
Weight: d.Weight,
DeletedAt: nil,
}
tx := repo.transactionContext.PgTx
... ...
... ... @@ -279,3 +279,35 @@ func (c *StaffAssessController) ListTargetUserMeSupperAssess() {
data, err := srv.ListTargetUserAssess(paramReq)
c.Response(data, err)
}
//获取周期列表
func (c *StaffAssessController) ListAssessCycle() {
srv := service.NewStaffAssessServeice()
// paramReq := &query.ListTargetUserAssessQuery{}
// err := c.BindJSON(paramReq)
// if err != nil {
// e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
// c.Response(nil, e)
// return
// }
userReq := middlewares.GetUser(c.Ctx)
data, err := srv.ListAllAssessCycle(int(userReq.CompanyId))
c.Response(data, err)
}
//获取周期里的考核日期
func (c *StaffAssessController) ListAssessCycleDay() {
srv := service.NewStaffAssessServeice()
paramReq := &query.ListAssessCycleDay{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
userReq := middlewares.GetUser(c.Ctx)
paramReq.CompanyId = int(userReq.CompanyId)
data, err := srv.ListAllAssessCycleDay(paramReq)
c.Response(data, err)
}
... ...
... ... @@ -13,6 +13,8 @@ func init() {
web.NSCtrlPost("/search/me", (*controllers.StaffAssessController).SearchAssessTaskMe), //获取我参与过的评估项目列表
web.NSCtrlPost("/desc/me", (*controllers.StaffAssessController).AssessTaskMeDesc), //获取我的项目评估进度描述
web.NSCtrlPost("/", (*controllers.StaffAssessController).CreateStaffAssessTask), //创建员工的评估任务
web.NSCtrlGet("/cycle", (*controllers.StaffAssessController).ListAssessCycle), //获取周期列表
web.NSCtrlPost("/cycle/day", (*controllers.StaffAssessController).ListAssessCycleDay), //获取周期中的考核日期
)
// /v1/staff-assess/self/me/list
assessNS := web.NewNamespace("/v1/staff-assess",
... ...