fix: 班级学生查询改sql方式放入应用申请部分
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/vo/result"
|
||||
systemModel "be.ems/src/modules/system/model"
|
||||
systemService "be.ems/src/modules/system/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// NewPtClass 实例化控制层
|
||||
var NewPtClass = &PtClass{
|
||||
sysUserService: systemService.NewSysUserImpl,
|
||||
}
|
||||
|
||||
// 班级信息数据
|
||||
//
|
||||
// PATH /class
|
||||
type PtClass struct {
|
||||
// 用户服务
|
||||
sysUserService systemService.ISysUser
|
||||
}
|
||||
|
||||
// 班级学生列表 (仅教师操作)
|
||||
//
|
||||
// GET /students
|
||||
func (s *PtClass) Students(c *gin.Context) {
|
||||
querys := ctx.QueryMap(c)
|
||||
dataScopeSQL := ctx.LoginUserToDataScopeSQL(c, "d", "u")
|
||||
data := s.sysUserService.SelectUserPage(querys, dataScopeSQL)
|
||||
|
||||
total := parse.Number(data["total"])
|
||||
rows := make([]map[string]any, 0)
|
||||
for _, v := range data["rows"].([]systemModel.SysUser) {
|
||||
if len(v.Roles) == 0 {
|
||||
total--
|
||||
continue
|
||||
}
|
||||
if v.Roles[0].RoleKey != "student" {
|
||||
total--
|
||||
continue
|
||||
}
|
||||
rows = append(rows, map[string]any{
|
||||
"userId": v.UserID,
|
||||
"userName": v.UserName,
|
||||
"nickName": v.NickName,
|
||||
"loginIp": v.LoginIP,
|
||||
"loginDate": v.LoginDate,
|
||||
})
|
||||
}
|
||||
data["total"] = total
|
||||
data["rows"] = rows
|
||||
|
||||
c.JSON(200, result.Ok(data))
|
||||
}
|
||||
@@ -66,6 +66,10 @@ func Setup(router *gin.Engine) {
|
||||
// 网元参数配置应用申请
|
||||
neConfigApplyGroup := ptGroup.Group("/neConfigApply")
|
||||
{
|
||||
neConfigApplyGroup.GET("/students",
|
||||
middleware.PreAuthorize(map[string][]string{"hasRoles": {"teacher"}}),
|
||||
controller.NewPtNeConfigApply.Students,
|
||||
)
|
||||
neConfigApplyGroup.GET("/list",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewPtNeConfigApply.List,
|
||||
@@ -81,13 +85,4 @@ func Setup(router *gin.Engine) {
|
||||
controller.NewPtNeConfigApply.Edit,
|
||||
)
|
||||
}
|
||||
|
||||
// 班级信息数据
|
||||
classGroup := ptGroup.Group("/class")
|
||||
{
|
||||
classGroup.GET("/students",
|
||||
middleware.PreAuthorize(map[string][]string{"hasRoles": {"teacher"}}),
|
||||
controller.NewPtClass.Students,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,7 @@ type IPtNeConfigApplyRepository interface {
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(paramIds []string) int64
|
||||
|
||||
// SelectListByClass 查询班级学生信息
|
||||
SelectListByClass(deptId, userName string) []map[string]any
|
||||
}
|
||||
|
||||
@@ -239,3 +239,37 @@ func (r *PtNeConfigApplyRepository) DeleteByIds(paramIds []string) int64 {
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
// SelectListByClass 查询班级学生信息
|
||||
func (r *PtNeConfigApplyRepository) SelectListByClass(deptId, userName string) []map[string]any {
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if deptId != "" {
|
||||
conditions = append(conditions, "d.dept_id = ?")
|
||||
params = append(params, deptId)
|
||||
}
|
||||
if userName != "" {
|
||||
conditions = append(conditions, "u.user_name = ?")
|
||||
params = append(params, userName)
|
||||
}
|
||||
// 构建查询条件语句
|
||||
whereSql := " where u.del_flag = '0' AND u.user_id != '1' AND ur.role_id = '4' "
|
||||
if len(conditions) > 0 {
|
||||
whereSql += " and " + strings.Join(conditions, " and ")
|
||||
}
|
||||
// 查询数据
|
||||
querySql := `SELECT
|
||||
u.user_Id as userId, u.user_name as userName, u.nick_name as nickName, u.login_ip as loginIp, u.login_date AS loginDate,
|
||||
COALESCE(pnca.status, '') as applyStatus
|
||||
FROM sys_user u
|
||||
LEFT JOIN sys_dept d ON u.dept_id = d.dept_id
|
||||
LEFT JOIN sys_user_role ur ON u.user_id = ur.user_id
|
||||
LEFT JOIN pt_ne_config_apply pnca ON pnca.create_by = u.user_name AND pnca.status = '0'
|
||||
` + whereSql
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
logger.Errorf("query err => %v", err)
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
@@ -23,4 +23,7 @@ type IPtNeConfigApplyService interface {
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(paramIds []string) (int64, error)
|
||||
|
||||
// SelectListByClass 查询班级学生信息
|
||||
SelectListByClass(deptId, userName string) []map[string]any
|
||||
}
|
||||
|
||||
@@ -65,3 +65,8 @@ func (r *PtNeConfigApplyService) DeleteByIds(paramIds []string) (int64, error) {
|
||||
// 删除信息失败!
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
|
||||
// SelectListByClass 查询班级学生信息
|
||||
func (r *PtNeConfigApplyService) SelectListByClass(deptId, userName string) []map[string]any {
|
||||
return r.ptNeConfigApplyRepository.SelectListByClass(deptId, userName)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user