123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- /*
- * @description: 项目设置相关--管理员可访问
- * @Author: CP
- * @Date: 2020-10-09 10:35:38
- * @FilePath: \construction_management\web\api\project_setting_api.go
- */
- package api
- import (
- "fmt"
- "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
- ServiceProject services.ProjectService
- ServiceBidAccount services.BidAccountService
- }
- // @Summary 获得项目账号列表
- // @Tags 项目设置-管理员
- // @Description id获得单条信息<br/>
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param id body string false "账号ID"
- // @Success 200 {object} viewmodels.ProjectAccount "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,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 {object} viewmodels.ProjectAccount "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,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))
- // 获得检索关键字
- AccountData := viewmodels.ProjectAccount{}
- err = c.Ctx.ReadForm(&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 role body int true "角色ID"
- // @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 int true "账号组"
- // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
- // @Router /api/projectSetting/account/create [post]
- func (c *ProjectSettingApi) PostAccountCreate() {
- ErrMsg := ""
- // 验证内容
- AccountData, err := c.ServiceProjectAccount.ValidRule(c.Ctx)
- if err != nil {
- ErrMsg = utils.FormValidError(err)
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", ErrMsg)})
- return
- } else {
- projectId, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- // 新增账号信息
- err = c.ServiceProjectAccount.Add(AccountData, projectId)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- c.Ctx.JSON(iris.Map{"code": 0, "msg": "新增成功"})
- }
- }
- // @Summary 编辑账号
- // @Tags 项目设置-管理员
- // @Description 编辑账号
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param id body string true "账号ID" default(PcqqGsn1O0jBSmLqkuOTwQ)
- // @Param role body int true "角色ID"
- // @Param name body string true "姓名"
- // @Param company body string true "公司"
- // @Param position body string true "职位"
- // @Param telephone body string true "座机"
- // @Param accountGroup body int true "账号组"
- // @Param X-CSRF-Token header string true "csrf"
- // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
- // @Router /api/projectSetting/account/save [post]
- func (c *ProjectSettingApi) PostAccountSave() {
- // 验证内容
- 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 {
- // 获得更新账号ID
- id, err := utils.GetDecryptId(AccountData.Id)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- projectId, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- err = c.ServiceProjectAccount.Save(AccountData, id, projectId)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- c.Ctx.JSON(iris.Map{"code": 0, "msg": "编辑成功"})
- }
- }
- // @Summary 账号启用/禁用
- // @Tags 项目设置-管理员
- // @Description 账号启用/禁用
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param id body string true "账号ID" default(PcqqGsn1O0jBSmLqkuOTwQ)
- // @Param enable body int true "启用/禁用"
- // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
- // @Router /api/projectSetting/account/enable [post]
- func (c *ProjectSettingApi) PostAccountEnable() {
- // 修改验证方式——TODO
- accountVaild := viewmodels.ProjectAccount{}
- err := c.Ctx.ReadJSON(&accountVaild)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "参数错误"})
- return
- }
- // 账号ID校验
- id, err := utils.GetDecryptId(accountVaild.Id)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "账号异常"})
- return
- }
- // 项目ID
- projectId, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "账号异常"})
- return
- }
- err = c.ServiceProjectAccount.Enable(id, projectId, accountVaild.Enable)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- c.Ctx.JSON(iris.Map{"code": 0, "msg": "操作成功"})
- }
- // @Summary 删除账号
- // @Tags 项目设置-管理员
- // @Description 删除账号
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param id body string true "账号ID" default(PcqqGsn1O0jBSmLqkuOTwQ)
- // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
- // @Router /api/projectSetting/account/delete [post]
- func (c *ProjectSettingApi) PostAccountDelete() {
- accountVaild := viewmodels.ProjectAccount{}
- err := c.Ctx.ReadJSON(&accountVaild)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "参数错误"})
- return
- }
- // 账号ID校验
- id, err := utils.GetDecryptId(accountVaild.Id)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "账号异常"})
- return
- }
- // 项目ID
- projectId, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "账号异常"})
- return
- }
- err = c.ServiceProjectAccount.Delete(id, projectId)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- c.Ctx.JSON(iris.Map{"code": 0, "msg": "操作成功"})
- }
- // @Summary 设置账号密码
- // @Tags 项目设置-管理员
- // @Description 设置账号密码
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param id body string true "账号ID" default(PcqqGsn1O0jBSmLqkuOTwQ)
- // @Param account body string true "账号" default(textoopd)
- // @Param password body string true "密码" default(ww123456)
- // @Param X-CSRF-Token header string true "csrf"
- // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
- // @Router /api/projectSetting/account/change [post]
- func (c *ProjectSettingApi) PostAccountChange() {
- // 验证内容
- 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 {
- // 获得更新账号ID
- id, err := utils.GetDecryptId(AccountData.Id)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- projectId, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- err = c.ServiceProjectAccount.ChangeAccount(id, projectId, 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": "编辑成功"})
- }
- }
- // @Summary 获取项目信息
- // @Tags 项目设置-管理员
- // @Description 获取项目信息
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
- // @Router /api/projectSetting/project [get]
- func (c *ProjectSettingApi) GetProject() {
- projectId, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- projectdata, err := c.ServiceProject.Get(projectId)
- userId, _ := utils.GetDecryptId(projectdata.UserId)
- accountData := c.ServiceProjectAccount.Get(userId, projectId)
- data := make(map[string]interface{})
- data["project"] = projectdata
- data["account"] = accountData
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- } else {
- c.Ctx.JSON(iris.Map{"code": 0, "msg": "操作成功", "data": data})
- }
- }
- // @Summary 保存项目信息
- // @Tags 项目设置-管理员
- // @Description 保存项目信息
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param name body string true "账号ID" default(红旗大桥)
- // @Param X-CSRF-Token header string true "csrf"
- // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
- // @Router /api/projectSetting/project/save [post]
- func (c *ProjectSettingApi) PostProjectSave() {
- ProjectData, err := c.ServiceProject.ValidRule(c.Ctx)
- if err != nil {
- ErrMsg := utils.FormValidError(err)
- c.Ctx.JSON(iris.Map{"code": -1, "msg": ErrMsg})
- return
- } else {
- // 项目ID
- projectId, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "账号异常"})
- return
- }
- err = c.ServiceProject.Save(projectId, ProjectData)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- c.Ctx.JSON(iris.Map{"code": 0, "msg": "操作成功"})
- }
- }
|