1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package eta_trial
- import (
- "fmt"
- "github.com/gin-gonic/gin"
- "github.com/go-playground/validator/v10"
- "hongze/hz_crm_eta/controller/resp"
- "hongze/hz_crm_eta/global"
- edbTrialModel "hongze/hz_crm_eta/models/eta_trial"
- "time"
- )
- // CreateManualAuth
- // @Description 新增手工录入权限
- // @Success 200 {string} string "操作成功"
- // @Router /eta_trial/manual_user/add_auth [post]
- func (a *EtaTrialController) CreateManualAuth(c *gin.Context) {
- var req edbTrialModel.CreateManualAuthReq
- err := c.Bind(&req)
- if err != nil {
- errs, ok := err.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
- return
- }
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
- return
- }
- if req.AdminId <= 0 {
- resp.FailData("参数有误", fmt.Sprintf("CreateManualAuth参数有误, AdminId: %d", req.AdminId), c)
- return
- }
- // 从ETA试用平台的edb库中读取手工数据分类
- classifyIds := make([]int, 0)
- {
- classifyOb := new(edbTrialModel.EdbdataClassify)
- cond := `is_show = 1`
- pars := make([]interface{}, 0)
- list, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "")
- if e != nil {
- resp.FailData("操作失败", "获取手工数据分类失败, Err: "+e.Error(), c)
- return
- }
- for _, v := range list {
- classifyIds = append(classifyIds, v.ClassifyId)
- }
- }
- // 新增用户及权限
- manualUser := new(edbTrialModel.ManualUser)
- manualUser.AdminId = req.AdminId
- manualUser.AdminRealName = req.AdminName
- manualUser.CreateTime = time.Now().Local()
- if e := manualUser.Create(); e != nil {
- resp.FailData("操作失败", "新增权限用户失败, Err: "+e.Error(), c)
- return
- }
- userClassifies := make([]*edbTrialModel.ManualUserClassify, 0)
- for _, v := range classifyIds {
- userClassifies = append(userClassifies, &edbTrialModel.ManualUserClassify{
- AdminId: req.AdminId,
- ClassifyId: v,
- CreateTime: time.Now().Local(),
- })
- }
- userClassifyOb := new(edbTrialModel.ManualUserClassify)
- if e := userClassifyOb.BatchCreate(userClassifies); e != nil {
- resp.FailData("操作失败", "批量新增权限用户分类失败, Err: "+e.Error(), c)
- return
- }
- resp.OkData("操作成功", "", c)
- }
|