作者 tangxvhui

添加接口

package adapter
type ListUserAssessContent struct {
TableHeader []ListTableHeader `json:"tableHeader"`
List []map[string]string `json:"list"`
Total int `json:"total"`
}
... ...
package service
import (
"fmt"
"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/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
)
... ... @@ -67,8 +71,8 @@ func (srv StaffAssessServeice) ListAllAssessCycleDay(param *query.ListAssessCycl
}
//根据周期id和日期获取 员工填写评估内容
// 有过滤查看权限
func (srv StaffAssessServeice) ListAllAssessContentCycleDay(param *query.ListAssessContentCycleDay) (map[string]interface{}, error) {
//有过滤查看权限
func (srv StaffAssessServeice) ListUserAssessContentCycleDay(param *query.ListAssessContentCycleDay) (*adapter.ListUserAssessContent, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -79,11 +83,110 @@ func (srv StaffAssessServeice) ListAllAssessContentCycleDay(param *query.ListAss
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// assessDao := dao.NewStaffAssessDao(map[string]interface{}{
// "transactionContext": transactionContext,
// })
roleRepo := factory.CreateRoleRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, roleList, err := roleRepo.Find(map[string]interface{}{
"type": domain.RoleTypeSystem,
"companyId": param.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error())
}
_, userRoleList, err := roleUserRepo.Find(map[string]interface{}{
"companyId": param.CompanyId,
"userId": param.OperaterId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
}
hrbp := -1
for _, v := range userRoleList {
for _, v2 := range roleList {
if v.RoleId == v2.Id {
hrbp = 1
break
}
}
if hrbp == 1 {
break
}
}
assessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
limit := param.PageSize
offset := (param.PageNumber - 1) * limit
cnt, err := assessDao.CountUserAssess(dao.SearchConditin1{
CompanyId: param.CompanyId,
CycleId: param.CycleId,
BeginDay: param.BeginDay,
TargetUserName: param.TargetUserName,
Limit: 5000,
Offset: 0,
OperaterId: param.OperaterId,
Hrbp: hrbp,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计总数"+err.Error())
}
contentList, err := assessDao.SearchUserAssessContent(dao.SearchConditin1{
CompanyId: param.CompanyId,
CycleId: param.CycleId,
BeginDay: param.BeginDay,
TargetUserName: param.TargetUserName,
Limit: limit,
Offset: offset,
OperaterId: param.OperaterId,
Hrbp: hrbp,
})
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())
}
return nil, nil
//可变的表格列
changeableHeader := []adapter.ListTableHeader{
{Key: "targetUserName", Name: "姓名"}, //固定列
}
//过滤重复的列
headerMap := map[string]string{}
// 获取已经填报的内容
changeableRows := map[string]map[string]string{}
tableSort := []string{} //确定列表数据的顺序
for i, v := range contentList {
name := fmt.Sprintf("%s-%s", v.Category, v.ContentName)
key := fmt.Sprintf("k%d", i)
if _, ok := headerMap[name]; !ok {
changeableHeader = append(changeableHeader, adapter.ListTableHeader{
Key: key, Name: name,
})
headerMap[name] = key
}
if _, ok := changeableRows[v.TargetUserId]; !ok {
changeableRows[v.TargetUserId] = map[string]string{}
tableSort = append(tableSort, v.TargetUserId)
}
key = headerMap[name]
changeableRows[v.TargetUserId][key] = v.Value
changeableRows[v.TargetUserId]["targetUserName"] = v.TargetUserName
changeableRows[v.TargetUserId]["targetUserId"] = v.TargetUserId
}
list := []map[string]string{}
for _, v := range tableSort {
list = append(list, changeableRows[v])
}
result := adapter.ListUserAssessContent{
TableHeader: changeableHeader,
Total: cnt,
List: list,
}
return &result, nil
}
... ...
... ... @@ -186,6 +186,12 @@ type SearchConditin1 struct {
//limit int, 分页条数
//offset int 分页偏移
func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserAssessContent, error) {
if param.Offset < 0 {
param.Offset = 0
}
if param.Limit < 0 {
param.Limit = 20
}
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 ,
... ... @@ -206,7 +212,7 @@ func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserA
sqlStr = sqlStr0 + sqlStr
tx := d.transactionContext.PgTx
var result []UserAssessContent
_, err := tx.QueryOne(&result, sqlStr, condition...)
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
... ... @@ -218,28 +224,19 @@ func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserA
//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
`
func (d *StaffAssessDao) CountUserAssess(param SearchConditin1) (int, error) {
sqlStr := ` select count(*) from t_staff_assess_1 `
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)
sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, 5000, 0)
sqlStr = sqlStr0 + sqlStr
tx := d.transactionContext.PgTx
var result []UserAssessContent
_, err := tx.QueryOne(&result, sqlStr, condition...)
var result int
_, err := tx.QueryOne(pg.Scan(&result), sqlStr, condition...)
return result, err
}
... ...
... ... @@ -3,13 +3,14 @@ package repository
import (
"errors"
"fmt"
"time"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
"time"
)
type RoleRepository struct {
... ... @@ -117,6 +118,10 @@ func (repo *RoleRepository) Find(queryOptions map[string]interface{}) (int64, []
query.Where("name = ?", v)
}
if v, ok := queryOptions["type"]; ok {
query.Where("type=?", v)
}
if companyId, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", companyId)
}
... ...
... ... @@ -283,15 +283,7 @@ func (c *StaffAssessController) ListTargetUserMeSupperAssess() {
//获取周期列表
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)
}
... ... @@ -311,3 +303,20 @@ func (c *StaffAssessController) ListAssessCycleDay() {
data, err := srv.ListAllAssessCycleDay(paramReq)
c.Response(data, err)
}
//根据周期里的考核日期,获取员工填写评估内容列表
func (c *StaffAssessController) ListAssessContentCycleDay() {
srv := service.NewStaffAssessServeice()
paramReq := &query.ListAssessContentCycleDay{}
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)
paramReq.OperaterId = int(userReq.UserId)
data, err := srv.ListUserAssessContentCycleDay(paramReq)
c.Response(data, err)
}
... ...
... ... @@ -10,11 +10,12 @@ import (
func init() {
assessTaskNS := web.NewNamespace("/v1/staff-assess-task",
web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken()),
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), //获取周期中的考核日期
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), //获取周期中的考核日期
web.NSCtrlPost("/cycle/day/content", (*controllers.StaffAssessController).ListAssessContentCycleDay), //根据周期里的考核日期,获取员工填写评估内容列表
)
// /v1/staff-assess/self/me/list
assessNS := web.NewNamespace("/v1/staff-assess",
... ...