| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 | /* * @description:项目设置-权限管理 * @Author: CP * @Date: 2020-10-20 15:47:07 * @FilePath: \construction_management\web\api\project_setting_auth_api.go */package apiimport (	"fmt"	"github.com/kataras/iris/v12"	"go.mod/web/utils"	"go.mod/web/viewmodels")// @Summary 获得标段账号// @Tags 项目设置-标段成员权限-管理员// @Description 获得标段账号// @Accept  json// @Produce  json// @Security ApiKeyAuth// @Param   bidsectionId     path    string     false        "标段ID"// @Param   name     path    string     false        "账号名称"// @Success 200 {object} viewmodels.ProjectAccount "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"// @Router /api/projectSetting/bid/account [get]func (c *ProjectSettingApi) GetBidAccount() {	// 获得标段ID	TreeData := viewmodels.ProjectAccount{}	err := c.Ctx.ReadForm(&TreeData)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})		return	}	if TreeData.BidsectionId == "" {		c.Ctx.JSON(iris.Map{"code": -1, "msg": "标段ID不能为空"})		return	}	// 解密标段ID	bidsectionId, err := utils.GetDecryptId(TreeData.BidsectionId)	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	}	// 获得项目账号ID	projectAccountIdInt, err := utils.GetProjectAccountId(c.Ctx)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})		return	}	dataList := c.ServiceProjectAccount.GetBidAccount(bidsectionId, projectIdInt, projectAccountIdInt, TreeData.Name)	c.Ctx.JSON(iris.Map{		"code": 0,		"msg":  "",		"data": dataList,	})}// @Summary 标段中添加成员-账号// @Tags 项目设置-标段成员权限-管理员// @Description 标段中添加成员-账号// @Accept  json// @Produce  json// @Security ApiKeyAuth// @Param   bidsectionId     body    string     false        "标段ID"// @Param   accountId     body    string     false        "账号ID"// @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"// @Router /api/projectSetting/bid/account/create [post]func (c *ProjectSettingApi) PostBidAccountCreate() {	// 账号ID,标段ID,目录ID	BidAccountData, err := c.ServiceBidAccount.ValidRule(c.Ctx)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": utils.FormValidError(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	}	// 获得账号ID	accountId, err := utils.GetProjectAccountId(c.Ctx)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})		return	}	// 创建标段和账号的关系	err = c.ServiceBidAccount.Create(BidAccountData, projectIdInt, accountId)	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   bidsectionId     body    string     false        "标段ID"// @Param   accountId     body    string     false        "账号ID"// @Param   contractAdd    body    int     false        "合同创建 1拥有0不拥有"// @Param   contractDelete        body    int     false        "合同删除 1拥有0不拥有"// @Param   contractAccess        body    int     false        "合同查看 1拥有0不拥有"// @Param   safeAdd    body    int     false        "安全创建 1拥有0不拥有"// @Param   safeDelete        body    int     false        "安全删除 1拥有0不拥有"// @Param   safeAccess        body    int     false        "安全查看 1拥有0不拥有"// @Param   qualityAdd    body    int     false        "合同创建 1拥有0不拥有"// @Param   qualityDelete        body    int     false        "合同删除 1拥有0不拥有"// @Param   qualityAccess        body    int     false        "合同查看 1拥有0不拥有"// @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"// @Router /api/projectSetting/bid/account/auth [post]func (c *ProjectSettingApi) PostBidAccountAuth() {	// 1.验证消息	PermissionData, err := c.ServiceProjectAccount.ValidRulePermission(c.Ctx)	// 获得项目ID	projectId, err := utils.GetProjectId(c.Ctx)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})		return	}	// 账号ID	accountId, err := utils.GetDecryptId(PermissionData.AccountId)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})		return	}	bidsectionId, err := utils.GetDecryptId(PermissionData.BidsectionId)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})		return	}	// 保存设置的权限	err = c.ServiceProjectAccount.SaveAuth(PermissionData, projectId, bidsectionId, accountId)	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   bidsectionId     body    string     false        "标段ID"// @Param   accountId     body    string     false        "账号ID"// @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"// @Router /api/projectSetting/bid/account [delete]func (c *ProjectSettingApi) DeleteBidAccount() {	// 账号ID,标段ID	BidAccountData, err := c.ServiceBidAccount.ValidRuleDelete(c.Ctx)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": utils.FormValidError(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	}	// 创建标段和账号的关系	err = c.ServiceBidAccount.Delete(BidAccountData, projectIdInt)	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   bidsectionId     path    string     false        "标段ID"// @Success 200 {object} viewmodels.PermissionView "{code:0成功,-1参数类错误,data:viewmodels.PermissionView,msg:错误信息}"// @Router /api/projectSetting/permission [get]func (c *ProjectSettingApi) GetPermission() {	// 1.验证消息	PermissionData, err := c.ServiceProjectAccount.ValidGetPermission(c.Ctx)	// 账号ID	accountId, err := utils.GetProjectAccountId(c.Ctx)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})		return	}	bidsectionId, err := utils.GetDecryptId(PermissionData.BidsectionId)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})		return	}	// 获得项目ID	pid, err := utils.GetProjectId(c.Ctx)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})		return	}	data, err := c.ServiceBidAccount.GetPermission(accountId, bidsectionId, pid)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})		return	}	c.Ctx.JSON(iris.Map{		"code": 0,		"msg":  "请求成功",		"data": data,	})}
 |