123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- /*
- * @description: 项目账号相关
- * @Author: CP
- * @Date: 2020-09-25 14:42:31
- * @FilePath: \construction_management\web\api\project_account_api.go
- */
- package api
- import (
- "fmt"
- "github.com/kataras/iris/v12"
- "go.mod/services"
- "go.mod/web/utils"
- "go.mod/web/viewmodels"
- )
- type ProjectAccountApi struct {
- //框架-web应用上下文环境
- Ctx iris.Context
- // 需要用的service
- ServiceProjectAccount services.ProjectAccountService
- }
- // @Summary 获得登陆账号信息相关
- // @Tags 项目账号相关
- // @Description 获得登陆账号相关信息
- // @Security ApiKeyAuth
- // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/projectAccount [get]
- func (c *ProjectAccountApi) Get() {
- // 获得项目账号ID
- projectAccountIdInt, err := utils.GetProjectAccountId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- // 获得项目ID
- projectIdInt, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- // 获得登陆用户
- AccountData := c.ServiceProjectAccount.Get(projectAccountIdInt, projectIdInt)
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "",
- "data": AccountData,
- })
- }
- // @Summary 获得项目账号列表
- // @Tags 项目账号相关
- // @Description 获得项目账号列表
- // @Security ApiKeyAuth
- // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/projectAccount/list [get]
- func (c *ProjectAccountApi) GetList() {
- // 获得项目ID
- projectIdInt, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- AccountData := c.ServiceProjectAccount.GetAll(projectIdInt)
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "",
- "data": AccountData,
- })
- }
- // @Summary 获得项目账号组
- // @Tags 项目账号相关
- // @Description 获得项目账号组
- // @Security ApiKeyAuth
- // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/projectAccount/group [get]
- func (c *ProjectAccountApi) GetGroup() {
- // 获得检索关键字
- // 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
- // }
- // 获得项目ID
- // projectId, err := utils.GetProjectId(c.Ctx)
- // if err != nil {
- // c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- // return
- // }
- // accountData := c.ServiceProjectAccount.GetAll(projectId)
- // 检索
- // accountData := c.ServiceProjectAccount.Search(AccountData.Name, projectId)
- groupDate := utils.GetAccountGroup()
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "",
- "data": groupDate,
- // "accountData": 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/projectAccount/search [get]
- func (c *ProjectAccountApi) GetSearch() {
- // 获得项目ID
- projectIdInt, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- // 获得检索关键字
- 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 id body string true "账号ID" default(PcqqGsn1O0jBSmLqkuOTwQ)
- // @Param name body string true "姓名"
- // @Param company body string true "公司"
- // @Param position body string true "职位"
- // @Param telephone body string true "座机"
- // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
- // @Router /api/projectAccount/account/save [post]
- func (c *ProjectAccountApi) PostAccountSave() {
- // 验证内容
- AccountData, err := c.ServiceProjectAccount.ValidRuleAccount(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.SaveAccount(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 password body string true "密码"
- // @Param newPassword body string true "新密码"
- // @Param confirmPassword body string true "确认新密码"
- // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
- // @Router /api/projectAccount/change/password [post]
- func (c *ProjectAccountApi) PostChangePassword() {
- // 验证内容
- AccountData, err := c.ServiceProjectAccount.ValidRuleChangePassword(c.Ctx)
- if err != nil {
- ErrMsg := utils.FormValidError(err)
- c.Ctx.JSON(iris.Map{"code": -1, "msg": ErrMsg})
- return
- } else {
- if AccountData.ConfirmPassword != AccountData.NewPassword {
- 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": fmt.Sprintf("%s", err)})
- return
- }
- // 获得项目账号ID
- projectAccountId, err := utils.GetProjectAccountId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- err = c.ServiceProjectAccount.ChangePassword(AccountData, projectId, projectAccountId)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- c.Ctx.JSON(iris.Map{"code": 0, "msg": "更新成功"})
- }
- }
- // 获得登陆账号信息
- func (c *ProjectAccountApi) GetAccount() {
- var (
- accountId int
- projectId int
- err error
- accountData *viewmodels.ProjectAccount
- )
- if accountId, err = utils.GetProjectAccountId(c.Ctx); err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- if projectId, err = utils.GetProjectId(c.Ctx); err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- fmt.Println(accountId)
- accountData = c.ServiceProjectAccount.Get(accountId, projectId)
- if accountData.Id == "0" {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "",
- "data": accountData,
- })
- }
|