|
@@ -1,15 +1,22 @@
|
|
|
package controller
|
|
|
|
|
|
import (
|
|
|
+ "bufio"
|
|
|
"cold-logistics/app/admin/model"
|
|
|
"cold-logistics/app/admin/service"
|
|
|
"cold-logistics/app/admin/service/dto"
|
|
|
"cold-logistics/common/actions"
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
"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"
|
|
|
+ "path"
|
|
|
)
|
|
|
|
|
|
type WaybillController struct {
|
|
@@ -54,13 +61,50 @@ 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) GetAppletPage(c *gin.Context) {
|
|
|
+ s := service.Waybill{}
|
|
|
+ req := dto.WaybillGetAppletPageReq{}
|
|
|
+ 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
|
|
|
+ err = s.GetAppletPage(&req, &list, &count, p)
|
|
|
+ if err != nil {
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
|
|
|
+}
|
|
|
+
|
|
|
// Get 通过id获取运单
|
|
|
// @Summary 通过id获取运单
|
|
|
// @Description 通过id获取运单
|
|
|
// @Tags 运单
|
|
|
// @Param id path string true "运单id"
|
|
|
// @Success 200 {object} response.Response{data=model.Waybill} "{"code": 200, "data": [...]}"
|
|
|
-// @Router /api/warehouse/{id} [get]
|
|
|
+// @Router /api/waybill/{id} [get]
|
|
|
// @Security Bearer
|
|
|
func (e WaybillController) Get(c *gin.Context) {
|
|
|
s := service.Waybill{}
|
|
@@ -370,3 +414,260 @@ func (e WaybillController) CarOut(c *gin.Context) {
|
|
|
}
|
|
|
e.OK(req.WaybillNoList, "下车成功")
|
|
|
}
|
|
|
+
|
|
|
+// Receipt 签收
|
|
|
+// @Summary 签收
|
|
|
+// @Description 签收
|
|
|
+// @Tags 运单
|
|
|
+// @Accept application/json
|
|
|
+// @Product application/json
|
|
|
+// @Param data body dto.WaybillInOutReq true "body"
|
|
|
+// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
|
|
+// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
|
|
|
+// @Router /api/waybill/car-out [post]
|
|
|
+// @Security Bearer
|
|
|
+func (e WaybillController) Receipt(c *gin.Context) {
|
|
|
+ s := service.Waybill{}
|
|
|
+ req := dto.WaybillInOutReq{}
|
|
|
+ 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.Receipt(&req, p)
|
|
|
+ if err != nil {
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ e.OK(req.WaybillNoList, "下车成功")
|
|
|
+}
|
|
|
+
|
|
|
+// GetCustomerPage 获取客户运单列表
|
|
|
+// @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/customer [get]
|
|
|
+// @Security Bearer
|
|
|
+func (e WaybillController) GetCustomerPage(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
|
|
|
+ err = s.GetCustomerPage(&req, &list, &count, p)
|
|
|
+ if err != nil {
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
|
|
|
+}
|
|
|
+
|
|
|
+// CustomerInsert 客户添加运单
|
|
|
+// @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/customer [post]
|
|
|
+// @Security Bearer
|
|
|
+func (e WaybillController) CustomerInsert(c *gin.Context) {
|
|
|
+ s := service.Waybill{}
|
|
|
+ userSvc := service.SysUser{}
|
|
|
+ req := dto.WaybillInsertReq{}
|
|
|
+ err := e.MakeContext(c).
|
|
|
+ MakeOrm().
|
|
|
+ Bind(&req, binding.JSON).
|
|
|
+ MakeService(&s.Service).
|
|
|
+ MakeService(&userSvc.Service).
|
|
|
+ Errors
|
|
|
+ if err != nil {
|
|
|
+ e.Logger.Error(err)
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ p := actions.GetPermissionFromContext(c)
|
|
|
+ var userObj model.SysUser
|
|
|
+ err = userSvc.Get(&dto.SysUserGetReq{Id: p.UserId}, nil, &userObj)
|
|
|
+ if err != nil {
|
|
|
+ e.Error(500, err, "获取用户信息失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if p.DeptId == 0 && req.DeptId == 0 {
|
|
|
+ e.Error(500, err, "请先选择运输公司")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 设置创建人
|
|
|
+ req.SetCreateBy(user.GetUserId(c))
|
|
|
+ req.CustomerId = p.UserId
|
|
|
+ req.CustomerName = userObj.NickName
|
|
|
+ if p.DeptId > 0 {
|
|
|
+ req.SetDeptId(p.DeptId)
|
|
|
+ }
|
|
|
+ err = s.Insert(&req)
|
|
|
+ if err != nil {
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ e.OK(req.GetId(), "创建成功")
|
|
|
+}
|
|
|
+func (e WaybillController) Import(c *gin.Context) {
|
|
|
+ s := service.Waybill{}
|
|
|
+ userSvc := service.SysUser{}
|
|
|
+ req := dto.WaybillImportReq{}
|
|
|
+ err := e.MakeContext(c).
|
|
|
+ MakeOrm().
|
|
|
+ Bind(&req, binding.Form).
|
|
|
+ MakeService(&s.Service).
|
|
|
+ MakeService(&userSvc.Service).
|
|
|
+ Errors
|
|
|
+ if err != nil {
|
|
|
+ e.Logger.Error(err)
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //读取第一fileName的文件
|
|
|
+ fileHeader, err := c.FormFile("file")
|
|
|
+ if err != nil {
|
|
|
+ err = errors.New("文件格式错误" + err.Error())
|
|
|
+ e.Logger.Error(err)
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if fileHeader.Size > 1024*1024*2 {
|
|
|
+ err = errors.New("文件大小超过2M")
|
|
|
+ e.Logger.Error(err)
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ file, err := fileHeader.Open()
|
|
|
+ if err != nil {
|
|
|
+ err = errors.New("文件格式错误" + err.Error())
|
|
|
+ e.Logger.Error(err)
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer file.Close()
|
|
|
+
|
|
|
+ xlsx, err := excelize.OpenReader(bufio.NewReader(file))
|
|
|
+ if err != nil {
|
|
|
+ err = errors.New("文件格式错误" + err.Error())
|
|
|
+ e.Logger.Error(err)
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ p := actions.GetPermissionFromContext(c)
|
|
|
+ if p.DeptId == 0 {
|
|
|
+ e.Error(500, err, "获取用户信息失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var userObj model.SysUser
|
|
|
+ err = userSvc.Get(&dto.SysUserGetReq{Id: p.UserId}, nil, &userObj)
|
|
|
+ if err != nil {
|
|
|
+ e.Error(500, err, "获取用户信息失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var customerId int
|
|
|
+ customerName := req.CustomerName
|
|
|
+ if userObj.UserType == model.UserTypeCustomer {
|
|
|
+ customerId = userObj.Id
|
|
|
+ customerName = userObj.NickName
|
|
|
+ }
|
|
|
+
|
|
|
+ rows, _ := xlsx.GetRows("Sheet1")
|
|
|
+ for indexRow, row := range rows {
|
|
|
+ if indexRow == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ for i, colCell := range row {
|
|
|
+ fmt.Println(i, ":", colCell)
|
|
|
+ }
|
|
|
+ obj := dto.WaybillInsertReq{
|
|
|
+ Status: 1,
|
|
|
+ SenderAddressName: row[0],
|
|
|
+ SenderAddressPhone: row[1],
|
|
|
+ SenderAddressDetails: row[2],
|
|
|
+ ConsigneeAddressName: row[3],
|
|
|
+ ConsigneeAddressPhone: row[4],
|
|
|
+ ConsigneeAddressDetails: row[5],
|
|
|
+ TemperatureInterval: row[6],
|
|
|
+ DeliveryCondition: row[7],
|
|
|
+ CargoType: row[8],
|
|
|
+ Remark: row[9],
|
|
|
+ CustomerId: customerId,
|
|
|
+ CustomerName: customerName,
|
|
|
+ }
|
|
|
+ obj.SetDeptId(p.DeptId)
|
|
|
+ obj.SetCreateBy(user.GetUserId(c))
|
|
|
+ err = s.Insert(&obj)
|
|
|
+ if err != nil {
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ e.OK(len(rows)-1, "导入成功")
|
|
|
+}
|
|
|
+func (e WaybillController) ExportTemplate(c *gin.Context) {
|
|
|
+ s := service.Waybill{}
|
|
|
+ err := e.MakeContext(c).
|
|
|
+ MakeOrm().
|
|
|
+ MakeService(&s.Service).
|
|
|
+ Errors
|
|
|
+ if err != nil {
|
|
|
+ e.Logger.Error(err)
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ filePath := "./ofile/运单导入模板.xlsx"
|
|
|
+ //打开文件
|
|
|
+ fileTmp, errByOpenFile := os.Open(filePath)
|
|
|
+ defer fileTmp.Close()
|
|
|
+
|
|
|
+ //获取文件的名称
|
|
|
+ fileName := path.Base(filePath)
|
|
|
+ if errByOpenFile != nil {
|
|
|
+ e.Logger.Error(err)
|
|
|
+ e.Error(500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.Header("Content-Type", "application/vnd.ms-excel;charset=utf8")
|
|
|
+ // PathEscape 函数对中文做处理
|
|
|
+ c.Header("Content-Disposition", "attachment; filename="+url.PathEscape(fileName))
|
|
|
+ c.Header("Content-Transfer-Encoding", "binary")
|
|
|
+ c.File(filePath)
|
|
|
+
|
|
|
+}
|