|
@@ -0,0 +1,173 @@
|
|
|
|
+package assessment_researcher
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "encoding/json"
|
|
|
|
+ "eta/eta_api/controllers"
|
|
|
|
+ "eta/eta_api/models"
|
|
|
|
+ "eta/eta_api/models/system"
|
|
|
|
+ "eta/eta_api/utils"
|
|
|
|
+ "fmt"
|
|
|
|
+ "time"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+// AssessmentResearcherController 考核研究员
|
|
|
|
+type AssessmentResearcherController struct {
|
|
|
|
+ controllers.BaseAuthController
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// Add
|
|
|
|
+// @Title 新增研究员
|
|
|
|
+// @Description 新增研究员
|
|
|
|
+// @Param request body models.AssessmentResearcherAddReq true "type json string"
|
|
|
|
+// @Success 200 string "操作成功"
|
|
|
|
+// @router /add [post]
|
|
|
|
+func (this *AssessmentResearcherController) Add() {
|
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
|
+ defer func() {
|
|
|
|
+ if br.ErrMsg == "" {
|
|
|
|
+ br.IsSendEmail = false
|
|
|
|
+ }
|
|
|
|
+ this.Data["json"] = br
|
|
|
|
+ this.ServeJSON()
|
|
|
|
+ }()
|
|
|
|
+ sysUser := this.SysUser
|
|
|
|
+ if sysUser == nil {
|
|
|
|
+ br.Msg = "请登录"
|
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
|
+ br.Ret = 408
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ var req models.AssessmentResearcherAddReq
|
|
|
|
+ if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
|
|
|
|
+ br.Msg = "参数有误"
|
|
|
|
+ br.ErrMsg = fmt.Sprintf("参数解析失败, %v", e)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if req.AdminId <= 0 {
|
|
|
|
+ br.Msg = "请选择研究员"
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 检验是否已添加过
|
|
|
|
+ researcherOb := new(models.AssessmentResearcher)
|
|
|
|
+ {
|
|
|
|
+ cond := fmt.Sprintf(` AND %s = ?`, researcherOb.Cols().AdminId)
|
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
|
+ pars = append(pars, req.AdminId)
|
|
|
|
+ exists, e := researcherOb.GetItemByCondition(cond, pars, "")
|
|
|
|
+ if e != nil && !utils.IsErrNoRow(e) {
|
|
|
|
+ br.Msg = "操作失败"
|
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取研究员失败, %v", e)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if exists != nil && exists.AssessmentResearcherId > 0 {
|
|
|
|
+ br.Msg = "该研究员已添加,请勿重复添加"
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ sysAdmin, e := system.GetSysAdminById(req.AdminId)
|
|
|
|
+ if e != nil {
|
|
|
|
+ if utils.IsErrNoRow(e) {
|
|
|
|
+ br.Msg = "该用户不存在,请重新选择"
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ br.Msg = "操作失败"
|
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取系统用户失败, %v", e)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if sysAdmin.Enabled != 1 {
|
|
|
|
+ br.Msg = "该用户被禁用,请重新选择"
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ newResearcher := new(models.AssessmentResearcher)
|
|
|
|
+ newResearcher.AdminId = req.AdminId
|
|
|
|
+ newResearcher.RealName = sysUser.RealName
|
|
|
|
+ newResearcher.Enabled = sysUser.Enabled
|
|
|
|
+ newResearcher.CreateTime = time.Now().Local()
|
|
|
|
+ newResearcher.ModifyTime = time.Now().Local()
|
|
|
|
+ if e = newResearcher.Create(); e != nil {
|
|
|
|
+ br.Msg = "操作失败"
|
|
|
|
+ br.ErrMsg = fmt.Sprintf("新增研究员失败, %v", e)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 查看/统计权限
|
|
|
|
+ mappings := make([]*models.AssessmentResearcherAdminMapping, 0)
|
|
|
|
+ if len(req.ViewAdminIds) > 0 {
|
|
|
|
+ for _, v := range req.ViewAdminIds {
|
|
|
|
+ m := new(models.AssessmentResearcherAdminMapping)
|
|
|
|
+ m.AdminId = req.AdminId
|
|
|
|
+ m.AuthAdminId = v
|
|
|
|
+ m.AuthType = models.AssessmentResearcherAdminAuthTypeView
|
|
|
|
+ mappings = append(mappings, m)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if len(req.AssessmentAdminIds) > 0 {
|
|
|
|
+ for _, v := range req.AssessmentAdminIds {
|
|
|
|
+ m := new(models.AssessmentResearcherAdminMapping)
|
|
|
|
+ m.AdminId = req.AdminId
|
|
|
|
+ m.AuthAdminId = v
|
|
|
|
+ m.AuthType = models.AssessmentResearcherAdminAuthTypeStatistics
|
|
|
|
+ mappings = append(mappings, m)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ mappingOb := new(models.AssessmentResearcherAdminMapping)
|
|
|
|
+ if e = mappingOb.CreateMulti(mappings); e != nil {
|
|
|
|
+ br.Msg = "操作失败"
|
|
|
|
+ br.ErrMsg = fmt.Sprintf("批量新增权限失败, %v", e)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ br.Ret = 200
|
|
|
|
+ br.Success = true
|
|
|
|
+ br.Msg = "操作成功"
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// Detail
|
|
|
|
+// @Title 新增研究员
|
|
|
|
+// @Description 新增研究员
|
|
|
|
+// @Param request body models.AssessmentResearcherAddReq true "type json string"
|
|
|
|
+// @Success 200 string "操作成功"
|
|
|
|
+// @router /add [post]
|
|
|
|
+func (this *AssessmentResearcherController) Detail() {
|
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
|
+ defer func() {
|
|
|
|
+ if br.ErrMsg == "" {
|
|
|
|
+ br.IsSendEmail = false
|
|
|
|
+ }
|
|
|
|
+ this.Data["json"] = br
|
|
|
|
+ this.ServeJSON()
|
|
|
|
+ }()
|
|
|
|
+ sysUser := this.SysUser
|
|
|
|
+ if sysUser == nil {
|
|
|
|
+ br.Msg = "请登录"
|
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
|
+ br.Ret = 408
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ researcherId, _ := this.GetInt("ResearcherId")
|
|
|
|
+ if researcherId <= 0 {
|
|
|
|
+ br.Msg = "参数有误"
|
|
|
|
+ br.ErrMsg = fmt.Sprintf("参数有误, ResearcherId: %d", researcherId)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ researcherOb := new(models.AssessmentResearcher)
|
|
|
|
+ researcher, e := researcherOb.GetItemById(researcherId)
|
|
|
|
+ if e != nil {
|
|
|
|
+ if utils.IsErrNoRow(e) {
|
|
|
|
+ br.Msg = "研究员不存在,请重新页面"
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ br.Msg = "获取失败"
|
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取研究员失败, %v", e)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ mappingOb := new(models.AssessmentResearcherAdminMapping)
|
|
|
|
+
|
|
|
|
+ br.Ret = 200
|
|
|
|
+ br.Success = true
|
|
|
|
+ br.Msg = "获取成功"
|
|
|
|
+}
|