|
@@ -7,11 +7,15 @@ import (
|
|
|
"cold-delivery/common/actions"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
+ "github.com/beego/beego/v2/core/logs"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"github.com/gin-gonic/gin/binding"
|
|
|
+ "github.com/xuri/excelize/v2"
|
|
|
"gogs.baozhida.cn/zoie/OAuth-core/api"
|
|
|
"gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/user"
|
|
|
_ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
|
|
|
+ "net/url"
|
|
|
+ "os"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -434,6 +438,41 @@ func (e IceRaftController) OutStorage(c *gin.Context) {
|
|
|
e.OK(nil, "出库成功")
|
|
|
}
|
|
|
|
|
|
+// IsOutStorage 判断冰排出库
|
|
|
+// @Summary 判断冰排出库
|
|
|
+// @Description 判断冰排出库
|
|
|
+// @Tags 冰排
|
|
|
+// @Accept application/json
|
|
|
+// @Product application/json
|
|
|
+// @Param data body dto.IceRaftOutStorageReq true "body"
|
|
|
+// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
|
|
+// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
|
|
|
+// @Router /api/isoutstorage [post]
|
|
|
+// @Security Bearer
|
|
|
+func (e IceRaftController) IsOutStorage(c *gin.Context) {
|
|
|
+ s := service.IceRaft{}
|
|
|
+ req := dto.IceOutStorageReq{}
|
|
|
+ err := e.MakeContext(c).
|
|
|
+ MakeOrm().
|
|
|
+ Bind(&req, binding.JSON, nil).
|
|
|
+ MakeService(&s.Service).
|
|
|
+ Errors
|
|
|
+ if err != nil {
|
|
|
+ e.Logger.Error(err)
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //数据权限检查
|
|
|
+ p := actions.GetPermissionFromContext(c)
|
|
|
+ err, str := s.IsOutStorage(&req, p)
|
|
|
+ if err != nil {
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ e.OK(nil, str)
|
|
|
+}
|
|
|
+
|
|
|
type IceRaftRecordController struct {
|
|
|
api.Api
|
|
|
}
|
|
@@ -613,3 +652,186 @@ func (e IceRaftRecordController) StartForCold(c *gin.Context) {
|
|
|
}
|
|
|
e.OK(req, "提交成功")
|
|
|
}
|
|
|
+
|
|
|
+// IceRaftRecordRecording 冰排使用记录
|
|
|
+// @Summary 冰排使用记录
|
|
|
+// @Description 冰排使用记录
|
|
|
+// @Tags 冰排
|
|
|
+// @Accept application/json
|
|
|
+// @Product application/json
|
|
|
+// @Param data body dto.IceRaftRecordEedReq true "body"
|
|
|
+// @Success 200 {string} string "{"code": 200, "message": "提交成功"}"
|
|
|
+// @Success 200 {string} string "{"code": -1, "message": "提交成功"}"
|
|
|
+// @Router /api/recording [get]
|
|
|
+// @Security Bearer
|
|
|
+func (e IceRaftRecordController) IceRaftRecordRecording(c *gin.Context) {
|
|
|
+ s := service.IceRaft{}
|
|
|
+ req := dto.IceRaftRecordRecording{}
|
|
|
+ err := e.MakeContext(c).
|
|
|
+ MakeOrm().
|
|
|
+ Bind(&req, binding.Query).
|
|
|
+ MakeService(&s.Service).
|
|
|
+ Errors
|
|
|
+ if err != nil {
|
|
|
+ e.Logger.Error(err)
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //数据权限检查
|
|
|
+ p := actions.GetPermissionFromContext(c)
|
|
|
+ list := make([]model.IceRaftRecord, 0)
|
|
|
+ var count int64
|
|
|
+
|
|
|
+ err = s.IceRaftRecordRecording(&req, &list, &count, p)
|
|
|
+ if err != nil {
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
|
|
|
+}
|
|
|
+
|
|
|
+// ExportExecl 导出冰排使用记录
|
|
|
+// @Summary 导出冰排使用记录
|
|
|
+// @Description 导出冰排使用记录
|
|
|
+// @Tags 冰排
|
|
|
+// @Accept application/json
|
|
|
+// @Product application/json
|
|
|
+// @Param data body dto.IceRaftRecordEedReq true "body"
|
|
|
+// @Success 200 {string} string "{"code": 200, "message": "提交成功"}"
|
|
|
+// @Success 200 {string} string "{"code": -1, "message": "提交成功"}"
|
|
|
+// @Router /api/export-execl [get]
|
|
|
+// @Security Bearer
|
|
|
+func (e IceRaftRecordController) ExportExecl(c *gin.Context) {
|
|
|
+ s := service.IceRaft{}
|
|
|
+ req := dto.IceRaftRecordRecording{}
|
|
|
+ err := e.MakeContext(c).
|
|
|
+ MakeOrm().
|
|
|
+ Bind(&req, binding.Query).
|
|
|
+ MakeService(&s.Service).
|
|
|
+ Errors
|
|
|
+ if err != nil {
|
|
|
+ e.Logger.Error(err)
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //数据权限检查
|
|
|
+ p := actions.GetPermissionFromContext(c)
|
|
|
+ list := make([]model.IceRaftRecord, 0)
|
|
|
+ var count int64
|
|
|
+ req.Page = 1
|
|
|
+ req.PageSize = 9999
|
|
|
+ err = s.IceRaftRecordRecording(&req, &list, &count, p)
|
|
|
+ if err != nil {
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ f := excelize.NewFile() // 设置单元格的值
|
|
|
+ //获取当前登录用户信息,查询是否有权限
|
|
|
+ err, sysUser := service.GetUserProfile(e.Orm, p.UserId)
|
|
|
+ if err != nil {
|
|
|
+ e.Error(500, err, "获取用户信息失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if sysUser.Dept.IsIceReleaseCold {
|
|
|
+
|
|
|
+ // 这里设置表头ÒÒ
|
|
|
+ f.SetCellValue("Sheet1", "A1", "序号")
|
|
|
+ f.SetCellValue("Sheet1", "B1", "冰排编号")
|
|
|
+ f.SetCellValue("Sheet1", "C1", "预冷日期")
|
|
|
+ f.SetCellValue("Sheet1", "D1", "预冷时间")
|
|
|
+ f.SetCellValue("Sheet1", "E1", "预冷温度")
|
|
|
+ f.SetCellValue("Sheet1", "F1", "预冷地点")
|
|
|
+ f.SetCellValue("Sheet1", "G1", "操作人员")
|
|
|
+ f.SetCellValue("Sheet1", "H1", "使用日期")
|
|
|
+ f.SetCellValue("Sheet1", "I1", "使用时间")
|
|
|
+ f.SetCellValue("Sheet1", "J1", "操作人员")
|
|
|
+ f.SetCellValue("Sheet1", "K1", "备注")
|
|
|
+
|
|
|
+ // 设置列宽
|
|
|
+ f.SetColWidth("Sheet1", "A", "A", 6)
|
|
|
+ f.SetColWidth("Sheet1", "B", "B", 8)
|
|
|
+ f.SetColWidth("Sheet1", "C", "C", 14)
|
|
|
+ f.SetColWidth("Sheet1", "D", "D", 14)
|
|
|
+ f.SetColWidth("Sheet1", "E", "E", 30)
|
|
|
+ f.SetColWidth("Sheet1", "F", "F", 14)
|
|
|
+ f.SetColWidth("Sheet1", "G", "G", 14)
|
|
|
+ f.SetColWidth("Sheet1", "H", "H", 30)
|
|
|
+ f.SetColWidth("Sheet1", "I", "J", 15)
|
|
|
+ f.SetColWidth("Sheet1", "K", "K", 30)
|
|
|
+
|
|
|
+ line := 1
|
|
|
+
|
|
|
+ // 循环写入数据
|
|
|
+ for i, v := range list {
|
|
|
+ line++
|
|
|
+ start, _ := time.Parse("2006-01-02 15:04:05", v.IceUseTime.String())
|
|
|
+ end, _ := time.Parse("2006-01-02 15:04:05", v.StartIceColdTime.String())
|
|
|
+ sub := start.Sub(end).String()
|
|
|
+ parse, _ := time.Parse("2006-01-02 15:04:05", v.UpdatedAt.String())
|
|
|
+ s2 := parse.Sub(end).String()
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.Code)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.StartIceColdTime)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), sub)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.SuitableForCold)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.IceColdAddress)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.IceColdUsers)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.IceUseTime)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), s2)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.IceUseUsers)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), "")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ // 这里设置表头ÒÒ
|
|
|
+ f.SetCellValue("Sheet1", "A1", "序号")
|
|
|
+ f.SetCellValue("Sheet1", "B1", "冰排编号")
|
|
|
+ f.SetCellValue("Sheet1", "C1", "操作人员")
|
|
|
+ f.SetCellValue("Sheet1", "D1", "使用日期")
|
|
|
+ f.SetCellValue("Sheet1", "E1", "使用时间")
|
|
|
+ f.SetCellValue("Sheet1", "F1", "操作人员")
|
|
|
+ f.SetCellValue("Sheet1", "G1", "备注")
|
|
|
+
|
|
|
+ // 设置列宽
|
|
|
+ f.SetColWidth("Sheet1", "A", "A", 6)
|
|
|
+ f.SetColWidth("Sheet1", "B", "B", 8)
|
|
|
+ f.SetColWidth("Sheet1", "C", "C", 14)
|
|
|
+ f.SetColWidth("Sheet1", "D", "D", 30)
|
|
|
+ f.SetColWidth("Sheet1", "E", "E", 15)
|
|
|
+ f.SetColWidth("Sheet1", "F", "F", 30)
|
|
|
+ f.SetColWidth("Sheet1", "G", "G", 30)
|
|
|
+
|
|
|
+ line := 1
|
|
|
+
|
|
|
+ // 循环写入数据
|
|
|
+ for i, v := range list {
|
|
|
+ line++
|
|
|
+ start, _ := time.Parse("2006-01-02 15:04:05", v.IceUseTime.String())
|
|
|
+ parse, _ := time.Parse("2006-01-02 15:04:05", v.UpdatedAt.String())
|
|
|
+ s2 := parse.Sub(start).String()
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.Code)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.IceColdUsers)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.IceUseTime)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), s2)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.IceUseUsers)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), "")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ timeStr := time.Now().Format("20060102150405")
|
|
|
+ filePath := "ofile/" + "冰排使用记录表" + timeStr + ".xlsx"
|
|
|
+ // 保存文件
|
|
|
+ if err = f.SaveAs(filePath); err != nil {
|
|
|
+ logs.Error("文件失败:", err)
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ os.Remove(filePath)
|
|
|
+ }()
|
|
|
+ c.Header("Content-Type", "application/vnd.ms-excel;charset=utf8")
|
|
|
+ // PathEscape 函数对中文做处理
|
|
|
+ c.Header("Content-Disposition", "attachment; filename="+url.PathEscape("冰排使用记录表"+timeStr+".xlsx"))
|
|
|
+ c.Header("Content-Transfer-Encoding", "binary")
|
|
|
+ c.File(filePath)
|
|
|
+}
|