Browse Source

ADD:运单管理添加药品数量

zoie 10 months ago
parent
commit
04407c72e6

+ 25 - 22
app/admin/controller/waybill.go

@@ -30,6 +30,7 @@ import (
 	"os"
 	"path"
 	"sort"
+	"strconv"
 	"sync"
 	"time"
 )
@@ -160,13 +161,13 @@ func (e WaybillController) Export(c *gin.Context) {
 	}
 	timeStr := time.Now().Format("20060102150405")
 	filePath := "ofile/" + "运单" + timeStr + ".xlsx"
-	defer func() {
-		os.Remove(filePath)
-	}()
 	// 保存文件
 	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"))
@@ -278,9 +279,9 @@ func (e WaybillController) GetAppletCount(c *gin.Context) {
 	var statusCount = make(map[int]int)
 	statusCount[0] = int(count)
 	for _, waybill := range list {
-		if  _, ok := statusCount[waybill.Status]; ok {
+		if _, ok := statusCount[waybill.Status]; ok {
 			statusCount[waybill.Status] += 1
-		}else {
+		} else {
 			statusCount[waybill.Status] = 1
 		}
 	}
@@ -288,7 +289,6 @@ func (e WaybillController) GetAppletCount(c *gin.Context) {
 	e.OK(statusCount, "查询成功")
 }
 
-
 // Get 通过id获取运单
 // @Summary 通过id获取运单
 // @Description 通过id获取运单
@@ -926,10 +926,10 @@ func (e WaybillController) Import(c *gin.Context) {
 	}
 
 	var customerId int
-	customerName := req.CustomerName
+	//customerName := req.CustomerName
 	if userObj.UserType == model.UserTypeCustomer {
 		customerId = userObj.Id
-		customerName = userObj.NickName
+		//customerName = userObj.NickName
 	}
 
 	rows, _ := xlsx.GetRows("Sheet1")
@@ -945,21 +945,22 @@ func (e WaybillController) Import(c *gin.Context) {
 		for i, colCell := range row {
 			fmt.Println(i, ":", colCell)
 		}
-
+		quantity, _ := strconv.Atoi(row[10])
 		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],
+			CustomerName:            row[3],
+			ConsigneeAddressName:    row[4],
+			ConsigneeAddressPhone:   row[5],
+			ConsigneeAddressDetails: row[6],
+			TemperatureInterval:     row[7],
+			DeliveryCondition:       row[8],
+			CargoType:               row[9],
+			Quantity:                quantity,
+			Remark:                  row[11],
 			CustomerId:              customerId,
-			CustomerName:            customerName,
 		}
 		obj.SetDeptId(p.DeptId)
 		obj.SetCreateBy(user.GetUserId(c))
@@ -1302,9 +1303,9 @@ func (e WaybillController) TemperaturePDF(c *gin.Context) {
 	if y > 841.89 {
 		// 图片结束直接分页
 		pdf.AddPage()
-		y = 40
+		y = 20
 	}
-
+	y += 20
 	pdf.SetFont("wts", "", 16)
 	pdf.SetXY(10, y)
 	pdf.Text("记录数据信息")
@@ -1410,9 +1411,11 @@ func (e WaybillController) TemperaturePDF(c *gin.Context) {
 	if err != nil {
 		return
 	}
-	//defer func() {
-	//	os.Remove(filePath)
-	//}()
+	defer func() {
+		os.Remove(tempFilepath)
+		os.Remove(humidityFilepath)
+		os.Remove(filePath)
+	}()
 
 	c.Header("Content-Disposition", "attachment; filename="+url.PathEscape(filename))
 	c.Header("Content-Transfer-Encoding", "binary")

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

@@ -52,7 +52,8 @@ type Waybill struct {
 	CargoType               string      `json:"cargoType"  gorm:"size:128"`               // 货物类型
 	TemperatureInterval     string      `json:"temperatureInterval"  gorm:"size:128"`     // 温度要求
 	DeliveryCondition       string      `json:"deliveryCondition"  gorm:"size:128"`       // 配送要求
-	Remark                  string      `json:"remark"  gorm:"size:128"`                  // 运输备注
+	Quantity                int         `json:"quantity"  gorm:"size:128"`                // 药品数量
+	Remark                  string      `json:"remark"  gorm:"size:4"`                  // 运输备注
 	CustomerId              int         `json:"customerId" gorm:"size:4"`                 // 下单客户id
 	CustomerName            string      `json:"customerName" gorm:"size:128"`             // 下单客户名称
 	OrderTime               model2.Time `json:"orderTime"  gorm:"size:128"`               // 下单时间

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

@@ -54,6 +54,7 @@ type WaybillInsertReq struct {
 	CargoType               string `json:"cargoType"`                            //货物类型
 	TemperatureInterval     string `json:"temperatureInterval"`                  //温度要求
 	DeliveryCondition       string `json:"deliveryCondition"`                    //配送要求
+	Quantity                int    `json:"quantity"`                             //药品数量
 	Remark                  string `json:"remark"`                               //运输备注
 	CustomerId              int    `json:"customerId"`                           //下单客户id
 	CustomerName            string `json:"customerName"`                         //下单客户名称
@@ -75,6 +76,7 @@ func (s *WaybillInsertReq) Generate(m *model.Waybill) {
 	m.CargoType = s.CargoType
 	m.TemperatureInterval = s.TemperatureInterval
 	m.DeliveryCondition = s.DeliveryCondition
+	m.Quantity = s.Quantity
 	m.Remark = s.Remark
 	m.CustomerId = s.CustomerId
 	m.CustomerName = s.CustomerName
@@ -106,6 +108,7 @@ type WaybillUpdateReq struct {
 	CargoType               string `json:"cargoType"`                            //货物类型
 	TemperatureInterval     string `json:"temperatureInterval"`                  //温度要求
 	DeliveryCondition       string `json:"deliveryCondition"`                    //配送要求
+	Quantity                int    `json:"quantity"`                             //药品数量
 	Remark                  string `json:"remark"`                               //运输备注
 	CustomerName            string `json:"customerName"`                         //下单客户名称
 	model2.ControlBy        `swaggerignore:"true"`
@@ -125,6 +128,7 @@ func (s *WaybillUpdateReq) Generate(m *model.Waybill) {
 	m.CargoType = s.CargoType
 	m.TemperatureInterval = s.TemperatureInterval
 	m.DeliveryCondition = s.DeliveryCondition
+	m.Quantity = s.Quantity
 	m.Remark = s.Remark
 	m.CustomerName = s.CustomerName
 

+ 4 - 3
app/admin/service/waybill.go

@@ -264,7 +264,7 @@ func (e *Waybill) AppletInsert(c *dto.WaybillInsertReq, p *actions.DataPermissio
 		}
 		return global.CreateFailedErr
 	}
-	if userModel.Type != model.SysUserTypeDriver && userModel.Type != model.SysUserTypeWarehouse {
+	if (userModel.Type != model.SysUserTypeDriver && userModel.Type != model.SysUserTypeWarehouse) && userModel.UserType != "customer" {
 		err = errors.New("无权添加!")
 		return err
 	}
@@ -409,8 +409,9 @@ func (e *Waybill) Delivery(c *dto.WaybillDeliveryReq, p *actions.DataPermission)
 		if waybillModel.Status != model.WaybillStatusWaitDelivery &&
 			waybillModel.Status != model.WaybillStatusWaitTruck &&
 			waybillModel.Status != model.WaybillStatusWaitStorage {
-			err = errors.New(fmt.Sprintf("运单状态为%s,禁止操作!", model.WaybillStatusMap[waybillModel.Status]))
-			return err
+			//err = errors.New(fmt.Sprintf("运单状态为%s,禁止操作!", model.WaybillStatusMap[waybillModel.Status]))
+			//return err
+			continue
 		}
 
 		var car = model.Car{}