123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- 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/flipped-aurora/gin-vue-admin/server/utils"
- "github.com/gin-gonic/gin"
- "go.uber.org/zap"
- "strconv"
- "time"
- )
- type ProblemInfoApi struct {
- }
- var problemInfoService = service.ServiceGroupApp.AutoCodeServiceGroup.ProblemInfoService
- // CreateProblemInfo 创建ProblemInfo
- // @Tags ProblemInfo
- // @Summary 创建ProblemInfo
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body autocode.ProblemInfo true "创建ProblemInfo"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
- // @Router /problemInfo/createProblemInfo [post]
- func (problemInfoApi *ProblemInfoApi) CreateProblemInfo(c *gin.Context) {
- userId := utils.GetUserID(c)
- var problemInfo autocode.ProblemInfo
- _ = c.ShouldBindJSON(&problemInfo)
- problemInfo.Status = "Untreated"
- if err, place := service.ServiceGroupApp.AutoCodeServiceGroup.PlaceService.GetPlace(problemInfo.SiteId); err != nil {
- response.FailWithMessage("创建失败,选择站点错误", c)
- } else {
- problemInfo.Oper = userId
- problemInfo.SiteType = place.Type
- problemInfo.Position = place.Position
- problemInfo.SiteName = place.Name
- problemInfo.Region = place.Region
- }
- if err := problemInfoService.CreateProblemInfo(problemInfo); err != nil {
- global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
- response.FailWithMessage("发布失败", c)
- } else {
- response.OkWithMessage("发布成功", c)
- }
- }
- func (problemInfoApi *ProblemInfoApi) ExportExcel(c *gin.Context) {
- var problemInfo autocodeReq.ProblemInfoSearch
- _ = c.ShouldBindJSON(&problemInfo)
- filePath := global.GVA_CONFIG.Excel.Dir + strconv.FormatInt(time.Now().Unix(), 10) + ".xlsx"
- if err, list, _ := problemInfoService.GetProblemInfoInfoList(problemInfo); err != nil {
- global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
- response.FailWithMessage("获取失败", c)
- } else {
- err := service.ServiceGroupApp.ExampleServiceGroup.ExcelService.ProblemInfoList2Excel(list, filePath)
- if err != nil {
- global.GVA_LOG.Error("转换Excel失败!", zap.Any("err", err))
- response.FailWithMessage("转换Excel失败", c)
- return
- }
- c.Writer.Header().Add("success", "true")
- c.File(filePath)
- }
- }
- // DeleteProblemInfo 删除ProblemInfo
- // @Tags ProblemInfo
- // @Summary 删除ProblemInfo
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body autocode.ProblemInfo true "删除ProblemInfo"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
- // @Router /problemInfo/deleteProblemInfo [delete]
- func (problemInfoApi *ProblemInfoApi) DeleteProblemInfo(c *gin.Context) {
- var problemInfo autocode.ProblemInfo
- _ = c.ShouldBindJSON(&problemInfo)
- if err := problemInfoService.DeleteProblemInfo(problemInfo); err != nil {
- global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
- response.FailWithMessage("删除失败", c)
- } else {
- response.OkWithMessage("删除成功", c)
- }
- }
- // DeleteProblemInfoByIds 批量删除ProblemInfo
- // @Tags ProblemInfo
- // @Summary 批量删除ProblemInfo
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body request.IdsReq true "批量删除ProblemInfo"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
- // @Router /problemInfo/deleteProblemInfoByIds [delete]
- func (problemInfoApi *ProblemInfoApi) DeleteProblemInfoByIds(c *gin.Context) {
- var IDS request.IdsReq
- _ = c.ShouldBindJSON(&IDS)
- if err := problemInfoService.DeleteProblemInfoByIds(IDS); err != nil {
- global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
- response.FailWithMessage("批量删除失败", c)
- } else {
- response.OkWithMessage("批量删除成功", c)
- }
- }
- // UpdateProblemInfo 更新ProblemInfo
- // @Tags ProblemInfo
- // @Summary 更新ProblemInfo
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body autocode.ProblemInfo true "更新ProblemInfo"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
- // @Router /problemInfo/updateProblemInfo [put]
- func (problemInfoApi *ProblemInfoApi) UpdateProblemInfo(c *gin.Context) {
- var problemInfo autocode.ProblemInfo
- _ = c.ShouldBindJSON(&problemInfo)
- _, problemInfoNow := problemInfoService.GetProblemInfo(problemInfo.ID)
- problemInfoNow.Handler = problemInfo.Handler
- problemInfoNow.HandImgs = problemInfo.HandImgs
- problemInfoNow.HandText = problemInfo.HandText
- problemInfoNow.Status = "Processed"
- if err := problemInfoService.UpdateProblemInfo(problemInfoNow); err != nil {
- global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
- response.FailWithMessage("更新失败", c)
- } else {
- response.OkWithMessage("更新成功", c)
- }
- }
- // FindProblemInfo 用id查询ProblemInfo
- // @Tags ProblemInfo
- // @Summary 用id查询ProblemInfo
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data query autocode.ProblemInfo true "用id查询ProblemInfo"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
- // @Router /problemInfo/findProblemInfo [get]
- func (problemInfoApi *ProblemInfoApi) FindProblemInfo(c *gin.Context) {
- var problemInfo autocode.ProblemInfo
- _ = c.ShouldBindQuery(&problemInfo)
- if err, reproblemInfo := problemInfoService.GetProblemInfo(problemInfo.ID); err != nil {
- global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
- response.FailWithMessage("查询失败", c)
- } else {
- response.OkWithData(gin.H{"reproblemInfo": reproblemInfo}, c)
- }
- }
- // GetProblemInfoList 分页获取ProblemInfo列表
- // @Tags ProblemInfo
- // @Summary 分页获取ProblemInfo列表
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data query autocodeReq.ProblemInfoSearch true "分页获取ProblemInfo列表"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
- // @Router /problemInfo/getProblemInfoList [get]
- func (problemInfoApi *ProblemInfoApi) GetProblemInfoList(c *gin.Context) {
- var pageInfo autocodeReq.ProblemInfoSearch
- _ = c.ShouldBindQuery(&pageInfo)
- if err, list, total := problemInfoService.GetProblemInfoInfoList(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)
- }
- }
|