123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- package admin
- import (
- "github.com/gin-gonic/gin"
- "server/dao"
- "server/global"
- "server/model/common/request"
- "server/model/common/response"
- "strconv"
- )
- type DepartmentApi struct {
- }
- func (da *DepartmentApi) QueryAllDep(c *gin.Context) {
- deps, err := departmentService.QueryAllDep()
- if err != nil {
- response.FailWithMessage("查询失败", c)
- global.GVA_LOG.Error("QueryAllDep ==" + err.Error())
- return
- }
- response.OkWithData(deps, c)
- }
- func (da *DepartmentApi) QueryDepByStart(c *gin.Context) {
- deps, err := departmentService.QueryDepByStart()
- if err != nil {
- response.FailWithMessage("查询失败", c)
- global.GVA_LOG.Error("QueryDepByStart ==" + err.Error())
- return
- }
- response.OkWithData(deps, c)
- }
- func (da *DepartmentApi) CreateDep(c *gin.Context) {
- department := dao.Department{}
- err := c.ShouldBindJSON(&department)
- if err != nil {
- global.GVA_LOG.Error("CreateDep ==" + err.Error())
- response.FailWithMessage("错误", c)
- return
- }
- err = departmentService.CreateDep(department)
- if err != nil {
- global.GVA_LOG.Error("CreateDep ==" + err.Error())
- response.FailWithMessage("错误", c)
- return
- }
- response.OkWithMessage("创建成功", c)
- }
- func (da *DepartmentApi) UpdateDep(c *gin.Context) {
- department := dao.Department{}
- err := c.ShouldBindJSON(&department)
- if err != nil {
- global.GVA_LOG.Error("UpdateDep ==" + err.Error())
- response.FailWithMessage("错误", c)
- return
- }
- err = departmentService.UpdateDep(department)
- if err != nil {
- global.GVA_LOG.Error("UpdateDep ==" + err.Error())
- response.FailWithMessage("错误", c)
- return
- }
- response.OkWithMessage("更新成功", c)
- }
- func (da *DepartmentApi) UpdateDepStatus(c *gin.Context) {
- department := dao.Department{}
- err := c.ShouldBindJSON(&department)
- if err != nil {
- global.GVA_LOG.Error("UpdateDepStatus ==" + err.Error())
- response.FailWithMessage("错误", c)
- return
- }
- err = departmentService.UpdateDepStatus(department.Id, department.IsStart)
- if err != nil {
- global.GVA_LOG.Error("UpdateDepStatus ==" + err.Error())
- response.FailWithMessage("错误", c)
- return
- }
- response.OkWithMessage("更新成功", c)
- }
- func (da *DepartmentApi) UpdateUserDep(c *gin.Context) {
- ids := request.Ids{}
- err := c.ShouldBindJSON(&ids)
- if err != nil {
- global.GVA_LOG.Error("UpdateUserDep ==" + err.Error())
- response.FailWithMessage("错误", c)
- return
- }
- err = departmentService.UpdateUserDep(ids.Ids, ids.Id)
- if err != nil {
- global.GVA_LOG.Error("UpdateUserDep ==" + err.Error())
- response.FailWithMessage("错误", c)
- return
- }
- response.OkWithMessage("更新成功", c)
- }
- func (da *DepartmentApi) DeleteDep(c *gin.Context) {
- id := c.Param("depId")
- depId, _ := strconv.Atoi(id)
- err := departmentService.DeleteDep(depId)
- if err != nil {
- global.GVA_LOG.Error("DeleteDep ==" + err.Error())
- response.FailWithMessage(err.Error(), c)
- return
- }
- response.OkWithMessage("删除成功", c)
- }
|