|
@@ -8,6 +8,7 @@ import (
|
|
|
"cold-logistics/common/actions"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "github.com/beego/beego/v2/core/logs"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"github.com/gin-gonic/gin/binding"
|
|
|
"github.com/xuri/excelize/v2"
|
|
@@ -17,6 +18,7 @@ import (
|
|
|
"net/url"
|
|
|
"os"
|
|
|
"path"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
type WaybillController struct {
|
|
@@ -61,6 +63,104 @@ func (e WaybillController) GetPage(c *gin.Context) {
|
|
|
e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
|
|
|
}
|
|
|
|
|
|
+// GetPage 获取运单列表
|
|
|
+// @Summary 获取运单列表
|
|
|
+// @Description 获取运单列表
|
|
|
+// @Tags 运单
|
|
|
+// @Param no query string false "运单号"
|
|
|
+// @Param pageSize query int false "页条数"
|
|
|
+// @Param page query int false "页码"
|
|
|
+// @Success 200 {object} response.Response{data=response.Page{list=[]model.Waybill}} "{"code": 200, "data": [...]}"
|
|
|
+// @Router /api/waybill [get]
|
|
|
+// @Security Bearer
|
|
|
+func (e WaybillController) Export(c *gin.Context) {
|
|
|
+ s := service.Waybill{}
|
|
|
+ req := dto.WaybillGetPageReq{}
|
|
|
+ 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.Waybill, 0)
|
|
|
+ var count int64
|
|
|
+ req.PageSize = 9999
|
|
|
+ err = s.GetPage(&req, &list, &count, p)
|
|
|
+ if err != nil {
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ f := excelize.NewFile() // 设置单元格的值
|
|
|
+ // 这里设置表头ÒÒ
|
|
|
+ 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.SetCellValue("Sheet1", "L1", "运输备注")
|
|
|
+
|
|
|
+ // 设置列宽
|
|
|
+ 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", "K", 15)
|
|
|
+ f.SetColWidth("Sheet1", "L", "L", 15)
|
|
|
+
|
|
|
+ line := 1
|
|
|
+
|
|
|
+ // 循环写入数据
|
|
|
+ for i, v := range list {
|
|
|
+ line++
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), model.WaybillStatusMap[v.Status])
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.SenderAddressName)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.SenderAddressPhone)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.SenderAddressDetails)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.ConsigneeAddressName)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.ConsigneeAddressPhone)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.ConsigneeAddressDetails)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v.TemperatureInterval)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.DeliveryCondition)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), v.CargoType)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), v.Remark)
|
|
|
+
|
|
|
+ }
|
|
|
+ timeStr := time.Now().Format("20060102150405")
|
|
|
+ filePath := "ofile/" + "运单" + timeStr + ".xlsx"
|
|
|
+ defer func() {
|
|
|
+ os.Remove(filePath)
|
|
|
+ }()
|
|
|
+ // 保存文件
|
|
|
+ if err = f.SaveAs(filePath); err != nil {
|
|
|
+ logs.Error("保存运单失败:", err)
|
|
|
+ }
|
|
|
+ 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)
|
|
|
+}
|
|
|
+
|
|
|
// Home 首页统计
|
|
|
// @Summary 首页统计
|
|
|
// @Description 首页统计
|
|
@@ -553,6 +653,95 @@ func (e WaybillController) GetCustomerPage(c *gin.Context) {
|
|
|
e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
|
|
|
}
|
|
|
|
|
|
+func (e WaybillController) CustomerExport(c *gin.Context) {
|
|
|
+ s := service.Waybill{}
|
|
|
+ req := dto.WaybillGetCustomerPageReq{}
|
|
|
+ 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.Waybill, 0)
|
|
|
+ var count int64
|
|
|
+ req.CustomerId = p.UserId
|
|
|
+ req.PageSize = 9999
|
|
|
+ err = s.GetCustomerPage(&req, &list, &count, p)
|
|
|
+ if err != nil {
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ f := excelize.NewFile() // 设置单元格的值
|
|
|
+ // 这里设置表头ÒÒ
|
|
|
+ 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.SetCellValue("Sheet1", "L1", "运输备注")
|
|
|
+
|
|
|
+ // 设置列宽
|
|
|
+ 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", "K", 15)
|
|
|
+ f.SetColWidth("Sheet1", "L", "L", 15)
|
|
|
+
|
|
|
+ line := 1
|
|
|
+
|
|
|
+ // 循环写入数据
|
|
|
+ for i, v := range list {
|
|
|
+ line++
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), model.GetCustomerWaybillStatus(v.Status))
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.SenderAddressName)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.SenderAddressPhone)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.SenderAddressDetails)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.ConsigneeAddressName)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.ConsigneeAddressPhone)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.ConsigneeAddressDetails)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v.TemperatureInterval)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.DeliveryCondition)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), v.CargoType)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), v.Remark)
|
|
|
+
|
|
|
+ }
|
|
|
+ timeStr := time.Now().Format("20060102150405")
|
|
|
+ filePath := "ofile/" + "运单" + timeStr + ".xlsx"
|
|
|
+ defer func() {
|
|
|
+ os.Remove(filePath)
|
|
|
+ }()
|
|
|
+ // 保存文件
|
|
|
+ if err = f.SaveAs(filePath); err != nil {
|
|
|
+ logs.Error("保存运单失败:", err)
|
|
|
+ }
|
|
|
+ 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)
|
|
|
+}
|
|
|
+
|
|
|
// CustomerInsert 客户添加运单
|
|
|
// @Summary 客户添加运单
|
|
|
// @Description 客户添加运单
|
|
@@ -604,6 +793,18 @@ func (e WaybillController) CustomerInsert(c *gin.Context) {
|
|
|
}
|
|
|
e.OK(req.GetId(), "创建成功")
|
|
|
}
|
|
|
+
|
|
|
+// Import 导入运单
|
|
|
+// @Summary 导入运单
|
|
|
+// @Description 导入运单
|
|
|
+// @Tags 运单
|
|
|
+// @Accept application/json
|
|
|
+// @Product application/json
|
|
|
+// @Param data body dto.WaybillInsertReq true "data"
|
|
|
+// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
|
|
+// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
|
|
+// @Router /api/waybill/import [post]
|
|
|
+// @Security Bearer
|
|
|
func (e WaybillController) Import(c *gin.Context) {
|
|
|
s := service.Waybill{}
|
|
|
userSvc := service.SysUser{}
|
|
@@ -711,6 +912,18 @@ func (e WaybillController) Import(c *gin.Context) {
|
|
|
|
|
|
e.OK(len(rows)-1, "导入成功")
|
|
|
}
|
|
|
+
|
|
|
+// ExportTemplate 导出运单模板
|
|
|
+// @Summary 导出运单模板
|
|
|
+// @Description 导出运单模板
|
|
|
+// @Tags 运单
|
|
|
+// @Accept application/json
|
|
|
+// @Product application/json
|
|
|
+// @Param data body dto.WaybillInsertReq true "data"
|
|
|
+// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
|
|
+// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
|
|
+// @Router /api/waybill/export-template [post]
|
|
|
+// @Security Bearer
|
|
|
func (e WaybillController) ExportTemplate(c *gin.Context) {
|
|
|
s := service.Waybill{}
|
|
|
err := e.MakeContext(c).
|