zk 2 жил өмнө
parent
commit
c2cb0a2621

+ 145 - 0
server/api/v1/autocode/assignment.go

@@ -0,0 +1,145 @@
+package autocode
+
+import (
+	"github.com/flipped-aurora/gin-vue-admin/server/global"
+	"github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
+	autocodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
+	"github.com/flipped-aurora/gin-vue-admin/server/model/common/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 AssignmentApi struct {
+}
+
+var assignmentService = service.ServiceGroupApp.AutoCodeServiceGroup.AssignmentService
+var fileUploadAndDownloadService = service.ServiceGroupApp.ExampleServiceGroup.FileUploadAndDownloadService
+
+// CreateAssignment 创建Assignment
+// @Tags Assignment
+// @Summary 创建Assignment
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Param data body autocode.Assignment true "创建Assignment"
+// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
+// @Router /assignment/createAssignment [post]
+func (assignmentApi *AssignmentApi) CreateAssignment(c *gin.Context) {
+	var assignment autocode.Assignment
+	_ = c.ShouldBindJSON(&assignment)
+	if err := assignmentService.CreateAssignment(assignment); err != nil {
+		global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
+		response.FailWithMessage("创建失败", c)
+	} else {
+		response.OkWithMessage("创建成功", c)
+	}
+}
+
+// DeleteAssignment 删除Assignment
+// @Tags Assignment
+// @Summary 删除Assignment
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Param data body autocode.Assignment true "删除Assignment"
+// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
+// @Router /assignment/deleteAssignment [delete]
+func (assignmentApi *AssignmentApi) DeleteAssignment(c *gin.Context) {
+	var assignment autocode.Assignment
+	_ = c.ShouldBindJSON(&assignment)
+	if err := assignmentService.DeleteAssignment(assignment); err != nil {
+		global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
+		response.FailWithMessage("删除失败", c)
+	} else {
+		response.OkWithMessage("删除成功", c)
+	}
+}
+
+// DeleteAssignmentByIds 批量删除Assignment
+// @Tags Assignment
+// @Summary 批量删除Assignment
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Param data body request.IdsReq true "批量删除Assignment"
+// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
+// @Router /assignment/deleteAssignmentByIds [delete]
+func (assignmentApi *AssignmentApi) DeleteAssignmentByIds(c *gin.Context) {
+	var IDS request.IdsReq
+	_ = c.ShouldBindJSON(&IDS)
+	if err := assignmentService.DeleteAssignmentByIds(IDS); err != nil {
+		global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
+		response.FailWithMessage("批量删除失败", c)
+	} else {
+		response.OkWithMessage("批量删除成功", c)
+	}
+}
+
+// UpdateAssignment 更新Assignment
+// @Tags Assignment
+// @Summary 更新Assignment
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Param data body autocode.Assignment true "更新Assignment"
+// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
+// @Router /assignment/updateAssignment [put]
+func (assignmentApi *AssignmentApi) UpdateAssignment(c *gin.Context) {
+	var assignment autocode.Assignment
+	_ = c.ShouldBindJSON(&assignment)
+	if err := assignmentService.UpdateAssignment(assignment); err != nil {
+		global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
+		response.FailWithMessage("更新失败", c)
+	} else {
+		response.OkWithMessage("更新成功", c)
+	}
+}
+
+// FindAssignment 用id查询Assignment
+// @Tags Assignment
+// @Summary 用id查询Assignment
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Param data query autocode.Assignment true "用id查询Assignment"
+// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
+// @Router /assignment/findAssignment [get]
+func (assignmentApi *AssignmentApi) FindAssignment(c *gin.Context) {
+	var assignment autocode.Assignment
+	_ = c.ShouldBindQuery(&assignment)
+	if err, reassignment := assignmentService.GetAssignment(assignment.ID); err != nil {
+		global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
+		response.FailWithMessage("查询失败", c)
+	} else {
+		_, files := fileUploadAndDownloadService.GetFileRecordInfoByList(reassignment.ID)
+		reassignment.Files = files
+		response.OkWithData(gin.H{"reassignment": reassignment}, c)
+	}
+}
+
+// GetAssignmentList 分页获取Assignment列表
+// @Tags Assignment
+// @Summary 分页获取Assignment列表
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Param data query autocodeReq.AssignmentSearch true "分页获取Assignment列表"
+// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
+// @Router /assignment/getAssignmentList [get]
+func (assignmentApi *AssignmentApi) GetAssignmentList(c *gin.Context) {
+	var pageInfo autocodeReq.AssignmentSearch
+	_ = c.ShouldBindQuery(&pageInfo)
+	if err, list, total := assignmentService.GetAssignmentInfoList(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)
+	}
+}

+ 22 - 0
server/model/autocode/assignment.go

@@ -0,0 +1,22 @@
+// 自动生成模板Assignment
+package autocode
+
+import (
+	"github.com/flipped-aurora/gin-vue-admin/server/global"
+	"github.com/flipped-aurora/gin-vue-admin/server/model/example"
+)
+
+// Assignment 结构体
+// 如果含有time.Time 请自行import time包
+type Assignment struct {
+	global.GVA_MODEL
+	UnitIds string                             `json:"unitIds" form:"unitIds" gorm:"column:unit_ids;comment:目标部门;type:varchar(255);"`
+	Title   string                             `json:"title" form:"title" gorm:"column:title;comment:标题;type:varchar(255);"`
+	Text    string                             `json:"text" form:"text" gorm:"column:text;comment:内容;type:text;"`
+	Files   []example.ExaFileUploadAndDownload `json:"files" gorm:"-"`
+}
+
+// TableName Assignment 表名
+func (Assignment) TableName() string {
+	return "assignment"
+}

+ 11 - 0
server/model/autocode/request/assignment.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 AssignmentSearch struct {
+	autocode.Assignment
+	request.PageInfo
+}

+ 24 - 0
server/router/autocode/assignment.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 AssignmentRouter struct {
+}
+
+// InitAssignmentRouter 初始化 Assignment 路由信息
+func (s *AssignmentRouter) InitAssignmentRouter(Router *gin.RouterGroup) {
+	assignmentRouter := Router.Group("assignment").Use(middleware.OperationRecord())
+	var assignmentApi = v1.ApiGroupApp.AutoCodeApiGroup.AssignmentApi
+	{
+		assignmentRouter.POST("createAssignment", assignmentApi.CreateAssignment)             // 新建Assignment
+		assignmentRouter.DELETE("deleteAssignment", assignmentApi.DeleteAssignment)           // 删除Assignment
+		assignmentRouter.DELETE("deleteAssignmentByIds", assignmentApi.DeleteAssignmentByIds) // 批量删除Assignment
+		assignmentRouter.PUT("updateAssignment", assignmentApi.UpdateAssignment)              // 更新Assignment
+		assignmentRouter.GET("findAssignment", assignmentApi.FindAssignment)                  // 根据ID获取Assignment
+		assignmentRouter.GET("getAssignmentList", assignmentApi.GetAssignmentList)            // 获取Assignment列表
+	}
+}

+ 60 - 0
server/service/autocode/assignment.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"
+	autoCodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
+	"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
+)
+
+type AssignmentService struct {
+}
+
+// CreateAssignment 创建Assignment记录
+// Author [piexlmax](https://github.com/piexlmax)
+func (assignmentService *AssignmentService) CreateAssignment(assignment autocode.Assignment) (err error) {
+	err = global.GVA_DB.Create(&assignment).Error
+	return err
+}
+
+// DeleteAssignment 删除Assignment记录
+// Author [piexlmax](https://github.com/piexlmax)
+func (assignmentService *AssignmentService) DeleteAssignment(assignment autocode.Assignment) (err error) {
+	err = global.GVA_DB.Delete(&assignment).Error
+	return err
+}
+
+// DeleteAssignmentByIds 批量删除Assignment记录
+// Author [piexlmax](https://github.com/piexlmax)
+func (assignmentService *AssignmentService) DeleteAssignmentByIds(ids request.IdsReq) (err error) {
+	err = global.GVA_DB.Delete(&[]autocode.Assignment{}, "id in ?", ids.Ids).Error
+	return err
+}
+
+// UpdateAssignment 更新Assignment记录
+// Author [piexlmax](https://github.com/piexlmax)
+func (assignmentService *AssignmentService) UpdateAssignment(assignment autocode.Assignment) (err error) {
+	err = global.GVA_DB.Save(&assignment).Error
+	return err
+}
+
+// GetAssignment 根据id获取Assignment记录
+// Author [piexlmax](https://github.com/piexlmax)
+func (assignmentService *AssignmentService) GetAssignment(id uint) (err error, assignment autocode.Assignment) {
+	err = global.GVA_DB.Where("id = ?", id).First(&assignment).Error
+	return
+}
+
+// GetAssignmentInfoList 分页获取Assignment记录
+// Author [piexlmax](https://github.com/piexlmax)
+func (assignmentService *AssignmentService) GetAssignmentInfoList(info autoCodeReq.AssignmentSearch) (err error, list interface{}, total int64) {
+	limit := info.PageSize
+	offset := info.PageSize * (info.Page - 1)
+	// 创建db
+	db := global.GVA_DB.Model(&autocode.Assignment{})
+	var assignments []autocode.Assignment
+	// 如果有条件搜索 下方会自动创建搜索语句
+	err = db.Count(&total).Error
+	err = db.Limit(limit).Offset(offset).Find(&assignments).Error
+	return err, assignments, total
+}