project_account_api.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * @description: 项目账号相关
  3. * @Author: CP
  4. * @Date: 2020-09-25 14:42:31
  5. * @FilePath: \construction_management\web\api\project_account_api.go
  6. */
  7. package api
  8. import (
  9. "fmt"
  10. "github.com/kataras/iris/v12"
  11. "go.mod/services"
  12. "go.mod/web/utils"
  13. "go.mod/web/viewmodels"
  14. )
  15. type ProjectAccountApi struct {
  16. //框架-web应用上下文环境
  17. Ctx iris.Context
  18. // 需要用的service
  19. ServiceProjectAccount services.ProjectAccountService
  20. }
  21. // @Summary 获得登陆账号信息相关
  22. // @Tags 项目账号相关
  23. // @Description 获得登陆账号相关信息
  24. // @Security ApiKeyAuth
  25. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  26. // @Router /api/projectAccount [get]
  27. func (c *ProjectAccountApi) Get() {
  28. // 获得项目账号ID
  29. projectAccountIdInt, err := utils.GetProjectAccountId(c.Ctx)
  30. if err != nil {
  31. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  32. return
  33. }
  34. // 获得项目ID
  35. projectIdInt, err := utils.GetProjectId(c.Ctx)
  36. if err != nil {
  37. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  38. return
  39. }
  40. // 获得登陆用户
  41. AccountData := c.ServiceProjectAccount.Get(projectAccountIdInt, projectIdInt)
  42. c.Ctx.JSON(iris.Map{
  43. "code": 0,
  44. "msg": "",
  45. "data": AccountData,
  46. })
  47. }
  48. // @Summary 获得项目账号列表
  49. // @Tags 项目账号相关
  50. // @Description 获得项目账号列表
  51. // @Security ApiKeyAuth
  52. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  53. // @Router /api/projectAccount/list [get]
  54. func (c *ProjectAccountApi) GetList() {
  55. // 获得项目ID
  56. projectIdInt, err := utils.GetProjectId(c.Ctx)
  57. if err != nil {
  58. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  59. return
  60. }
  61. AccountData := c.ServiceProjectAccount.GetAll(projectIdInt)
  62. c.Ctx.JSON(iris.Map{
  63. "code": 0,
  64. "msg": "",
  65. "data": AccountData,
  66. })
  67. }
  68. // @Summary 获得项目账号组
  69. // @Tags 项目账号相关
  70. // @Description 获得项目账号组
  71. // @Security ApiKeyAuth
  72. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  73. // @Router /api/projectAccount/group [get]
  74. func (c *ProjectAccountApi) GetGroup() {
  75. // 获得检索关键字
  76. // AccountData := viewmodels.ProjectAccount{}
  77. // err := c.Ctx.ReadForm(&AccountData)
  78. // if err != nil {
  79. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("JSON转换异常, error=%s", err)})
  80. // return
  81. // }
  82. // 获得项目ID
  83. // projectId, err := utils.GetProjectId(c.Ctx)
  84. // if err != nil {
  85. // c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  86. // return
  87. // }
  88. // accountData := c.ServiceProjectAccount.GetAll(projectId)
  89. // 检索
  90. // accountData := c.ServiceProjectAccount.Search(AccountData.Name, projectId)
  91. groupDate := map[int]string{
  92. 1: "建设单位",
  93. 2: "监理单位",
  94. 3: "施工单位",
  95. 4: "设计单位",
  96. }
  97. c.Ctx.JSON(iris.Map{
  98. "code": 0,
  99. "msg": "",
  100. "data": groupDate,
  101. // "accountData": accountData,
  102. })
  103. }
  104. // @Summary 检索账号信息
  105. // @Tags 项目账号相关
  106. // @Description 检索字段:账号 姓名 单位 手机 前匹配
  107. // @Accept json
  108. // @Produce json
  109. // @Security ApiKeyAuth
  110. // @Param name body string true "检索内容"
  111. // @Success 200 {object} viewmodels.ProjectAccount "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
  112. // @Router /api/projectAccount/search [get]
  113. func (c *ProjectAccountApi) GetSearch() {
  114. // 获得项目ID
  115. projectIdInt, err := utils.GetProjectId(c.Ctx)
  116. if err != nil {
  117. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  118. return
  119. }
  120. // 获得检索关键字
  121. AccountData := viewmodels.ProjectAccount{}
  122. err = c.Ctx.ReadForm(&AccountData)
  123. if err != nil {
  124. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("JSON转换异常, error=%s", err)})
  125. return
  126. }
  127. // 检索
  128. dataList := c.ServiceProjectAccount.Search(AccountData.Name, projectIdInt)
  129. c.Ctx.JSON(iris.Map{
  130. "code": 0, "msg": "",
  131. "data": dataList,
  132. })
  133. }
  134. // @Summary 编辑账号
  135. // @Tags 项目账号相关
  136. // @Description 编辑账号
  137. // @Accept json
  138. // @Produce json
  139. // @Security ApiKeyAuth
  140. // @Param id body string true "账号ID" default(PcqqGsn1O0jBSmLqkuOTwQ)
  141. // @Param name body string true "姓名"
  142. // @Param company body string true "公司"
  143. // @Param position body string true "职位"
  144. // @Param telephone body string true "座机"
  145. // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
  146. // @Router /api/projectAccount/account/save [post]
  147. func (c *ProjectAccountApi) PostAccountSave() {
  148. // 验证内容
  149. AccountData, err := c.ServiceProjectAccount.ValidRuleAccount(c.Ctx)
  150. if err != nil {
  151. ErrMsg := utils.FormValidError(err)
  152. c.Ctx.JSON(iris.Map{"code": -1, "msg": ErrMsg})
  153. return
  154. } else {
  155. // 获得更新账号ID
  156. id, err := utils.GetDecryptId(AccountData.Id)
  157. if err != nil {
  158. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  159. return
  160. }
  161. projectId, err := utils.GetProjectId(c.Ctx)
  162. if err != nil {
  163. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  164. return
  165. }
  166. err = c.ServiceProjectAccount.SaveAccount(AccountData, id, projectId)
  167. if err != nil {
  168. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  169. return
  170. }
  171. c.Ctx.JSON(iris.Map{"code": 0, "msg": "编辑成功"})
  172. }
  173. }
  174. // @Summary 修改密码
  175. // @Tags 项目账号相关
  176. // @Description 编辑账号
  177. // @Accept json
  178. // @Produce json
  179. // @Security ApiKeyAuth
  180. // @Param password body string true "密码"
  181. // @Param newPassword body string true "新密码"
  182. // @Param confirmPassword body string true "确认新密码"
  183. // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
  184. // @Router /api/projectAccount/change/password [post]
  185. func (c *ProjectAccountApi) PostChangePassword() {
  186. // 验证内容
  187. AccountData, err := c.ServiceProjectAccount.ValidRuleChangePassword(c.Ctx)
  188. if err != nil {
  189. ErrMsg := utils.FormValidError(err)
  190. c.Ctx.JSON(iris.Map{"code": -1, "msg": ErrMsg})
  191. return
  192. } else {
  193. if AccountData.ConfirmPassword != AccountData.NewPassword {
  194. c.Ctx.JSON(iris.Map{"code": -1, "msg": "新密码和确认密码不一致"})
  195. return
  196. }
  197. // 获得项目ID
  198. projectId, err := utils.GetProjectId(c.Ctx)
  199. if err != nil {
  200. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  201. return
  202. }
  203. // 获得项目账号ID
  204. projectAccountId, err := utils.GetProjectAccountId(c.Ctx)
  205. if err != nil {
  206. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  207. return
  208. }
  209. err = c.ServiceProjectAccount.ChangePassword(AccountData, projectId, projectAccountId)
  210. if err != nil {
  211. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  212. return
  213. }
  214. c.Ctx.JSON(iris.Map{"code": 0, "msg": "更新成功"})
  215. }
  216. }