123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- /*
- * @description: 项目设置相关--管理员可访问
- * @Author: CP
- * @Date: 2020-10-09 10:35:38
- * @FilePath: \construction_management\web\api\project_setting.go
- */
- package api
- import (
- "fmt"
- "github.com/iris-contrib/middleware/csrf"
- "github.com/kataras/iris/v12"
- "go.mod/services"
- "go.mod/web/utils"
- "go.mod/web/viewmodels"
- )
- type ProjectSettingApi struct {
- //框架-web应用上下文环境
- Ctx iris.Context
- // 需要用的service
- ServiceProjectAccount services.ProjectAccountService
- }
- // @Summary 获得项目账号列表
- // @Tags 项目设置-管理员
- // @Description id获得单条信息<br/>name模糊检索
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param id body string false "账号ID"
- // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/projectSetting/account [get]
- func (c *ProjectSettingApi) GetAccount() {
- // 获得项目ID
- projectIdInt, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- // 获得账号ID
- AccountData := viewmodels.ProjectAccount{}
- err = c.Ctx.ReadJSON(&AccountData)
- if err != nil {
- // 获得所有项目下的账号
- dataList := c.ServiceProjectAccount.GetAll(projectIdInt)
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "",
- "data": dataList,
- })
- } else {
- // 获得单个账号ID
- id, err := utils.GetDecryptId(AccountData.Id)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- accountData := c.ServiceProjectAccount.Get(id, projectIdInt)
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "",
- "data": accountData,
- })
- }
- }
- // @Summary 检索账号信息
- // @Tags 项目设置-管理员
- // @Description 检索字段:账号 姓名 单位 手机 前匹配
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param name body string true "检索内容"
- // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/projectSetting/account/search [get]
- func (c *ProjectSettingApi) GetAccountSearch() {
- // 获得项目ID
- projectIdInt, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- c.Ctx.Header("X-CSRF-Token", csrf.Token(c.Ctx))
- fmt.Println(c.Ctx.GetHeader("X-CSRF-Token"))
- fmt.Println(csrf.Token(c.Ctx))
- // 获得检索关键字
- AccountData := viewmodels.ProjectAccount{}
- err = c.Ctx.ReadJSON(&AccountData)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("JSON转换异常, error=%s", err)})
- return
- }
- // 检索
- dataList := c.ServiceProjectAccount.Search(AccountData.Name, projectIdInt)
- c.Ctx.JSON(iris.Map{
- "code": 0, "msg": "",
- "data": dataList,
- })
- }
- // @Summary 新增账号
- // @Tags 项目设置-管理员
- // @Description 新增账号
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param account body string true "账号"
- // @Param password body string true "密码"
- // @Param name body string true "姓名"
- // @Param company body string true "公司"
- // @Param position body string true "职位"
- // @Param mobile body string true "手机"
- // @Param telephone body string true "座机"
- // @Param accountGroup body string true "账号组"
- // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/projectSetting/account/add [post]
- func (c *ProjectSettingApi) PostAccountAdd() {
- ErrMsg := ""
- // 验证内容
- AccountData, err := c.ServiceProjectAccount.ValidRule(c.Ctx)
- if err != nil {
- ErrMsg = utils.FormValidError(err)
- c.Ctx.JSON(iris.Map{"code": -1, "msg": ErrMsg})
- return
- } else {
- // 新增账号信息
- err := c.ServiceProjectAccount.Add(AccountData)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- c.Ctx.JSON(iris.Map{"code": 0, "msg": "新增成功"})
- }
- }
|