123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837 |
- package controller
- import (
- "cold-delivery/app/admin/model"
- "cold-delivery/app/admin/service"
- "cold-delivery/app/admin/service/dto"
- "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"
- )
- type IceRaftController struct {
- api.Api
- }
- // GetPage 获取冰排列表
- // @Summary 获取冰排列表
- // @Description 获取冰排列表
- // @Tags 冰排
- // @Param name query string false "冰排名称"
- // @Param pageSize query int false "页条数"
- // @Param page query int false "页码"
- // @Success 200 {object} response.Response{data=response.Page{list=[]model.IceRaft}} "{"code": 200, "data": [...]}"
- // @Router /api/ice-raft [get]
- // @Security Bearer
- func (e IceRaftController) GetPage(c *gin.Context) {
- s := service.IceRaft{}
- req := dto.IceRaftGetPageReq{}
- 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.IceRaft, 0)
- var count int64
- err = s.GetPage(&req, &list, &count, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
- }
- func (e IceRaftController) GetPageByCoolerBoxId(c *gin.Context) {
- s := service.IceRaft{}
- req := dto.GetPageByCoolerBoxIdReq{}
- 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([]string, 0)
- err = s.GetPageByCoolerBoxId(req.CoolerBoxId, &list, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(list, "查询成功")
- }
- // GetNewestRecordPage 获取冰排记录列表
- // @Summary 获取冰排列表
- // @Description 获取冰排列表
- // @Tags 冰排
- // @Param name query string false "冰排名称"
- // @Param pageSize query int false "页条数"
- // @Param page query int false "页码"
- // @Success 200 {object} response.Response{data=response.Page{list=[]model.IceRaft}} "{"code": 200, "data": [...]}"
- // @Router /api/ice-raft [get]
- // @Security Bearer
- func (e IceRaftController) GetNewestRecordPage(c *gin.Context) {
- s := service.IceRaft{}
- req := dto.IceRaftGetNewestRecordPageReq{}
- 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.IceRaft, 0)
- var count int64
- err = s.GetRecordPage(&req, &list, &count, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
- }
- func (e IceRaftController) GetNewestRecordPageSSE(c *gin.Context) {
- s := service.IceRaft{}
- req := dto.IceRaftGetNewestRecordPageReq{}
- 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.IceRaft, 0)
- var count int64
- // Set the response header to indicate SSE content type
- c.Header("Content-Type", "text/event-stream")
- c.Header("Cache-Control", "no-cache")
- c.Header("Connection", "keep-alive")
- // Create a channel to send events to the client
- println("Client connected")
- // Listen for client close and remove the client from the list
- notify := c.Writer.CloseNotify()
- go func() {
- <-notify
- fmt.Println("Client disconnected")
- }()
- type Page struct {
- Count int `json:"count"` //总数
- Page int `json:"page"` //页码
- PageSize int `json:"pageSize"` //页条数
- List interface{} `json:"list"`
- }
- type Response struct {
- RequestId string `protobuf:"bytes,1,opt,name=requestId,proto3" json:"requestId,omitempty"`
- Code int32 `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
- Msg string `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"`
- Status string `protobuf:"bytes,4,opt,name=status,proto3" json:"status,omitempty"`
- Data Page `json:"data"`
- }
- // Continuously send data to the client
- for {
- err = s.GetRecordPage(&req, &list, &count, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- var response Response
- var page Page
- response.Code = 200
- response.Msg = "查询成功"
- response.Msg = "查询成功"
- page.Count = int(count)
- page.Page = req.GetPageIndex()
- page.PageSize = req.GetPageSize()
- page.List = list
- response.Data = page
- //data := <-eventChan
- res, _ := json.Marshal(&response)
- fmt.Fprintf(c.Writer, "data: %s\n\n", string(res))
- c.Writer.Flush()
- time.Sleep(10 * time.Second)
- }
- }
- // Get 通过id获取冰排
- // @Summary 通过id获取冰排
- // @Description 通过id获取冰排
- // @Tags 冰排
- // @Param id path string true "冰排id"
- // @Success 200 {object} response.Response{data=model.IceRaft} "{"code": 200, "data": [...]}"
- // @Router /api/ice-raft/{id} [get]
- // @Security Bearer
- func (e IceRaftController) Get(c *gin.Context) {
- s := service.IceRaft{}
- req := dto.IceRaftGetReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, nil).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- var object model.IceRaft
- p := actions.GetPermissionFromContext(c)
- //数据权限检查
- err = s.Get(&req, &object, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(object, "查询成功")
- }
- // GetByCode 通过code获取冰排
- // @Summary 通过code获取冰排
- // @Description 通过code获取冰排
- // @Tags 冰排
- // @Param id path string true "冰排id"
- // @Success 200 {object} response.Response{data=model.IceRaft} "{"code": 200, "data": [...]}"
- // @Router /api/ice-raft/code/{code} [get]
- // @Security Bearer
- func (e IceRaftController) GetByCode(c *gin.Context) {
- s := service.IceRaft{}
- req := dto.IceRaftGetByCodeReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, nil).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- var object model.IceRaft
- p := actions.GetPermissionFromContext(c)
- //数据权限检查
- err = s.GetByCode(&req, &object, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(object, "查询成功")
- }
- // Insert 添加冰排
- // @Summary 添加冰排
- // @Description 添加冰排
- // @Tags 冰排
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.IceRaftInsertReq true "data"
- // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
- // @Router /api/ice-raft [post]
- // @Security Bearer
- func (e IceRaftController) Insert(c *gin.Context) {
- s := service.IceRaft{}
- req := dto.IceRaftInsertReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.JSON).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- p := actions.GetPermissionFromContext(c)
- // 设置创建人
- req.SetCreateBy(user.GetUserId(c))
- req.SetDeptId(p.DeptId)
- err = s.Insert(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(req.GetId(), "添加成功")
- }
- // Update 修改冰排
- // @Summary 修改冰排
- // @Description 修改冰排
- // @Tags 冰排
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.IceRaftUpdateReq true "body"
- // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
- // @Router /api/ice-raft [put]
- // @Security Bearer
- func (e IceRaftController) Update(c *gin.Context) {
- s := service.IceRaft{}
- req := dto.IceRaftUpdateReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- p := actions.GetPermissionFromContext(c)
- req.SetUpdateBy(user.GetUserId(c))
- err = s.Update(&req, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(req.GetId(), "修改成功")
- }
- // Delete 删除冰排
- // @Summary 删除冰排
- // @Description 删除冰排
- // @Tags 冰排
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.IceRaftDeleteReq true "body"
- // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
- // @Router /api/ice-raft [delete]
- // @Security Bearer
- func (e IceRaftController) Delete(c *gin.Context) {
- s := service.IceRaft{}
- req := dto.IceRaftDeleteReq{}
- 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 = s.Remove(&req, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(req.GetId(), "删除成功")
- }
- // InStorage 冰排入库
- // @Summary 冰排入库
- // @Description 冰排入库
- // @Tags 冰排
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.IceRaftInStorageReq true "body"
- // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
- // @Router /api/ice-raft [delete]
- // @Security Bearer
- func (e IceRaftController) InStorage(c *gin.Context) {
- s := service.IceRaft{}
- req := dto.IceRaftInStorageReq{}
- 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 = s.InStorage(&req, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(nil, "入库成功")
- }
- // OutStorage 冰排出库
- // @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/ice-raft [delete]
- // @Security Bearer
- func (e IceRaftController) OutStorage(c *gin.Context) {
- s := service.IceRaft{}
- req := dto.IceRaftOutStorageReq{}
- 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 = s.OutStorage(&req, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- 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
- }
- // GetPage 获取冰排历史记记录列表
- // @Summary 获取冰排列表
- // @Description 获取冰排列表
- // @Tags 冰排
- // @Param name query string false "冰排名称"
- // @Param pageSize query int false "页条数"
- // @Param page query int false "页码"
- // @Success 200 {object} response.Response{data=response.Page{list=[]model.IceRaft}} "{"code": 200, "data": [...]}"
- // @Router /api/ice-raft [get]
- // @Security Bearer
- func (e IceRaftRecordController) GetPage(c *gin.Context) {
- s := service.IceRaftRecord{}
- req := dto.IceRaftRecordGetPageReq{}
- 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.GetPage(&req, &list, &count, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
- }
- // Update 修改冰排出入库历史记录
- // @Summary 修改冰排出入库历史记录
- // @Description 修改冰排出入库历史记录
- // @Tags 冰排
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.IceRaftUpdateReq true "body"
- // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
- // @Router /api/ice-raft [put]
- // @Security Bearer
- func (e IceRaftRecordController) Update(c *gin.Context) {
- s := service.IceRaftRecord{}
- req := dto.IceRaftRecordUpdateReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- p := actions.GetPermissionFromContext(c)
- req.SetUpdateBy(user.GetUserId(c))
- err = s.Update(&req, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(req.GetId(), "修改成功")
- }
- // Delete 删除冰排出入库历史记录
- // @Summary 删除冰排出入库历史记录
- // @Description 删除冰排出入库历史记录
- // @Tags 冰排
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.IceRaftDeleteReq true "body"
- // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
- // @Router /api/ice-raft [delete]
- // @Security Bearer
- func (e IceRaftRecordController) Delete(c *gin.Context) {
- s := service.IceRaftRecord{}
- req := dto.IceRaftRecordDeleteReq{}
- 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 = s.Remove(&req, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(req.GetId(), "删除成功")
- }
- // EndForCold 保温箱冰排结束适冷
- // @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/end-for-cold [post]
- // @Security Bearer
- func (e IceRaftRecordController) EndForCold(c *gin.Context) {
- s := service.IceRaftRecord{}
- req := dto.IceRaftRecordEedReq{}
- 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 = s.EndForCold(&req, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(req.Id, "提交成功")
- }
- // StartForCold 冰排开始释冷
- // @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/start-for-cold [post]
- // @Security Bearer
- func (e IceRaftRecordController) StartForCold(c *gin.Context) {
- s := service.IceRaftRecord{}
- req := dto.IceStartbleForColfTimReq{}
- 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 = s.StartForCold(&req, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- 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)
- }
|