Browse Source

ADD:图片上传,运单签收添加签收图片

zoie 11 months ago
parent
commit
9a11423c8b

+ 2 - 5
app/admin/controller/upload.go

@@ -2,6 +2,7 @@ package controller
 
 import (
 	"cold-logistics/common/file_store"
+	"cold-logistics/conf"
 	"fmt"
 	"github.com/gin-gonic/gin"
 	"github.com/google/uuid"
@@ -31,8 +32,6 @@ func (e UploadController) FilesUpload(c *gin.Context) {
 
 	// 处理文件上传逻辑
 	file, err := c.FormFile("file")
-	//bizType := c.PostForm("bizType")
-	//correlationCode := c.PostForm("correlationCode")
 	uploadFileName := file.Filename          // 获取文件名
 	fileType := filepath.Ext(uploadFileName) // 获取文件类型(扩展名)
 	if err != nil {
@@ -50,8 +49,6 @@ func (e UploadController) FilesUpload(c *gin.Context) {
 		os.Remove(filePath)
 	}()
 
-	// TODO: 文件上传到省平台
-
 	filename := fmt.Sprintf("%s/%s%s", time.Now().Format("2006-01-02"), strings.Replace(uuid.New().String(), "-", "", -1), fileType)
 
 	err = file_store.QiniuFileStore.UpLoad(filename, filePath)
@@ -62,7 +59,7 @@ func (e UploadController) FilesUpload(c *gin.Context) {
 
 	e.Custom(gin.H{
 		"code": 200,
-		"data": filename,
+		"data": conf.ExtConfig.Qiniu.Endpoint + filename,
 		"msg":  "success",
 	})
 }

+ 2 - 2
app/admin/controller/waybill.go

@@ -462,7 +462,7 @@ func (e WaybillController) CarOut(c *gin.Context) {
 // @Security Bearer
 func (e WaybillController) Receipt(c *gin.Context) {
 	s := service.Waybill{}
-	req := dto.WaybillInOutReq{}
+	req := dto.WaybillReceiptReq{}
 	err := e.MakeContext(c).
 		MakeOrm().
 		Bind(&req, binding.JSON, nil).
@@ -481,7 +481,7 @@ func (e WaybillController) Receipt(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
-	e.OK(req.WaybillNoList, "下车成功")
+	e.OK(req.WaybillNo, "签收成功")
 }
 
 // GetCustomerPage 获取客户运单列表

+ 9 - 6
app/admin/model/car.go

@@ -1,15 +1,18 @@
 package model
 
-import model2 "cold-logistics/common/model"
+import (
+	model2 "cold-logistics/common/model"
+)
 
 // 仓库
 type Car struct {
 	model2.Model
-	CarNo  string      `json:"carNo" gorm:"size:128"`                                // 商品名称
-	Sn     string      `json:"sn" gorm:"size:128"`                                   // sn
-	Status string      `json:"status" gorm:"size:4;not null;default:'2';comment:状态"` // 1-停用 2-正启用
-	UserId int         `json:"userId" gorm:"size:255;"`                              // 司机id
-	User   SysUserOmit `json:"user"`
+	CarNo     string            `json:"carNo" gorm:"size:128"`                                // 商品名称
+	Sn        string            `json:"sn" gorm:"size:128"`                                   // sn
+	Status    string            `json:"status" gorm:"size:4;not null;default:'2';comment:状态"` // 1-停用 2-正启用
+	UserId    int               `json:"userId" gorm:"size:255;"`                              // 司机id
+	HistorySn model2.StringList `json:"historySn"`                                            // 历史绑定的sn
+	User      SysUserOmit       `json:"user"`
 	model2.ControlBy
 	model2.ModelTime
 	model2.DeptBy

+ 8 - 6
app/admin/model/warehouse.go

@@ -5,12 +5,14 @@ import model2 "cold-logistics/common/model"
 // 仓库
 type Warehouse struct {
 	model2.Model
-	Name    string      `json:"name" gorm:"size:128"`                                 // 商品名称
-	Sn      string      `json:"sn" gorm:"size:128"`                                   // sn
-	Address string      `json:"address" gorm:"size:255;"`                             // 地址
-	Status  string      `json:"status" gorm:"size:4;not null;default:'2';comment:状态"` // 1-停用 2-正启用
-	UserId  int         `json:"userId" gorm:"size:255;"`                              // 仓管id
-	User    SysUserOmit `json:"user"`
+	Name      string            `json:"name" gorm:"size:128"`                                 // 商品名称
+	Sn        string            `json:"sn" gorm:"size:128"`                                   // sn
+	Address   string            `json:"address" gorm:"size:255;"`                             // 地址
+	Status    string            `json:"status" gorm:"size:4;not null;default:'2';comment:状态"` // 1-停用 2-正启用
+	UserId    int               `json:"userId" gorm:"size:255;"`                              // 仓管id
+	HistorySn model2.StringList `json:"historySn"`                                            // 历史绑定的sn
+
+	User SysUserOmit `json:"user"`
 	model2.ControlBy
 	model2.ModelTime
 	model2.DeptBy

+ 1 - 0
app/admin/model/waybill.go

@@ -47,6 +47,7 @@ type Waybill struct {
 	ReceiptTime             model2.Time `json:"receiptTime"  gorm:"size:128"`             //签收时间
 	WarehouseId             int         `json:"warehouseId"  gorm:"size:128"`             // 仓库id
 	CarId                   int         `json:"carId"  gorm:"size:128"`                   // 仓库id
+	ReceiptImg              string      `json:"ReceiptImg"  gorm:"size:128"`              // 签收图片
 
 	Freight   float64     `json:"freight"  gorm:"size:9"` //运费
 	PrintUser SysUserOmit `json:"printUser" gorm:"->;foreignkey:PrintUserId;references:Id"`

+ 3 - 0
app/admin/service/car.go

@@ -104,6 +104,7 @@ func (e *Car) Insert(c *dto.CarInsertReq) error {
 
 	// 添加仓库
 	c.Generate(&data)
+	data.HistorySn = []string{data.Sn}
 	err = tx.Create(&data).Error
 	if err != nil {
 		e.Log.Errorf("db error: %s", err)
@@ -153,6 +154,8 @@ func (e *Car) Update(c *dto.CarUpdateReq, p *actions.DataPermission) error {
 			e.Log.Errorf("db error: %s", err)
 			return err
 		}
+
+		carModel.HistorySn = append(carModel.HistorySn, c.Sn)
 	}
 
 	c.Generate(&carModel)

+ 1 - 1
app/admin/service/dto/sys_user.go

@@ -95,7 +95,7 @@ func (s *SysUserInsertReq) Generate(userModel *model.SysUser) {
 	userModel.RoleId = s.RoleId
 	userModel.Status = "2"
 	userModel.Type = s.Type
-	userModel.UserType = model.UserTypeCustomer
+	userModel.UserType = model.UserTypeSys
 
 	if s.ControlBy.UpdateBy != 0 {
 		userModel.UpdateBy = s.UpdateBy

+ 7 - 0
app/admin/service/dto/waybill.go

@@ -171,6 +171,13 @@ type WaybillInOutReq struct {
 	WaybillNoList []string    `json:"waybillNoList"  gorm:"size:128"` // 订单编号
 }
 
+// 运单签收
+type WaybillReceiptReq struct {
+	StartTime  model2.Time `json:"startTime"`
+	WaybillNo  string      `json:"waybillNo"  gorm:"size:128"`  // 订单编号
+	ReceiptImg string      `json:"receiptImg"  gorm:"size:128"` // 签收图片
+}
+
 type WaybillGetAppletPageReq struct {
 	dto.Pagination `search:"-"`
 	WaybillNo      string `form:"waybillNo" search:"type:contains;column:waybill_no;table:waybill_logistics"` // 运单编号

+ 1 - 0
app/admin/service/dto/waybill_logistics.go

@@ -11,6 +11,7 @@ type WaybillLogisticsGetPageReq struct {
 
 type WaybillLogisticsOrder struct {
 	CreatedAtOrder string `search:"type:order;column:created_at;table:waybill_logistics" form:"createdAtOrder" default:"desc"`
+	IdOrder        string `search:"type:order;column:id;table:waybill_logistics" form:"idOrder" default:"desc"`
 }
 
 func (m *WaybillLogisticsGetPageReq) GetNeedSearch() interface{} {

+ 2 - 0
app/admin/service/warehouse.go

@@ -104,6 +104,7 @@ func (e *Warehouse) Insert(c *dto.WarehouseInsertReq) error {
 
 	// 添加仓库
 	c.Generate(&data)
+	data.HistorySn = []string{c.Sn}
 	err = tx.Create(&data).Error
 	if err != nil {
 		e.Log.Errorf("db error: %s", err)
@@ -152,6 +153,7 @@ func (e *Warehouse) Update(c *dto.WarehouseUpdateReq, p *actions.DataPermission)
 			e.Log.Errorf("db error: %s", err)
 			return err
 		}
+		warehouseModel.HistorySn = append(warehouseModel.HistorySn, c.Sn)
 	}
 
 	c.Generate(&warehouseModel)

+ 80 - 82
app/admin/service/waybill.go

@@ -909,7 +909,7 @@ func (e *Waybill) CarOut(c *dto.WaybillInOutReq, p *actions.DataPermission) erro
 
 	return nil
 }
-func (e *Waybill) Receipt(c *dto.WaybillInOutReq, p *actions.DataPermission) error {
+func (e *Waybill) Receipt(c *dto.WaybillReceiptReq, p *actions.DataPermission) error {
 	var err error
 
 	tx := e.Orm.Begin()
@@ -931,95 +931,70 @@ func (e *Waybill) Receipt(c *dto.WaybillInOutReq, p *actions.DataPermission) err
 		return errors.New("获取车辆信息失败")
 	}
 
-	for _, waybillNo := range c.WaybillNoList {
-		var waybillModel = model.Waybill{}
-		// 查询运单是否存在
-		err = tx.Scopes(actions.Permission(waybillModel.TableName(), p)).
-			Where("waybill_no = ?", waybillNo).
-			First(&waybillModel).Error
-		if err != nil {
-			e.Log.Errorf("db error: %s", err)
-			if errors.Is(err, gorm.ErrRecordNotFound) {
-				return errors.New(fmt.Sprintf("运单号%s不存在", waybillNo))
-			}
-			return errors.New(fmt.Sprintf("运单号%s查询失败", waybillNo))
+	var waybillModel = model.Waybill{}
+	// 查询运单是否存在
+	err = tx.Scopes(actions.Permission(waybillModel.TableName(), p)).
+		Where("waybill_no = ?", c.WaybillNo).
+		First(&waybillModel).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return errors.New(fmt.Sprintf("运单号%s不存在", c.WaybillNo))
 		}
+		return errors.New(fmt.Sprintf("运单号%s查询失败", c.WaybillNo))
+	}
 
-		if waybillModel.Status == model.WaybillStatusReceipt {
-			continue
-		}
-		waybillModel.Status = model.WaybillStatusReceipt
-		waybillModel.CarId = car.Id
-		waybillModel.ReceiptTime = model2.Time(time.Now())
-		err = tx.Save(&waybillModel).Error
-		if err != nil {
-			e.Log.Errorf("db error: %s", err)
-			return errors.New(fmt.Sprintf("保存运单信息失败:%s", err))
-		}
-		// 获取传感器信息
-		// 获取传感器信息
-		var deviceSensorList = []nats_server.DeviceSensor_R{}
-		var count int64
-		deviceSensorList, count, err = nats_server.Cold_CompanyDeviceSensor_List_ByKey(car.Sn)
-		if err != nil || count == 0 {
-			err = errors.New("查询设备定位信息失败")
-			return err
-		}
-		var lng, Lat string
-		if len(deviceSensorList[0].T_DeviceSensorData.T_site) > 0 {
-			site := strings.Split(deviceSensorList[0].T_DeviceSensorData.T_site, ",")
-			if len(site) == 2 {
-				lng = site[0]
-				Lat = site[1]
-			}
+	if waybillModel.Status == model.WaybillStatusReceipt {
+		return nil
+	}
+	waybillModel.Status = model.WaybillStatusReceipt
+	waybillModel.CarId = car.Id
+	waybillModel.ReceiptTime = c.StartTime
+	waybillModel.ReceiptImg = c.ReceiptImg
+	err = tx.Save(&waybillModel).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return errors.New(fmt.Sprintf("保存运单信息失败:%s", err))
+	}
+	// 获取传感器信息
+	// 获取传感器信息
+	var deviceSensorList = []nats_server.DeviceSensor_R{}
+	var count int64
+	deviceSensorList, count, err = nats_server.Cold_CompanyDeviceSensor_List_ByKey(car.Sn)
+	if err != nil || count == 0 {
+		err = errors.New("查询设备定位信息失败")
+		return err
+	}
+	var lng, Lat string
+	if len(deviceSensorList[0].T_DeviceSensorData.T_site) > 0 {
+		site := strings.Split(deviceSensorList[0].T_DeviceSensorData.T_site, ",")
+		if len(site) == 2 {
+			lng = site[0]
+			Lat = site[1]
 		}
+	}
 
-		// 查询任务
-		var task model.WaybillTask
-		err = tx.Model(&task).Where("waybill_no = ? and car_id = ?", waybillNo, car.Id).
-			Last(&task).Error
+	// 查询任务
+	var task model.WaybillTask
+	err = tx.Model(&task).Where("waybill_no = ? and car_id = ?", c.WaybillNo, car.Id).
+		Last(&task).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return errors.New(fmt.Sprintf("查询运单任务信息失败:%s", err))
+	}
+	// 未下车 直接点签收
+	if time.Time(task.EndTime).IsZero() {
+		task.EndTime = model2.Time(time.Now())
+		task.UpdateBy = p.UserId
+		err = tx.Save(&task).Error
 		if err != nil {
 			e.Log.Errorf("db error: %s", err)
-			return errors.New(fmt.Sprintf("查询运单任务信息失败:%s", err))
-		}
-		// 未下车 直接点签收
-		if time.Time(task.EndTime).IsZero() {
-			task.EndTime = model2.Time(time.Now())
-			task.UpdateBy = p.UserId
-			err = tx.Save(&task).Error
-			if err != nil {
-				e.Log.Errorf("db error: %s", err)
-				return errors.New(fmt.Sprintf("保存运单任务信息失败:%s", err))
-			}
-			// 添加下车物流记录
-			Logistics := model.WaybillLogistics{
-				WaybillNo: waybillNo,
-				Status:    model.WaybillStatusTruckOut,
-				CarId:     car.Id,
-				UserId:    p.UserId,
-				Lng:       lng,
-				Lat:       Lat,
-				ControlBy: model2.ControlBy{
-					CreateBy: p.UserId,
-				},
-				DeptBy: model2.DeptBy{
-					DeptId: p.DeptId,
-				},
-				ModelTime: model2.ModelTime{
-					CreatedAt: c.StartTime,
-				},
-			}
-			err = tx.Create(&Logistics).Error
-			if err != nil {
-				e.Log.Errorf("db error: %s", err)
-				return errors.New(fmt.Sprintf("保存运单物流信息失败:%s", err))
-			}
+			return errors.New(fmt.Sprintf("保存运单任务信息失败:%s", err))
 		}
-
-		// 添加签收记录
+		// 添加下车物流记录
 		Logistics := model.WaybillLogistics{
-			WaybillNo: waybillNo,
-			Status:    model.WaybillStatusReceipt,
+			WaybillNo: c.WaybillNo,
+			Status:    model.WaybillStatusTruckOut,
 			CarId:     car.Id,
 			UserId:    p.UserId,
 			Lng:       lng,
@@ -1039,7 +1014,30 @@ func (e *Waybill) Receipt(c *dto.WaybillInOutReq, p *actions.DataPermission) err
 			e.Log.Errorf("db error: %s", err)
 			return errors.New(fmt.Sprintf("保存运单物流信息失败:%s", err))
 		}
+	}
 
+	// 添加签收记录
+	Logistics := model.WaybillLogistics{
+		WaybillNo: c.WaybillNo,
+		Status:    model.WaybillStatusReceipt,
+		CarId:     car.Id,
+		UserId:    p.UserId,
+		Lng:       lng,
+		Lat:       Lat,
+		ControlBy: model2.ControlBy{
+			CreateBy: p.UserId,
+		},
+		DeptBy: model2.DeptBy{
+			DeptId: p.DeptId,
+		},
+		ModelTime: model2.ModelTime{
+			CreatedAt: c.StartTime,
+		},
+	}
+	err = tx.Create(&Logistics).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return errors.New(fmt.Sprintf("保存运单物流信息失败:%s", err))
 	}
 
 	return nil

+ 12 - 0
common/model/byat.go

@@ -2,6 +2,7 @@ package model
 
 import (
 	"database/sql/driver"
+	"encoding/json"
 	"fmt"
 	"gorm.io/gorm"
 	"time"
@@ -96,3 +97,14 @@ func (t *Time) Scan(v interface{}) error {
 	}
 	return fmt.Errorf("can not convert %v to timestamp", v)
 }
+
+type StringList []string
+
+func (e StringList) Value() (driver.Value, error) {
+	d, err := json.Marshal(e)
+	return string(d), err
+}
+
+func (e *StringList) Scan(src interface{}) error {
+	return json.Unmarshal(src.([]byte), e)
+}