package GovAreaController import ( "dsBaseWeb/Business/GovArea/GovAreaService" "dsBaseWeb/Model" "dsBaseWeb/Utils/CommonUtil" "github.com/gin-gonic/gin" "net/http" ) //模块的路由配置 func Routers(r *gin.RouterGroup) { rr := r.Group("/area") //配置接口 rr.POST("/AddGovArea", AddGovArea) rr.POST("/DeleteGovArea", DeleteGovArea) rr.POST("/UpdateGovArea", UpdateGovArea) rr.GET("/PageGovArea", PageGovArea) rr.GET("/GetGovArea", GetGovArea) return } // @Summary 增加行政区划信息 // @Description 增加行政区划信息 // @Tags 行政区划 // @Accept application/x-www-form-urlencoded // @Produce json // @Param areaCode formData string true "区域代码" // @Param areaName formData string true "区域名称" // @Param masterCode formData string true "上级代码" // @Param areaTypeId formData int true "区域类型" // @Success 200 {object} Model.Res // @Router /base/area/AddGovArea [post] // @X-EmptyLimit ["areaTypeId","areaCode","areaName","masterCode"] // @X-IntLimit ["areaTypeId"] // @X-LengthLimit [{"areaCode":"6,6"},{"masterCode":"6,6"},{"areaName":"3,50"}] // @X-RoleLimit ["1","2","3","4","5","6","7"] func AddGovArea(c *gin.Context) { areaCode := c.PostForm("areaCode") areaName := c.PostForm("areaName") masterCode := c.PostForm("masterCode") areaTypeId := CommonUtil.ConvertStringToInt32(c.PostForm("areaTypeId")) //操作人 actionPersonId, err := c.Cookie("person_id") if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "未获取到Cookie中的人员编码!", }) return } //操作IP actionIpAddress := c.ClientIP() r, err := GovAreaService.AddGovArea(areaCode, areaName, masterCode, 3, areaTypeId, actionPersonId, actionIpAddress) if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "调用RPC服务失败!", }) return } c.JSON(http.StatusOK, Model.Res{ Success: r.Success, Message: r.Message, }) } // @Summary 删除行政区划信息 // @Description 删除行政区划信息 // @Tags 行政区划 // @Accept application/x-www-form-urlencoded // @Produce json // @Param areaCode formData string true "区域代码" // @Success 200 {object} Model.Res // @Router /base/area/DeleteGovArea [post] // @X-EmptyLimit ["areaCode"] // @X-LengthLimit [{"areaCode":"6,6"}] // @X-RoleLimit ["1","2","3","4","5","6","7"] func DeleteGovArea(c *gin.Context) { areaCode := c.PostForm("areaCode") //操作人 actionPersonId, err := c.Cookie("person_id") if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "未获取到Cookie中的人员编码!", }) return } //操作IP actionIpAddress := c.ClientIP() r, err := GovAreaService.DeleteGovArea(areaCode, actionPersonId, actionIpAddress) if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "调用RPC服务失败!", }) return } c.JSON(http.StatusOK, Model.Res{ Success: r.Success, Message: r.Message, }) } // @Summary 修改行政区划信息 // @Description 修改行政区划信息 // @Tags 行政区划 // @Accept application/x-www-form-urlencoded // @Produce json // @Param areaCode formData string true "区域代码" // @Param areaName formData string true "区域名称" // @Param masterCode formData string true "上级代码" // @Param areaTypeId formData int true "区域类型" // @Success 200 {object} Model.Res // @Router /base/area/UpdateGovArea [post] // @X-EmptyLimit ["areaTypeId","areaCode","areaName","masterCode"] // @X-IntLimit ["areaTypeId"] // @X-LengthLimit [{"areaCode":"6,6"},{"masterCode":"6,6"},{"areaName":"3:50"}] // @X-RoleLimit ["1","2","3","4","5","6","7"] func UpdateGovArea(c *gin.Context) { areaCode := c.PostForm("areaCode") areaName := c.PostForm("areaName") masterCode := c.PostForm("masterCode") areaTypeId := CommonUtil.ConvertStringToInt32(c.PostForm("areaTypeId")) //操作人 actionPersonId, err := c.Cookie("person_id") if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "未获取到Cookie中的人员编码!", }) return } //操作IP actionIpAddress := c.ClientIP() r, err := GovAreaService.UpdateGovArea(areaCode, areaName, masterCode, areaTypeId, actionPersonId, actionIpAddress) if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "调用RPC服务失败!", }) return } c.JSON(http.StatusOK, Model.Res{ Success: r.Success, Message: r.Message, }) } // @Summary 获取行政区划信息(单条) // @Description 获取行政区划信息(单条) // @Tags 行政区划 // @Accept application/x-www-form-urlencoded // @Produce json // @Param areaCode query string true "行政区划码" // @Success 200 {object} Model.Res // @Router /base/area/GetGovArea [get] // @X-EmptyLimit ["areaCode"] // @X-IntLimit ["areaCode"] // @X-LengthLimit [{"areaCode":"6,6"}] // @X-RoleLimit ["1","2","3","4","5","6","7"] func GetGovArea(c *gin.Context) { areaCode := c.Query("areaCode") //操作人 actionPersonId, err := c.Cookie("person_id") if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "未获取到Cookie中的人员编码!", }) return } //操作IP actionIpAddress := c.ClientIP() r, err := GovAreaService.GetGovArea(areaCode, actionPersonId, actionIpAddress) if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "调用RPC服务失败!", }) return } c.JSON(http.StatusOK, Model.Res{ Success: r.Success, List: CommonUtil.ConvertJsonStringToMapArray(r.List), Message: r.Message, }) } // @Summary 获取行政区划信息(列表) // @Description 获取行政区划信息(列表) // @Tags 行政区划 // @Accept application/x-www-form-urlencoded // @Produce json // @Param page query int true "第几页" // @Param limit query int true "一页显示多少条" // @Param areaCode query string true "行政区划码" // @Success 200 {object} Model.Res // @Router /base/area/PageGovArea [get] // @X-EmptyLimit ["page","limit","areaCode"] // @X-IntLimit ["page","limit","areaCode"] // @X-LengthLimit [{"areaCode":"6,6"}] // @X-RoleLimit ["1","2","3","4","5","6","7"] // @X-TableName ["t_gov_area"] func PageGovArea(c *gin.Context) { page := CommonUtil.ConvertStringToInt32(c.Query("page")) limit := CommonUtil.ConvertStringToInt32(c.Query("limit")) areaCode := c.Query("areaCode") //操作人 actionPersonId, err := c.Cookie("person_id") if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "未获取到Cookie中的人员编码!", }) return } //操作IP actionIpAddress := c.ClientIP() r, err := GovAreaService.PageGovArea(page, limit, areaCode, actionPersonId, actionIpAddress) if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "调用RPC服务失败!", }) return } c.JSON(http.StatusOK, Model.Res{ Success: true, List: CommonUtil.ConvertJsonStringToMapArray(r.List), Message: "获取成功", Count: r.Count, }) }