123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- package controller
- import (
- "cold-logistics/app/admin/model"
- "cold-logistics/app/admin/service"
- "cold-logistics/app/admin/service/dto"
- "cold-logistics/common/actions"
- "cold-logistics/common/nats/nats_server"
- "errors"
- "github.com/gin-gonic/gin"
- "github.com/gin-gonic/gin/binding"
- "gogs.baozhida.cn/zoie/OAuth-core/api"
- "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/user"
- _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
- )
- type WaybillTaskController struct {
- api.Api
- }
- // GetPage 获取运单任务列表
- // @Summary 获取运单任务列表
- // @Description 获取运单任务列表
- // @Tags 运单任务
- // @Param waybillNo query string true "运单号"
- // @Success 200 {object} response.Response{data=response.Page{list=[]model.WaybillTask}} "{"code": 200, "data": [...]}"
- // @Router /api/waybill-task [get]
- // @Security Bearer
- func (e WaybillTaskController) GetPage(c *gin.Context) {
- s := service.WaybillTask{}
- req := dto.WaybillTaskGetPageReq{}
- 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
- }
- list := make([]model.WaybillTask, 0)
- var count int64
- err = s.GetPage(&req, &list, &count)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- //e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
- e.PageOK(list, int(count), 0, 0, "查询成功")
- }
- // GetData 获取温湿度记录
- // @Summary 获取传感器列表
- // @Description 获取传感器列表
- // @Tags 运单任务
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.WaybillTaskGetDataPageReq true "body"
- // @Success 200 {object} response.Response{data=response.Page{list=[]model.WaybillTask}} "{"code": 200, "data": [...]}"
- // @Router /api/waybill-task/data [post]
- // @Security Bearer
- func (e WaybillTaskController) GetData(c *gin.Context) {
- s := service.WaybillTask{}
- req := dto.WaybillTaskGetDataPageReq{}
- 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
- }
- list := make([]nats_server.DeviceData_R, 0)
- var count int64
- list, count, err = s.GetDataPage(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
- }
- // GetPrintData 获取打印的温湿度记录
- // @Summary 获取打印的温湿度记录
- // @Description 获取打印的温湿度记录
- // @Tags 运单任务
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.WaybillTaskGetDataPageReq true "body"
- // @Success 200 {object} response.Response{data=response.Page{list=[]model.WaybillTask}} "{"code": 200, "data": [...]}"
- // @Router /api/waybill-task/print-data [post]
- // @Security Bearer
- func (e WaybillTaskController) GetPrintData(c *gin.Context) {
- s := service.WaybillTask{}
- waybillSvc := service.Waybill{}
- companySvc := service.Company{}
- req := dto.WaybillTaskGetDataPageReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.JSON, nil).
- MakeService(&s.Service).
- MakeService(&companySvc.Service).
- MakeService(&waybillSvc.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- var waybill model.Waybill
- var company model.SysDept
- err = waybillSvc.GetByWaybillNo(&dto.WaybillGetByWaybillPdfReq{WaybillNo: req.WaybillNo}, &waybill, nil)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- err = companySvc.Get(&dto.CompanyGetReq{Id: waybill.DeptId}, &company)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- if company.PrintIntercept == true {
- var qualified bool
- qualified, err = waybillSvc.VerifyDataQualified(req.WaybillNo)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- if !qualified {
- err = errors.New("数据不合格,无法打印!")
- // 错误码 5000 提示无法打印
- e.Error(5000, err, err.Error())
- return
- }
- }
- list := make([]nats_server.DeviceData_R, 0)
- var count int64
- list, count, err = s.GetPrintDataPage(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
- }
- // GetNewestData 获取最新温湿度记录
- // @Summary 获取最新温湿度记录
- // @Description 获取最新温湿度记录
- // @Tags 运单任务
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.WaybillTaskGetNewestDataPageReq true "body"
- // @Success 200 {object} response.Response{data=response.Page{list=[]model.WaybillTask}} "{"code": 200, "data": [...]}"
- // @Router /api/waybill-task/newest-locus [post]
- // @Security Bearer
- func (e WaybillTaskController) GetNewestData(c *gin.Context) {
- s := service.WaybillTask{}
- req := dto.WaybillTaskGetNewestDataPageReq{}
- 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
- }
- data := nats_server.DeviceData_R{}
- data, err = s.GetNewestDataPage(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(data, "查询成功")
- }
- // GetLocus 获取轨迹信息
- // @Summary 获取轨迹信息
- // @Description 获取轨迹信息
- // @Tags 运单任务
- // @Accept application/json
- // @Product application/json
- // @Param waybillNo query string true "运单号"
- // @Success 200 {object} response.Response{data=response.Page{list=[]model.WaybillTask}} "{"code": 200, "data": [...]}"
- // @Router /api/waybill-task/locus [get]
- // @Security Bearer
- func (e WaybillTaskController) GetLocus(c *gin.Context) {
- s := service.WaybillTask{}
- req := dto.WaybillGetLocusReq{}
- 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
- }
- list := make([]nats_server.DeviceData_R2, 0)
- list, err = s.GetLocus(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(list, "获取轨迹信息成功")
- }
- // Update 修改运单任务
- // @Summary 修改运单任务
- // @Description 修改运单任务
- // @Tags 运单任务
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.WaybillTaskUpdateReq true "body"
- // @Success 200 {string} string "{"code": 200, "message": "修改成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "修改失败"}"
- // @Router /api/waybill [put]
- // @Security Bearer
- func (e WaybillTaskController) Update(c *gin.Context) {
- s := service.WaybillTask{}
- req := dto.WaybillTaskUpdateReq{}
- 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(nil, "修改成功")
- }
|