|
@@ -0,0 +1,402 @@
|
|
|
+/*
|
|
|
+ * @description: 项目设置相关--管理员可访问
|
|
|
+ * @Author: CP
|
|
|
+ * @Date: 2020-10-09 10:35:38
|
|
|
+ * @FilePath: \construction_management\web\backstage\project_account_bs.go
|
|
|
+ */
|
|
|
+package backstage
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+
|
|
|
+ "github.com/kataras/iris/v12"
|
|
|
+ "go.mod/services"
|
|
|
+ "go.mod/web/utils"
|
|
|
+ "go.mod/web/viewmodels"
|
|
|
+)
|
|
|
+
|
|
|
+type ProjectAccountBs struct {
|
|
|
+ //框架-web应用上下文环境
|
|
|
+ Ctx iris.Context
|
|
|
+ // 需要用的service
|
|
|
+ ServiceProjectAccount services.ProjectAccountService
|
|
|
+ ServiceProject services.ProjectService
|
|
|
+ ServiceBidAccount services.BidAccountService
|
|
|
+ ServiceBackstage services.BackstageService
|
|
|
+}
|
|
|
+
|
|
|
+// @Summary 获得项目账号列表
|
|
|
+// @Tags 后台 - 项目账号
|
|
|
+// @Description id获得单条信息<br/>projectId必须传
|
|
|
+// @Accept json
|
|
|
+// @Produce json
|
|
|
+// @Security ApiKeyAuth
|
|
|
+// @Param id body string false "账号ID"
|
|
|
+// @Param projectId body string false "项目ID"
|
|
|
+// @Success 200 {object} viewmodels.ProjectAccount "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
|
|
|
+// @Router /backstage/account [get]
|
|
|
+func (c *ProjectAccountBs) Get() {
|
|
|
+
|
|
|
+ accountData, err := c.ServiceProjectAccount.ValidRuleProjectId(c.Ctx)
|
|
|
+ if err != nil {
|
|
|
+ c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获得项目ID
|
|
|
+ projectIdInt, err := utils.GetDecryptId(accountData.ProjectId)
|
|
|
+ if err != nil {
|
|
|
+ c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if accountData.Id == "" {
|
|
|
+ // 获得所有项目下的账号
|
|
|
+ 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 "检索内容"
|
|
|
+// @Param projectId body string false "项目ID"
|
|
|
+// @Success 200 {object} viewmodels.ProjectAccount "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
|
|
|
+// @Router /backstage/account/search [get]
|
|
|
+func (c *ProjectAccountBs) GetSearch() {
|
|
|
+ accountData, err := c.ServiceProjectAccount.ValidRuleProjectId(c.Ctx)
|
|
|
+ if err != nil {
|
|
|
+ c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获得项目ID
|
|
|
+ projectIdInt, err := utils.GetDecryptId(accountData.ProjectId)
|
|
|
+ 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 projectId body string true "项目ID"
|
|
|
+// @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 /backstage/account/create [post]
|
|
|
+func (c *ProjectAccountBs) PostCreate() {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ // 项目ID
|
|
|
+ if AccountData.ProjectId == "" {
|
|
|
+ c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目ID必填"})
|
|
|
+ }
|
|
|
+ projectId, err := utils.GetDecryptId(AccountData.ProjectId)
|
|
|
+ if err != nil {
|
|
|
+ c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 是否有该项目
|
|
|
+ _, err = c.ServiceProject.Get(projectId)
|
|
|
+ if err != nil {
|
|
|
+ c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目不存在"})
|
|
|
+ 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 projectId body string true "项目ID"
|
|
|
+// @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 /backstage/account/save [post]
|
|
|
+func (c *ProjectAccountBs) PostSave() {
|
|
|
+
|
|
|
+ // TODO
|
|
|
+
|
|
|
+ // 验证内容
|
|
|
+ AccountData, err := c.ServiceProjectAccount.ValidRule(c.Ctx)
|
|
|
+ if err != nil {
|
|
|
+ ErrMsg := utils.FormValidError(err)
|
|
|
+ c.Ctx.JSON(iris.Map{"code": -1, "msg": ErrMsg})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 获得更新账号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 /backstage/account/enable [post]
|
|
|
+func (c *ProjectAccountBs) PostEnable() {
|
|
|
+ // 修改验证方式——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 /backstage/account/delete [post]
|
|
|
+func (c *ProjectAccountBs) PostDelete() {
|
|
|
+ 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 /backstage/account/change [post]
|
|
|
+func (c *ProjectAccountBs) PostChange() {
|
|
|
+ // 验证内容
|
|
|
+ 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 /backstage/account/project [get]
|
|
|
+// func (c *ProjectAccountBs) 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 /backstage/account/project/save [post]
|
|
|
+// func (c *ProjectAccountBs) 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": "操作成功"})
|
|
|
+// }
|
|
|
+// }
|