Ver Fonte

一类单位

zk há 2 anos atrás
pai
commit
615629d5e2

+ 143 - 0
server/api/v1/autocode/unit.go

@@ -0,0 +1,143 @@
+package autocode
+
+import (
+	"github.com/flipped-aurora/gin-vue-admin/server/global"
+    "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
+    "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
+    autocodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
+    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
+    "github.com/flipped-aurora/gin-vue-admin/server/service"
+    "github.com/gin-gonic/gin"
+    "go.uber.org/zap"
+)
+
+type UnitApi struct {
+}
+
+var unitService = service.ServiceGroupApp.AutoCodeServiceGroup.UnitService
+
+
+// CreateUnit 创建Unit
+// @Tags Unit
+// @Summary 创建Unit
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Param data body autocode.Unit true "创建Unit"
+// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
+// @Router /unit/createUnit [post]
+func (unitApi *UnitApi) CreateUnit(c *gin.Context) {
+	var unit autocode.Unit
+	_ = c.ShouldBindJSON(&unit)
+	if err := unitService.CreateUnit(unit); err != nil {
+        global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
+		response.FailWithMessage("创建失败", c)
+	} else {
+		response.OkWithMessage("创建成功", c)
+	}
+}
+
+// DeleteUnit 删除Unit
+// @Tags Unit
+// @Summary 删除Unit
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Param data body autocode.Unit true "删除Unit"
+// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
+// @Router /unit/deleteUnit [delete]
+func (unitApi *UnitApi) DeleteUnit(c *gin.Context) {
+	var unit autocode.Unit
+	_ = c.ShouldBindJSON(&unit)
+	if err := unitService.DeleteUnit(unit); err != nil {
+        global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
+		response.FailWithMessage("删除失败", c)
+	} else {
+		response.OkWithMessage("删除成功", c)
+	}
+}
+
+// DeleteUnitByIds 批量删除Unit
+// @Tags Unit
+// @Summary 批量删除Unit
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Param data body request.IdsReq true "批量删除Unit"
+// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
+// @Router /unit/deleteUnitByIds [delete]
+func (unitApi *UnitApi) DeleteUnitByIds(c *gin.Context) {
+	var IDS request.IdsReq
+    _ = c.ShouldBindJSON(&IDS)
+	if err := unitService.DeleteUnitByIds(IDS); err != nil {
+        global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
+		response.FailWithMessage("批量删除失败", c)
+	} else {
+		response.OkWithMessage("批量删除成功", c)
+	}
+}
+
+// UpdateUnit 更新Unit
+// @Tags Unit
+// @Summary 更新Unit
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Param data body autocode.Unit true "更新Unit"
+// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
+// @Router /unit/updateUnit [put]
+func (unitApi *UnitApi) UpdateUnit(c *gin.Context) {
+	var unit autocode.Unit
+	_ = c.ShouldBindJSON(&unit)
+	if err := unitService.UpdateUnit(unit); err != nil {
+        global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
+		response.FailWithMessage("更新失败", c)
+	} else {
+		response.OkWithMessage("更新成功", c)
+	}
+}
+
+// FindUnit 用id查询Unit
+// @Tags Unit
+// @Summary 用id查询Unit
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Param data query autocode.Unit true "用id查询Unit"
+// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
+// @Router /unit/findUnit [get]
+func (unitApi *UnitApi) FindUnit(c *gin.Context) {
+	var unit autocode.Unit
+	_ = c.ShouldBindQuery(&unit)
+	if err, reunit := unitService.GetUnit(unit.ID); err != nil {
+        global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
+		response.FailWithMessage("查询失败", c)
+	} else {
+		response.OkWithData(gin.H{"reunit": reunit}, c)
+	}
+}
+
+// GetUnitList 分页获取Unit列表
+// @Tags Unit
+// @Summary 分页获取Unit列表
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Param data query autocodeReq.UnitSearch true "分页获取Unit列表"
+// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
+// @Router /unit/getUnitList [get]
+func (unitApi *UnitApi) GetUnitList(c *gin.Context) {
+	var pageInfo autocodeReq.UnitSearch
+	_ = c.ShouldBindQuery(&pageInfo)
+	if err, list, total := unitService.GetUnitInfoList(pageInfo); err != nil {
+	    global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
+        response.FailWithMessage("获取失败", c)
+    } else {
+        response.OkWithDetailed(response.PageResult{
+            List:     list,
+            Total:    total,
+            Page:     pageInfo.Page,
+            PageSize: pageInfo.PageSize,
+        }, "获取成功", c)
+    }
+}

+ 11 - 0
server/model/autocode/request/unit.go

@@ -0,0 +1,11 @@
+package request
+
+import (
+	"github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
+	"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
+)
+
+type UnitSearch struct{
+    autocode.Unit
+    request.PageInfo
+}

+ 21 - 0
server/model/autocode/unit.go

@@ -0,0 +1,21 @@
+// 自动生成模板Unit
+package autocode
+
+import (
+	"github.com/flipped-aurora/gin-vue-admin/server/global"
+)
+
+// Unit 结构体
+// 如果含有time.Time 请自行import time包
+type Unit struct {
+      global.GVA_MODEL
+      UnitName  string `json:"unitName" form:"unitName" gorm:"column:unit_name;comment:单位名称;type:varchar(200);"`
+      UnitIntegral  *int `json:"unitIntegral" form:"unitIntegral" gorm:"column:unit_integral;comment:现有积分;type:int"`
+}
+
+
+// TableName Unit 表名
+func (Unit) TableName() string {
+  return "unit"
+}
+

+ 24 - 0
server/router/autocode/unit.go

@@ -0,0 +1,24 @@
+package autocode
+
+import (
+	"github.com/flipped-aurora/gin-vue-admin/server/api/v1"
+	"github.com/flipped-aurora/gin-vue-admin/server/middleware"
+	"github.com/gin-gonic/gin"
+)
+
+type UnitRouter struct {
+}
+
+// InitUnitRouter 初始化 Unit 路由信息
+func (s *UnitRouter) InitUnitRouter(Router *gin.RouterGroup) {
+	unitRouter := Router.Group("unit").Use(middleware.OperationRecord())
+	var unitApi = v1.ApiGroupApp.AutoCodeApiGroup.UnitApi
+	{
+		unitRouter.POST("createUnit", unitApi.CreateUnit)   // 新建Unit
+		unitRouter.DELETE("deleteUnit", unitApi.DeleteUnit) // 删除Unit
+		unitRouter.DELETE("deleteUnitByIds", unitApi.DeleteUnitByIds) // 批量删除Unit
+		unitRouter.PUT("updateUnit", unitApi.UpdateUnit)    // 更新Unit
+		unitRouter.GET("findUnit", unitApi.FindUnit)        // 根据ID获取Unit
+		unitRouter.GET("getUnitList", unitApi.GetUnitList)  // 获取Unit列表
+	}
+}

+ 60 - 0
server/service/autocode/unit.go

@@ -0,0 +1,60 @@
+package autocode
+
+import (
+	"github.com/flipped-aurora/gin-vue-admin/server/global"
+	"github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
+	"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
+    autoCodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
+)
+
+type UnitService struct {
+}
+
+// CreateUnit 创建Unit记录
+// Author [piexlmax](https://github.com/piexlmax)
+func (unitService *UnitService) CreateUnit(unit autocode.Unit) (err error) {
+	err = global.GVA_DB.Create(&unit).Error
+	return err
+}
+
+// DeleteUnit 删除Unit记录
+// Author [piexlmax](https://github.com/piexlmax)
+func (unitService *UnitService)DeleteUnit(unit autocode.Unit) (err error) {
+	err = global.GVA_DB.Delete(&unit).Error
+	return err
+}
+
+// DeleteUnitByIds 批量删除Unit记录
+// Author [piexlmax](https://github.com/piexlmax)
+func (unitService *UnitService)DeleteUnitByIds(ids request.IdsReq) (err error) {
+	err = global.GVA_DB.Delete(&[]autocode.Unit{},"id in ?",ids.Ids).Error
+	return err
+}
+
+// UpdateUnit 更新Unit记录
+// Author [piexlmax](https://github.com/piexlmax)
+func (unitService *UnitService)UpdateUnit(unit autocode.Unit) (err error) {
+	err = global.GVA_DB.Save(&unit).Error
+	return err
+}
+
+// GetUnit 根据id获取Unit记录
+// Author [piexlmax](https://github.com/piexlmax)
+func (unitService *UnitService)GetUnit(id uint) (err error, unit autocode.Unit) {
+	err = global.GVA_DB.Where("id = ?", id).First(&unit).Error
+	return
+}
+
+// GetUnitInfoList 分页获取Unit记录
+// Author [piexlmax](https://github.com/piexlmax)
+func (unitService *UnitService)GetUnitInfoList(info autoCodeReq.UnitSearch) (err error, list interface{}, total int64) {
+	limit := info.PageSize
+	offset := info.PageSize * (info.Page - 1)
+    // 创建db
+	db := global.GVA_DB.Model(&autocode.Unit{})
+    var units []autocode.Unit
+    // 如果有条件搜索 下方会自动创建搜索语句
+	err = db.Count(&total).Error
+	err = db.Limit(limit).Offset(offset).Find(&units).Error
+	return err, units, total
+}