Преглед изворни кода

update:优化swagger接口文档

zoie пре 9 месеци
родитељ
комит
2924e88b8a

+ 2 - 12
README.md

@@ -61,26 +61,16 @@ env GOOS=windows GOARCH=amd64 go build main.go
 env GOOS=linux GOARCH=amd64 go build main.go
 ```
 
-### 初始化数据库,以及服务启动
-
-``` bash
-# 首次配置需要初始化数据库资源信息
-# macOS or linux 下使用
-$ ./OAuth migrate -c conf/settings.yml
-
-# ️注意:windows 下使用
-$ OAuth.exe migrate -c conf/settings.yml
-```
 
 ### 启动服务,也可以用IDE进行调试
 
 ```shell
 # macOS or linux 下使用
-$ ./OAuth server -c conf/settings.yml
+$ ./cold-logistics server -c conf/settings.yml
 
 
 # 注意:windows 下使用
-$ OAuth.exe server -c conf/settings.yml
+$ cold-logistics.exe server -c conf/settings.yml
 ```
 
 ### 接口文档

+ 7 - 4
app/admin/controller/address.go

@@ -21,6 +21,9 @@ type AddressController struct {
 // @Summary 获取地址列表
 // @Description 获取地址列表
 // @Tags 地址
+// @Param name query int false "电话/地址/省市区"
+// @Param addressType query int false "地址类型:sender-发货人 consignee-收货人"
+// @Param dataType query int false "我的my 全部all"
 // @Param pageSize query int false "页条数"
 // @Param page query int false "页码"
 // @Success 200 {object} response.Response{data=response.Page{list=[]model.Address}} "{"code": 200, "data": [...]}"
@@ -128,7 +131,7 @@ func (e AddressController) Insert(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
-	e.OK(req.GetId(), "创建成功")
+	e.OK(req.GetId(), "添加成功")
 }
 
 // Update 修改地址
@@ -138,8 +141,8 @@ func (e AddressController) Insert(c *gin.Context) {
 // @Accept  application/json
 // @Product application/json
 // @Param data body dto.AddressUpdateReq true "body"
-// @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
-// @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
+// @Success 200 {string} string	"{"code": 200, "message": "修改成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "修改失败"}"
 // @Router /api/address [put]
 // @Security Bearer
 func (e AddressController) Update(c *gin.Context) {
@@ -163,7 +166,7 @@ func (e AddressController) Update(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
-	e.OK(req.GetId(), "更新成功")
+	e.OK(req.GetId(), "修改成功")
 }
 
 // Delete 删除地址

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

@@ -21,6 +21,9 @@ type CarController struct {
 // @Description 获取车辆列表
 // @Tags 车辆
 // @Param name query string false "车辆名称"
+// @Param sn query string false "车辆关联sn"
+// @Param status query string false "状态:1-停用 2-启用"
+// @Param isBind query bool false "是否绑定司机"
 // @Param pageSize query int false "页条数"
 // @Param page query int false "页码"
 // @Success 200 {object} response.Response{data=response.Page{list=[]model.Car}} "{"code": 200, "data": [...]}"
@@ -121,7 +124,7 @@ func (e CarController) Insert(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
-	e.OK(req.GetId(), "创建成功")
+	e.OK(req.GetId(), "添加成功")
 }
 
 // Update 修改车辆
@@ -131,8 +134,8 @@ func (e CarController) Insert(c *gin.Context) {
 // @Accept  application/json
 // @Product application/json
 // @Param data body dto.CarUpdateReq true "body"
-// @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
-// @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
+// @Success 200 {string} string	"{"code": 200, "message": "修改成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "修改失败"}"
 // @Router /api/car [put]
 // @Security Bearer
 func (e CarController) Update(c *gin.Context) {
@@ -156,7 +159,7 @@ func (e CarController) Update(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
-	e.OK(req.GetId(), "更新成功")
+	e.OK(req.GetId(), "修改成功")
 }
 
 // Delete 删除车辆
@@ -202,7 +205,7 @@ func (e CarController) Delete(c *gin.Context) {
 // @Tags 保温箱
 // @Accept  application/json
 // @Product application/json
-// @Param data body dto.CoolerBoxInsertReq true "data"
+// @Param data body dto.CarBatchInsertReq true "data"
 // @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
 // @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
 // @Router /api/CoolerBox [post]
@@ -229,5 +232,5 @@ func (e CarController) BatchInsert(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
-	e.OK(nil, "创建成功")
+	e.OK(nil, "添加成功")
 }

+ 8 - 11
app/admin/controller/company.go

@@ -55,7 +55,6 @@ func (e CompanyController) GetPage(c *gin.Context) {
 // @Summary 添加用户-获取公司列表
 // @Description 添加用户-获取公司列表
 // @Tags 公司
-// @Param id path string true "公司id"
 // @Success 200 {object} response.Response{data=model.SysDept} "{"code": 200, "data": [...]}"
 // @Router /api/company/{id} [get]
 // @Security Bearer
@@ -150,7 +149,7 @@ func (e CompanyController) Insert(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
-	e.OK(req.GetId(), "创建成功")
+	e.OK(req.GetId(), "添加成功")
 }
 
 // Update 修改公司
@@ -160,8 +159,8 @@ func (e CompanyController) Insert(c *gin.Context) {
 // @Accept  application/json
 // @Product application/json
 // @Param data body dto.CompanyUpdateReq true "body"
-// @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
-// @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
+// @Success 200 {string} string	"{"code": 200, "message": "修改成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "修改失败"}"
 // @Router /api/company [put]
 // @Security Bearer
 func (e CompanyController) Update(c *gin.Context) {
@@ -184,7 +183,7 @@ func (e CompanyController) Update(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
-	e.OK(req.GetId(), "更新成功")
+	e.OK(req.GetId(), "修改成功")
 }
 
 // Delete 删除公司
@@ -228,7 +227,6 @@ func (e CompanyController) Delete(c *gin.Context) {
 // @Summary 通过id获取我的公司
 // @Description 通过id获取我的公司
 // @Tags 公司
-// @Param id path string true "公司id"
 // @Success 200 {object} response.Response{data=model.SysDept} "{"code": 200, "data": [...]}"
 // @Router /api/company/{id} [get]
 // @Security Bearer
@@ -257,16 +255,15 @@ func (e CompanyController) GetMyCompany(c *gin.Context) {
 	e.OK(object, "查询成功")
 }
 
-
 // UpdateMyCompany 修改我的公司
 // @Summary 修改我的公司
 // @Description 修改我的公司
 // @Tags 公司
 // @Accept  application/json
 // @Product application/json
-// @Param data body dto.CompanyUpdateReq true "body"
-// @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
-// @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
+// @Param data body dto.MyCompanyUpdateReq true "body"
+// @Success 200 {string} string	"{"code": 200, "message": "修改成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "修改失败"}"
 // @Router /api/company [put]
 // @Security Bearer
 func (e CompanyController) UpdateMyCompany(c *gin.Context) {
@@ -289,5 +286,5 @@ func (e CompanyController) UpdateMyCompany(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
-	e.OK(req.GetId(), "更新成功")
+	e.OK(req.GetId(), "修改成功")
 }

+ 8 - 6
app/admin/controller/cooler_box.go

@@ -21,6 +21,8 @@ type CoolerBoxController struct {
 // @Description 获取保温箱列表
 // @Tags 保温箱
 // @Param name query string false "保温箱名称"
+// @Param sn query string false "保温箱关联sn"
+// @Param status query string false "状态:1-停用 2-启用"
 // @Param pageSize query int false "页条数"
 // @Param page query int false "页码"
 // @Success 200 {object} response.Response{data=response.Page{list=[]model.CoolerBox}} "{"code": 200, "data": [...]}"
@@ -121,7 +123,7 @@ func (e CoolerBoxController) Insert(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
-	e.OK(req.GetId(), "创建成功")
+	e.OK(req.GetId(), "添加成功")
 }
 
 // Update 修改保温箱
@@ -131,8 +133,8 @@ func (e CoolerBoxController) Insert(c *gin.Context) {
 // @Accept  application/json
 // @Product application/json
 // @Param data body dto.CoolerBoxUpdateReq true "body"
-// @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
-// @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
+// @Success 200 {string} string	"{"code": 200, "message": "修改成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "修改失败"}"
 // @Router /api/CoolerBox [put]
 // @Security Bearer
 func (e CoolerBoxController) Update(c *gin.Context) {
@@ -156,7 +158,7 @@ func (e CoolerBoxController) Update(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
-	e.OK(req.GetId(), "更新成功")
+	e.OK(req.GetId(), "修改成功")
 }
 
 // Delete 删除保温箱
@@ -200,7 +202,7 @@ func (e CoolerBoxController) Delete(c *gin.Context) {
 // @Tags 保温箱
 // @Accept  application/json
 // @Product application/json
-// @Param data body dto.CoolerBoxInsertReq true "data"
+// @Param data body dto.CoolerBoxBatchInsertReq true "data"
 // @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
 // @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
 // @Router /api/CoolerBox [post]
@@ -227,5 +229,5 @@ func (e CoolerBoxController) BatchInsert(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
-	e.OK(nil, "创建成功")
+	e.OK(nil, "添加成功")
 }

+ 17 - 6
app/admin/controller/customer.go

@@ -30,7 +30,8 @@ type Customer struct {
 // @Summary 获取客户列表
 // @Description 获取客户列表
 // @Tags 客户
-// @Param username query string false "客户名"
+// @Param username query string false "登录用户名"
+// @Param name query string false "姓名"
 // @Param pageSize query int false "页条数"
 // @Param page query int false "页码"
 // @Success 200 {object} response.Response{data=response.Page{list=[]model.SysUser}}  "{"code": 200, "data": [...]}"
@@ -106,8 +107,10 @@ func (e Customer) Get(c *gin.Context) {
 // @Tags 客户
 // @Accept  application/json
 // @Product application/json
-// @Param data body dto.CustomerInsertReq true "客户数据"
+// @Param data body dto.CustomerInsertReq true "body"
 // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
+// @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
 // @Router /api/customer [post]
 // @Security Bearer
 func (e Customer) Insert(c *gin.Context) {
@@ -140,7 +143,7 @@ func (e Customer) Insert(c *gin.Context) {
 		return
 	}
 
-	e.OK(req.GetId(), "创建成功")
+	e.OK(req.GetId(), "添加成功")
 }
 
 // Update 修改客户数据
@@ -151,6 +154,8 @@ func (e Customer) Insert(c *gin.Context) {
 // @Product application/json
 // @Param data body dto.CustomerUpdateReq true "body"
 // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
+// @Success 200 {string} string	"{"code": 200, "message": "修改成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "修改失败"}"
 // @Router /api/customer [put]
 // @Security Bearer
 func (e Customer) Update(c *gin.Context) {
@@ -177,7 +182,7 @@ func (e Customer) Update(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
-	e.OK(req.GetId(), "更新成功")
+	e.OK(req.GetId(), "修改成功")
 }
 
 // Delete 通过id删除客户数据
@@ -186,6 +191,8 @@ func (e Customer) Update(c *gin.Context) {
 // @Tags 客户
 // @Param data body dto.CustomerDeleteReq true "body"
 // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
+// @Success 200 {string} string	"{"code": 200, "message": "删除成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "删除失败"}"
 // @Router /api/customer [delete]
 // @Security Bearer
 func (e Customer) Delete(c *gin.Context) {
@@ -203,7 +210,7 @@ func (e Customer) Delete(c *gin.Context) {
 	}
 	userId := user.GetUserId(c)
 	if userId == req.Id {
-		err := errors.New("禁止删除自己")
+		err = errors.New("禁止删除自己")
 		e.Error(500, err, err.Error())
 		return
 	}
@@ -229,6 +236,8 @@ func (e Customer) Delete(c *gin.Context) {
 // @Product application/json
 // @Param data body dto.ResetCustomerPwdReq true "body"
 // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
+// @Success 200 {string} string	"{"code": 200, "message": "修改成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "修改失败"}"
 // @Router /api/user/pwd/reset [put]
 // @Security Bearer
 func (e Customer) ResetPwd(c *gin.Context) {
@@ -257,7 +266,7 @@ func (e Customer) ResetPwd(c *gin.Context) {
 		return
 	}
 
-	e.OK(req.GetId(), "更新成功")
+	e.OK(req.GetId(), "修改成功")
 
 }
 
@@ -269,6 +278,8 @@ func (e Customer) ResetPwd(c *gin.Context) {
 // @Product application/json
 // @Param data body dto.CustomerPassWord true "body"
 // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
+// @Success 200 {string} string	"{"code": 200, "message": "密码修改成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "修改失败"}"
 // @Router /api/customer/pwd/set [put]
 // @Security Bearer
 func (e Customer) UpdatePwd(c *gin.Context) {

+ 14 - 23
app/admin/controller/device.go

@@ -20,7 +20,7 @@ type DeviceController struct {
 // @Summary 获取传感器列表
 // @Description 获取传感器列表
 // @Tags 设备
-// @Success 200 {object} response.Response{data=response.Page{list=[]model.Device}} "{"code": 200, "data": [...]}"
+// @Success 200 {object} response.Response{data=response.Page{list=[]nats_server.Device_R}} "{"code": 200, "data": [...]}"
 // @Router /api/device/sensor-list [get]
 // @Security Bearer
 func (e DeviceController) GetSensorList(c *gin.Context) {
@@ -43,15 +43,17 @@ func (e DeviceController) GetSensorList(c *gin.Context) {
 	e.PageOK(deviceSensorList, int(count), 0, 0, "查询成功")
 }
 
-// GetData 获取车辆温湿度信息
-// @Summary 获取车辆温湿度信息
-// @Description 获取车辆温湿度信息
+// GetData 获取温湿度信息
+// @Summary 获取温湿度信息
+// @Description 获取温湿度信息
 // @Tags 设备
-// @Param t_sn query string false "sn"
+// @Param t_sn query string false "设备sn"
 // @Param t_id query string false "传感器id"
+// @Param startTime query string false "开始时间"
+// @Param endTime query string false "结束时间"
 // @Param pageSize query int false "页条数"
 // @Param page query int false "页码"
-// @Success 200 {object} response.Response{data=response.Page{list=[]model.Device}} "{"code": 200, "data": [...]}"
+// @Success 200 {object} response.Response{data=response.Page{list=[]nats_server.Device_R}} "{"code": 200, "data": [...]}"
 // @Router /api/device/sensor-list [get]
 // @Security Bearer
 func (e DeviceController) GetData(c *gin.Context) {
@@ -77,14 +79,14 @@ func (e DeviceController) GetData(c *gin.Context) {
 }
 
 // GetDevicePage 获取未绑定的设备列表
-// @Summary 获取保温箱列表
-// @Description 获取保温箱列表
-// @Tags 保温箱
-// @Param name query string false "保温箱名称"
+// @Summary 获取未绑定的设备列表
+// @Description 获取未绑定的设备列表
+// @Tags 设备
+// @Param name query string false "设备名称"
 // @Param pageSize query int false "页条数"
 // @Param page query int false "页码"
-// @Success 200 {object} response.Response{data=response.Page{list=[]model.CoolerBox}} "{"code": 200, "data": [...]}"
-// @Router /api/CoolerBox [get]
+// @Success 200 {object} response.Response{data=response.Page{list=[]nats_server.Device_R}} "{"code": 200, "data": [...]}"
+// @Router /api/device [get]
 // @Security Bearer
 func (e DeviceController) GetDevicePage(c *gin.Context) {
 	coolerBoxSvc := service.CoolerBox{}
@@ -140,13 +142,6 @@ func (e DeviceController) GetDevicePage(c *gin.Context) {
 	for _, v := range carList {
 		bindMap[v.Sn] = struct{}{}
 	}
-	// Fixme 测试完成之后删除
-	//for i := 0; i < 20; i++ {
-	//	list = append(list, nats_server.Device_R{
-	//		T_devName: fmt.Sprintf("保温箱%03d", i),
-	//		T_sn:      fmt.Sprintf("2024114956064%03d", i),
-	//	})
-	//}
 
 	list2 := make([]nats_server.Device_R, 0)
 	for i := 0; i < len(list); i++ {
@@ -157,10 +152,6 @@ func (e DeviceController) GetDevicePage(c *gin.Context) {
 		list2 = append(list2, list[i])
 	}
 
-	//if len(list2) == 0 {
-	//	e.PageOK(list2, len(list2), req.GetPageIndex(), req.GetPageSize(), "查询成功")
-	//}
-
 	// 计算总页数
 	totalPages := (len(list2) + req.GetPageSize() - 1) / req.GetPageSize()
 

+ 12 - 17
app/admin/controller/sys_user.go

@@ -31,10 +31,8 @@ type SysUser struct {
 // @Description 获取系统用户列表
 // @Tags 用户
 // @Param username query string false "用户名"
-// @Param deptId query int false "部门id"
-// @Param roleId query string false "角色id"
-// @Param postId query string false "岗位id"
-// @Param status query string false "状态 1-停用 2-正常"
+// @Param name query string false "姓名"
+// @Param type query int false "类型:管理员1 仓管2 司机3"
 // @Param pageSize query int false "页条数"
 // @Param page query int false "页码"
 // @Success 200 {object} response.Response{data=response.Page{list=[]model.SysUser}}  "{"code": 200, "data": [...]}"
@@ -110,7 +108,7 @@ func (e SysUser) Get(c *gin.Context) {
 // @Tags 用户
 // @Accept  application/json
 // @Product application/json
-// @Param data body dto.SysUserInsertReq true "用户数据"
+// @Param data body dto.SysUserInsertReq true "body"
 // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
 // @Router /api/sys-user [post]
 // @Security Bearer
@@ -135,7 +133,7 @@ func (e SysUser) Insert(c *gin.Context) {
 		return
 	}
 
-	e.OK(req.GetId(), "创建成功")
+	e.OK(req.GetId(), "添加成功")
 }
 
 // Update 修改用户数据
@@ -172,7 +170,7 @@ func (e SysUser) Update(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
-	e.OK(req.GetId(), "更新成功")
+	e.OK(req.GetId(), "修改成功")
 }
 
 // Delete 通过id删除用户数据
@@ -198,7 +196,7 @@ func (e SysUser) Delete(c *gin.Context) {
 	}
 	userId := user.GetUserId(c)
 	if userId == req.Id {
-		err := errors.New("禁止删除自己")
+		err = errors.New("禁止删除自己")
 		e.Error(500, err, err.Error())
 		return
 	}
@@ -251,7 +249,7 @@ func (e SysUser) UpdateStatus(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
-	e.OK(req.GetId(), "更新成功")
+	e.OK(req.GetId(), "修改成功")
 }
 
 // ResetPwd 重置用户密码
@@ -290,7 +288,7 @@ func (e SysUser) ResetPwd(c *gin.Context) {
 		return
 	}
 
-	e.OK(req.GetId(), "更新成功")
+	e.OK(req.GetId(), "修改成功")
 
 }
 
@@ -337,7 +335,7 @@ func (e SysUser) UpdatePwd(c *gin.Context) {
 // @Summary 获取个人中心用户
 // @Description 获取个人中心用户
 // @Tags 个人中心
-// @Success 200 {object} response.Response{user=model.SysUser,role=model.SysRole}  "{"code": 200, "data": {"user":[...],"role":[...]}}"
+// @Success 200 {object} response.Response{user=model.SysUser}  "{"code": 200, "data": {"user":[...],"role":[...]}}"
 // @Router /api/user/profile [get]
 // @Security Bearer
 func (e SysUser) GetProfile(c *gin.Context) {
@@ -423,8 +421,7 @@ func (e SysUser) GetInfo(c *gin.Context) {
 // @Summary 获取短信验证码
 // @Description 获取短信验证码
 // @Tags 登录
-// @Accept  application/json
-// @Product application/json
+// @Param phone query string true "手机号"
 // @Success 200 {string} string "{"code": 200, "data": "18888888888"}"
 // @Router /verify-code [get]
 // @Security Bearer
@@ -468,10 +465,8 @@ func (e SysUser) VerifyCode(c *gin.Context) {
 // @Description 获取用户列表-仓库/车辆绑定
 // @Tags 用户
 // @Param username query string false "用户名"
-// @Param deptId query int false "部门id"
-// @Param roleId query string false "角色id"
-// @Param postId query string false "岗位id"
-// @Param status query string false "状态 1-停用 2-正常"
+// @Param name query string false "姓名"
+// @Param type query int false "类型:管理员1 仓管2 司机3"
 // @Param pageSize query int false "页条数"
 // @Param page query int false "页码"
 // @Success 200 {object} response.Response{data=response.Page{list=[]model.SysUser}}  "{"code": 200, "data": [...]}"

+ 1 - 1
app/admin/controller/upload.go

@@ -21,7 +21,7 @@ type UploadController struct {
 // @Summary 文件上传
 // @Description 文件上传
 // @Tags 工具
-// @Success 200 {object} response.Response{data=string,id=string,msg=string} "{"code": 200, "data": [...]}"
+// @Success 200 {object} response.Response{data=string} "{"code": 200, "data": [...]}"
 // @Router /api/upload [get]
 func (e UploadController) FilesUpload(c *gin.Context) {
 	err := e.MakeContext(c).Errors

+ 14 - 11
app/admin/controller/warehouse.go

@@ -21,6 +21,9 @@ type WarehouseController struct {
 // @Description 获取仓库列表
 // @Tags 仓库
 // @Param name query string false "仓库名称"
+// @Param sn query string false "仓库关联sn"
+// @Param status query string false "状态:1-停用 2-启用"
+// @Param isBind query bool false "是否绑定仓管"
 // @Param pageSize query int false "页条数"
 // @Param page query int false "页码"
 // @Success 200 {object} response.Response{data=response.Page{list=[]model.Warehouse}} "{"code": 200, "data": [...]}"
@@ -121,7 +124,7 @@ func (e WarehouseController) Insert(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
-	e.OK(req.GetId(), "创建成功")
+	e.OK(req.GetId(), "添加成功")
 }
 
 // Update 修改仓库
@@ -131,8 +134,8 @@ func (e WarehouseController) Insert(c *gin.Context) {
 // @Accept  application/json
 // @Product application/json
 // @Param data body dto.WarehouseUpdateReq true "body"
-// @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
-// @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
+// @Success 200 {string} string	"{"code": 200, "message": "修改成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "修改失败"}"
 // @Router /api/warehouse [put]
 // @Security Bearer
 func (e WarehouseController) Update(c *gin.Context) {
@@ -156,7 +159,7 @@ func (e WarehouseController) Update(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
-	e.OK(req.GetId(), "更新成功")
+	e.OK(req.GetId(), "修改成功")
 }
 
 // Delete 删除仓库
@@ -194,16 +197,16 @@ func (e WarehouseController) Delete(c *gin.Context) {
 	e.OK(req.GetId(), "删除成功")
 }
 
-// BatchInsert 批量添加保温箱
-// @Summary 批量添加保温箱
-// @Description 批量添加保温箱
-// @Tags 保温箱
+// BatchInsert 批量添加仓库
+// @Summary 批量添加仓库
+// @Description 批量添加仓库
+// @Tags 仓库
 // @Accept  application/json
 // @Product application/json
-// @Param data body dto.CoolerBoxInsertReq true "data"
+// @Param data body dto.WarehouseBatchInsertReq true "data"
 // @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
 // @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
-// @Router /api/CoolerBox [post]
+// @Router /api/warehouse/import [post]
 // @Security Bearer
 func (e WarehouseController) BatchInsert(c *gin.Context) {
 	s := service.Warehouse{}
@@ -227,5 +230,5 @@ func (e WarehouseController) BatchInsert(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
-	e.OK(nil, "创建成功")
+	e.OK(nil, "添加成功")
 }

Разлика између датотеке није приказан због своје велике величине
+ 496 - 1493
app/admin/controller/waybill.go


+ 7 - 6
app/admin/controller/waybill_logistics.go

@@ -14,15 +14,16 @@ type WaybillLogisticsController struct {
 	api.Api
 }
 
-// GetPage 获取运单列表
-// @Summary 获取运单列表
-// @Description 获取运单列表
-// @Tags 运单
-// @Param no query string false "运单号"
+// GetPage 获取运单物流信息列表
+// @Summary 获取运单物流信息列表
+// @Description 获取运单物流信息列表
+// @Tags 运单物流信息
+// @Param waybillNo query string false "运单号"
+// @Param status query int false "状态"
 // @Param pageSize query int false "页条数"
 // @Param page query int false "页码"
 // @Success 200 {object} response.Response{data=response.Page{list=[]model.WaybillLogistics}} "{"code": 200, "data": [...]}"
-// @Router /api/waybill [get]
+// @Router /api/waybill-logistics [get]
 // @Security Bearer
 func (e WaybillLogisticsController) GetPage(c *gin.Context) {
 	s := service.WaybillLogistics{}

+ 25 - 4
app/admin/controller/waybill_task.go

@@ -20,7 +20,7 @@ type WaybillTaskController struct {
 // @Summary 获取运单任务列表
 // @Description 获取运单任务列表
 // @Tags 运单任务
-// @Param no query string true "运单号"
+// @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
@@ -84,6 +84,17 @@ func (e WaybillTaskController) GetData(c *gin.Context) {
 	}
 	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{}
@@ -131,7 +142,7 @@ func (e WaybillTaskController) GetPrintData(c *gin.Context) {
 	}
 	list := make([]nats_server.DeviceData_R, 0)
 	var count int64
-	list, count, err = s.GetDataPage(&req)
+	list, count, err = s.GetPrintDataPage(&req)
 	if err != nil {
 		e.Error(500, err, err.Error())
 		return
@@ -145,9 +156,9 @@ func (e WaybillTaskController) GetPrintData(c *gin.Context) {
 // @Tags 运单任务
 // @Accept  application/json
 // @Product application/json
-// @Param data body dto.WaybillTaskGetDataPageReq true "body"
+// @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/data [post]
+// @Router /api/waybill-task/newest-locus [post]
 // @Security Bearer
 func (e WaybillTaskController) GetNewestData(c *gin.Context) {
 	s := service.WaybillTask{}
@@ -173,6 +184,16 @@ func (e WaybillTaskController) GetNewestData(c *gin.Context) {
 	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{}

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

@@ -20,7 +20,8 @@ type Car struct {
 
 type CarOmit struct {
 	Id     int         `json:"id,omitempty"`     // 主键编码
-	CarNo  string      `json:"carNo,omitempty"`  // 商品名称
+	CarNo  string      `json:"carNo,omitempty"`  // 车牌号
+	Sn     string      `json:"sn,omitempty"`     // sn
 	UserId int         `json:"userId,omitempty"` // 仓管id
 	User   SysUserOmit `json:"user,omitempty"`
 }

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

@@ -17,6 +17,7 @@ type CoolerBox struct {
 type CoolerBoxOmit struct {
 	Id   int    `json:"id,omitempty"`   // 主键编码
 	Name string `json:"name,omitempty"` // 保温箱名称
+	Sn   string `json:"sn,omitempty"`   // sn
 }
 
 func (CoolerBox) TableName() string {

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

@@ -22,6 +22,7 @@ type SysDept struct {
 	ColdKey        string `json:"coldKey"  gorm:"size:128;"`               // 冷链3.0key
 	PrintIntercept bool   `json:"printIntercept"`                          // 温湿度打印拦截 默认关闭
 	Logo           string `json:"logo"  gorm:"size:128;"`                  // 公司logo
+	Seal           string `json:"seal"  gorm:"size:128;"`                  // 公司公章
 	ColdPid        int    `json:"coldPid"  gorm:"size:128;"`               // 冷链3.0公司id
 	model2.ControlBy
 	model2.ModelTime

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

@@ -5,12 +5,12 @@ 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;"`                               // 地址
+	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
+	UserId    int               `json:"userId" gorm:"size:255;"`                              // 仓管id
+	HistorySn model2.StringList `json:"historySn"`                                            // 历史绑定的sn
 
 	User SysUserOmit `json:"user"`
 	model2.ControlBy
@@ -19,7 +19,8 @@ type Warehouse struct {
 }
 type WarehouseOmit struct {
 	Id     int         `json:"id,omitempty"`     // 主键编码
-	Name   string      `json:"name,omitempty"`   // 商品名称
+	Name   string      `json:"name,omitempty"`   // 名称
+	Sn     string      `json:"sn,omitempty"`     // sn
 	UserId int         `json:"userId,omitempty"` // 仓管id
 	User   SysUserOmit `json:"user,omitempty"`
 }

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

@@ -46,7 +46,7 @@ func GetCustomerWaybillStatus(status int) string {
 type Waybill struct {
 	model2.Model
 	WaybillNo string `json:"waybillNo"  gorm:"size:128"` //单号
-	Status    int    `json:"status"  gorm:"size:128"`    //运单状态:1待派单 2待装车 3待入库 4已装车 5已入库 6已下车 7已出库 8已签收
+	Status    int    `json:"status"  gorm:"size:128"`    //运单状态:1待派单 2待装车 3待入库 4已装车 5已入库 6已下车 7已出库 8已签收 9待装箱 10已装箱 11已出箱
 	//SenderAddressId         int         `json:"senderAddressId"  gorm:"size:128"`         //发货地址Id
 	SenderAddressDetails string `json:"senderAddressDetails"  gorm:"size:128"` //发货地址详情
 	SenderAddressName    string `json:"senderAddressName"  gorm:"size:128"`    //发货地址名称

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

@@ -29,6 +29,7 @@ func registerWaybillRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle
 		r.POST("/car-in", cont.CarIn) // 装车
 		//r.POST("/car-out", cont.CarOut)             // 下车
 		r.POST("/cooler-box-in", cont.CoolerBoxIn) // 装箱
+		r.POST("/stop-record", cont.StopRecord)    // 停止记录
 		r.POST("/receipt", cont.Receipt)           // 签收
 		r.GET("/customer", cont.GetCustomerPage)   // 客户下单列表
 		r.POST("/customer", cont.CustomerInsert)   // 客户下单
@@ -39,7 +40,7 @@ func registerWaybillRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle
 		r.GET("/export-template", cont.ExportTemplate) // 导出运单模板
 		r.GET("/home", cont.Home)                      // 首页统计
 		r.GET("/export", cont.Export)                  // 运单管理-导出
-		r.GET("/customer/export", cont.CustomerExport) // 客户下单
+		r.GET("/customer/export", cont.CustomerExport) // 运单管理-客户导出
 		r.GET("/temperature-pdf", cont.TemperaturePDF) // 导出温湿度pdf
 		r.GET("/waybill-pdf", cont.WaybillPDF)         // 导出运单pdf
 		r.POST("/send-mail", cont.SendMail)            // 发送温湿度邮件

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

@@ -9,7 +9,7 @@ import (
 type AddressGetPageReq struct {
 	dto.Pagination `search:"-"`
 	Name           string `form:"name" search:"-"`                                                   // 地址名称
-	AddressType    string `form:"addressType" search:"type:exact;column:address_type;table:address"` //地址类型:sender-发货人 consignee-收货人
+	AddressType    string `form:"addressType" search:"type:exact;column:address_type;table:address"` // 地址类型:sender-发货人 consignee-收货人
 	DataType       string `form:"dataType" search:"-"`                                               // 我的my 全部all
 	AddressOrder
 }

+ 3 - 1
app/admin/service/dto/company.go

@@ -79,7 +79,8 @@ func (s *CompanyUpdateReq) GetId() interface{} {
 
 type MyCompanyUpdateReq struct {
 	Id               int    `json:"id" comment:"编码"`                 // 编码
-	Logo             string `json:"logo" example:"https://xxxx.jpg"` //名称
+	Logo             string `json:"logo" example:"https://xxxx.jpg"` // logo
+	Seal             string `json:"seal" example:"https://xxxx.jpg"` // 公章
 	PrintIntercept   bool   `json:"printIntercept"`                  // 备注
 	common.ControlBy `swaggerignore:"true"`
 }
@@ -90,6 +91,7 @@ func (s *MyCompanyUpdateReq) Generate(model *model.SysDept) {
 		model.Id = s.Id
 	}
 	model.Logo = s.Logo
+	model.Seal = s.Seal
 	model.PrintIntercept = s.PrintIntercept
 }
 

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

@@ -10,7 +10,6 @@ type CustomerGetPageReq struct {
 	dto2.Pagination `search:"-"`
 	Username        string `form:"username" search:"type:contains;column:username;table:sys_user" comment:"用户名"`
 	Name            string `form:"name" search:"type:contains;column:nick_name;table:sys_user" comment:"昵称"`
-	Type            int    `form:"type" search:"type:exact;column:type;table:sys_user" comment:"状态"`
 	CustomerOrder
 }
 type CustomerOrder struct {

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

@@ -194,6 +194,10 @@ type WaybillReceiptReq struct {
 	WaybillNo  string      `json:"waybillNo"  gorm:"size:128"`  // 运单编号
 	ReceiptImg string      `json:"receiptImg"  gorm:"size:128"` // 签收图片
 }
+type WaybillStopRecordReq struct {
+	StartTime model2.Time `json:"startTime"`
+	WaybillNo string      `json:"waybillNo"  gorm:"size:128"` // 运单编号
+}
 
 type WaybillGetAppletPageReq struct {
 	dto.Pagination `search:"-"`

+ 284 - 22
app/admin/service/waybill.go

@@ -1540,7 +1540,7 @@ func (e *Waybill) Receipt(c *dto.WaybillReceiptReq, p *actions.DataPermission) e
 	}
 
 	// 保温箱配送 不需要中转
-	if waybillModel.CoolerBoxId > 0 && waybillModel.Status == model.WaybillStatusVanning {
+	if waybillModel.Status == model.WaybillStatusVanning || waybillModel.Status == model.WaybillStatusVanningOut {
 		// 查询保温箱信息
 		var coolerBox = model.CoolerBox{}
 		// 查询保温箱是否存在
@@ -1638,7 +1638,7 @@ func (e *Waybill) Receipt(c *dto.WaybillReceiptReq, p *actions.DataPermission) e
 		return nil
 	}
 
-	if waybillModel.Status == model.WaybillStatusTruck {
+	if waybillModel.Status == model.WaybillStatusTruck || waybillModel.Status == model.WaybillStatusTruckOut {
 		// 查询车辆信息
 		var car = model.Car{}
 		// 查询运单是否存在
@@ -1733,7 +1733,8 @@ func (e *Waybill) Receipt(c *dto.WaybillReceiptReq, p *actions.DataPermission) e
 			return errors.New(fmt.Sprintf("保存运单物流信息失败:%s", err))
 		}
 	}
-	if waybillModel.Status == model.WaybillStatusStorage {
+
+	if waybillModel.Status == model.WaybillStatusStorage || waybillModel.Status == model.WaybillStatusStorageOut {
 		// 查询车辆信息
 		var warehouse model.Warehouse
 		// 查询运单是否存在
@@ -1832,6 +1833,259 @@ func (e *Waybill) Receipt(c *dto.WaybillReceiptReq, p *actions.DataPermission) e
 	return nil
 }
 
+// 停止记录
+func (e *Waybill) StopRecord(c *dto.WaybillStopRecordReq, p *actions.DataPermission) error {
+	var err error
+
+	tx := e.Orm.Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+		} else {
+			tx.Commit()
+		}
+	}()
+
+	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.WaybillStatusTruckOut ||
+		waybillModel.Status == model.WaybillStatusStorageOut ||
+		waybillModel.Status == model.WaybillStatusVanningOut {
+		return nil
+	}
+
+	if waybillModel.Status == model.WaybillStatusWaitDelivery ||
+		waybillModel.Status == model.WaybillStatusWaitTruck ||
+		waybillModel.Status == model.WaybillStatusWaitStorage ||
+		waybillModel.Status == model.WaybillStatusWaitVanning {
+		err = errors.New(fmt.Sprintf("运单号%s状态为%s,无法停止记录!", c.WaybillNo, model.WaybillStatusMap[waybillModel.Status]))
+		return err
+	}
+
+	// 保温箱配送 不需要中转
+	if waybillModel.Status == model.WaybillStatusVanning {
+		// 查询保温箱信息
+		var coolerBox = model.CoolerBox{}
+		// 查询保温箱是否存在
+		err = tx.Scopes(actions.Permission(coolerBox.TableName(), p)).
+			Where("id = ?", waybillModel.CoolerBoxId).
+			First(&coolerBox).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return errors.New("获取保温箱信息失败")
+		}
+
+		waybillModel.Status = model.WaybillStatusVanningOut
+		err = tx.Save(&waybillModel).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return errors.New(fmt.Sprintf("保存运单信息失败:%s", err))
+		}
+
+		var lng, lat string
+		lng, lat, err = e.GetSite(p.DeptId, coolerBox.Sn, c.StartTime.String())
+		if err != nil {
+			e.Log.Errorf("获取定位信息失败: %s", err)
+			return err
+		}
+
+		// 查询任务
+		var task model.WaybillTask
+		err = tx.Model(&task).Where("waybill_no = ? and cooler_box_id = ?", c.WaybillNo, coolerBox.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 = c.StartTime
+			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:   c.WaybillNo,
+				Status:      model.WaybillStatusVanningOut,
+				CoolerBoxId: coolerBox.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
+	}
+
+	if waybillModel.Status == model.WaybillStatusTruck {
+		// 查询车辆信息
+		var car = model.Car{}
+		// 查询运单是否存在
+		err = tx.Scopes(actions.Permission(car.TableName(), p)).
+			Where("user_id = ?", p.UserId).
+			First(&car).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return errors.New("获取车辆信息失败")
+		}
+
+		waybillModel.Status = model.WaybillStatusTruckOut
+		err = tx.Save(&waybillModel).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return errors.New(fmt.Sprintf("保存运单信息失败:%s", err))
+		}
+
+		var lng, lat string
+		lng, lat, err = e.GetSite(p.DeptId, car.Sn, c.StartTime.String())
+		if err != nil {
+			e.Log.Errorf("获取定位信息失败: %s", err)
+			return err
+		}
+
+		// 查询任务
+		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 = c.StartTime
+			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: c.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))
+			}
+		}
+
+	}
+	if waybillModel.Status == model.WaybillStatusStorage {
+		// 查询车辆信息
+		var warehouse model.Warehouse
+		// 查询运单是否存在
+		err = tx.Scopes(actions.Permission(warehouse.TableName(), p)).
+			Where("user_id = ?", p.UserId).
+			First(&warehouse).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return errors.New("获取仓库信息失败")
+		}
+
+		waybillModel.Status = model.WaybillStatusStorageOut
+		err = tx.Save(&waybillModel).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return errors.New(fmt.Sprintf("保存运单信息失败:%s", err))
+		}
+
+		var lng, lat string
+		lng, lat, err = e.GetSite(p.DeptId, warehouse.Sn, c.StartTime.String())
+		if err != nil {
+			e.Log.Errorf("获取定位信息失败: %s", err)
+			return err
+		}
+
+		// 查询任务
+		var task model.WaybillTask
+		err = tx.Model(&task).Where("waybill_no = ? and warehouse_id = ?", c.WaybillNo, warehouse.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 = c.StartTime
+			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:   c.WaybillNo,
+				Status:      model.WaybillStatusTruckOut,
+				WarehouseId: warehouse.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
+}
+
 // 获取入库 出库 上车 下车 定位信息
 func (e *Waybill) GetSite(companyId int, sn string, time string) (lng, lat string, err error) {
 	// 获取公司秘钥
@@ -2117,7 +2371,7 @@ func (e *Waybill) GetTwoDeviceSensorData(c *dto.WaybillGetByWaybillNoReq) ([]nat
 
 	err = e.Orm.Model(&data).
 		Where("waybill_no = ?", c.WaybillNo).
-		Order("id desc").
+		//Order("id desc").
 		Preload("Warehouse").Preload("Car").Preload("CoolerBox").
 		Find(&taskList).Error
 	if err != nil {
@@ -2168,29 +2422,27 @@ func (e *Waybill) GetTwoDeviceSensorData(c *dto.WaybillGetByWaybillNoReq) ([]nat
 				for j := 0; j < len(list); j++ {
 					if v.T_id == list[j].T_id {
 						if list[j].T_time != taskList[i].StartTime.String() {
-							if i < len(taskList)-2 && list[j].T_time != taskList[i+1].EndTime.String() {
-								firstData := list[len(list)-1-j]
-								firstData.T_time = taskList[i].StartTime.String()
-								firstMap[v.T_id] = firstData
-								count += 1
-							}
+							firstData := list[len(list)-1-j]
+							firstData.T_time = taskList[i].StartTime.String()
+							firstMap[v.T_id] = firstData
+							count += 1
 						}
 						break
 					}
 				}
-				if waybill.Status == model.WaybillStatusReceipt {
-					for k := len(list) - 1; k >= 0; k-- {
-						if v.T_id == list[k].T_id {
-							if taskList[i].Id == lastWaybillTask.Id && list[k].T_time != taskList[i].EndTime.String() && !time.Time(taskList[i].EndTime).IsZero() {
-								lastData := list[len(list)-1-k]
-								lastData.T_time = taskList[i].EndTime.String()
-								lastMap[v.T_id] = lastData
-								count += 1
-							}
-							break
+
+				for k := len(list) - 1; k >= 0; k-- {
+					if v.T_id == list[k].T_id {
+						if list[k].T_time != taskList[i].EndTime.String() && !time.Time(taskList[i].EndTime).IsZero() {
+							lastData := list[len(list)-1-k]
+							lastData.T_time = taskList[i].EndTime.String()
+							lastMap[v.T_id] = lastData
+							count += 1
 						}
+						break
 					}
 				}
+
 			}
 		}
 		for _, v := range firstMap {
@@ -2202,17 +2454,21 @@ func (e *Waybill) GetTwoDeviceSensorData(c *dto.WaybillGetByWaybillNoReq) ([]nat
 		}
 
 		name := ""
+		sn := ""
 		if taskList[i].WarehouseId > 0 {
 			name = taskList[i].Warehouse.Name
+			sn = taskList[i].Warehouse.Sn
 		}
 		if taskList[i].CarId > 0 {
 			name = taskList[i].Car.CarNo
+			sn = taskList[i].Car.Sn
 		}
 		if taskList[i].CoolerBoxId > 0 {
 			name = taskList[i].CoolerBox.Name
+			sn = taskList[i].CoolerBox.Sn
 		}
 
-		deviceDataPdfList := DeviceSensorDataListToDeviceDataPdfList(name, list, t_id_list[0], t_id_list[1])
+		deviceDataPdfList := DeviceSensorDataListToDeviceDataPdfList(name, sn, list, t_id_list[0], t_id_list[1])
 		deviceDataPdf = append(deviceDataPdf, deviceDataPdfList...)
 		dataList = append(dataList, list...)
 		waybillPDF = append(waybillPDF, WaybillPDF{
@@ -2232,6 +2488,10 @@ func (e *Waybill) GetTwoDeviceSensorData(c *dto.WaybillGetByWaybillNoReq) ([]nat
 	})
 
 	sort.Slice(deviceDataPdf, func(i, j int) bool {
+		if deviceDataPdf[i].T_time == deviceDataPdf[j].T_time {
+			// 如果时间相同,则按预设顺序排序
+			return orderMap[dataList[i].T_sn] < orderMap[dataList[j].T_sn]
+		}
 		return deviceDataPdf[i].T_time < deviceDataPdf[j].T_time
 	})
 
@@ -2246,13 +2506,14 @@ type WaybillPDF struct {
 }
 
 type DeviceDataPdf struct {
+	T_sn   string   // 设备名称
 	T_name string   // 设备名称
 	T_time string   // 时间
 	T_id1  *float32 // 传感器id1温度
 	T_id2  *float32 // 传感器id2温度
 }
 
-func DeviceSensorDataListToDeviceDataPdfList(T_name string, list []nats_server.DeviceData_R, T_id1 int, T_id2 int) []DeviceDataPdf {
+func DeviceSensorDataListToDeviceDataPdfList(T_name, T_sn string, list []nats_server.DeviceData_R, T_id1 int, T_id2 int) []DeviceDataPdf {
 	// 创建一个 map 用于存储 DeviceData_Pdf 结果
 	resultMap := make(map[string]DeviceDataPdf)
 
@@ -2263,6 +2524,7 @@ func DeviceSensorDataListToDeviceDataPdfList(T_name string, list []nats_server.D
 		if _, ok := resultMap[key]; !ok {
 			pdf.T_time = item.T_time
 			pdf.T_name = T_name
+			pdf.T_sn = T_sn
 			resultMap[key] = pdf
 		}
 		data := resultMap[key]

+ 154 - 12
app/admin/service/waybill_task.go

@@ -154,22 +154,164 @@ func (e *WaybillTask) GetDataPage(c *dto.WaybillTaskGetDataPageReq) (list []nats
 					break
 				}
 			}
-			if waybill.Status == model.WaybillStatusReceipt {
-				for i := len(list) - 1; i >= 0; i-- {
-					if beforeEndTime {
-						break
+
+			for i := len(list) - 1; i >= 0; i-- {
+				if beforeEndTime {
+					break
+				}
+				if v == list[i].T_id {
+					if list[i].T_time != task.EndTime.String() && !task.EndTime.Local().IsZero() {
+						data := list[len(list)-1-i]
+						data.T_time = task.EndTime.String()
+						lastMap[v] = data
+						count += 1
 					}
-					if v == list[i].T_id {
-						if c.TaskId == lastWaybillTask.Id && list[i].T_time != task.EndTime.String() && !task.EndTime.Local().IsZero() {
-							data := list[len(list)-1-i]
-							data.T_time = task.EndTime.String()
-							lastMap[v] = data
-							count += 1
-						}
-						break
+					break
+				}
+			}
+
+		}
+	}
+
+	for _, data := range firstMap {
+		list = append(list, data)
+	}
+
+	for _, data := range lastMap {
+		list = append(list, data)
+	}
+
+	sort.Slice(list, func(i, j int) bool {
+		// 先按 T_time 字段排序,如果 T_time 相同则按 T_name 字段排序
+		if list[i].T_time == list[j].T_time {
+			return list[i].T_name < list[j].T_name
+		}
+		return list[i].T_time > list[j].T_time
+	})
+
+	// 计算总页数
+	totalPages := (int(count) + c.PageSize - 1) / c.PageSize
+
+	// 如果n超出范围,返回错误
+	if c.Page > totalPages {
+		return []nats_server.DeviceData_R{}, count, err
+	}
+	if c.Page < 1 {
+		c.Page = 1
+	}
+	// 计算当前页的数据
+	start := (c.Page - 1) * c.PageSize
+	end := start + c.PageSize
+	if end > int(count) {
+		end = int(count)
+	}
+	currentPage := list[start:end]
+
+	return currentPage, count, err
+}
+func (e *WaybillTask) GetPrintDataPage(c *dto.WaybillTaskGetDataPageReq) (list []nats_server.DeviceData_R, count int64, err error) {
+
+	var waybill model.Waybill
+	err = e.Orm.Where("waybill_no = ?", c.WaybillNo).First(&waybill).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		err = errors.New("获取运单信息错误!")
+		return
+	}
+
+	var task model.WaybillTask
+	err = e.Orm.Where("id = ? and waybill_no = ?", c.TaskId, c.WaybillNo).First(&task).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		err = errors.New("获取运单信息错误!")
+		return
+	}
+
+	// 获取最后一个任务id
+	var lastWaybillTask model.WaybillTask
+	err = e.Orm.Model(&lastWaybillTask).Where("waybill_no = ?", c.WaybillNo).Last(&lastWaybillTask).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		err = errors.New("获取运单信息错误!")
+		return
+	}
+	var afterStartTime bool
+	var beforeEndTime bool
+	if len(c.StartTime) > 0 {
+		var st time.Time
+		st, err = time.ParseInLocation("2006-01-02 15:04:05", c.StartTime, time.Local)
+		if err != nil {
+			err = errors.New("解析时间字符串出错!")
+			return
+		}
+		fmt.Println("st", st)
+		fmt.Println("task.StartTime", task.StartTime.Local())
+		if task.StartTime.Local().After(st) || st.Truncate(time.Second).Equal(task.StartTime.Local().Truncate(time.Second)) {
+			c.StartTime = task.StartTime.String()
+		} else {
+			afterStartTime = true
+		}
+	} else {
+		c.StartTime = task.StartTime.String()
+	}
+	if len(c.EndTime) > 0 {
+		var et time.Time
+		et, err = time.ParseInLocation("2006-01-02 15:04:05", c.EndTime, time.Local)
+		if err != nil {
+			err = errors.New("解析时间字符串出错!")
+			return
+		}
+		fmt.Println("et", et)
+		fmt.Println("task.EndTime", task.EndTime.Local())
+		if et.After(task.EndTime.Local()) || et.Truncate(time.Second).Equal(task.EndTime.Local().Truncate(time.Second)) {
+			c.EndTime = task.EndTime.String()
+		} else {
+			beforeEndTime = true
+		}
+	} else {
+		c.EndTime = task.EndTime.String()
+	}
+
+	T_snid := ""
+	for _, id := range c.T_ids {
+		T_snid += fmt.Sprintf("%s,%d|", task.Sn, id)
+	}
+	list, count, err = nats_server.Cold_ReadDeviceDataListBy_T_snid(T_snid, c.StartTime, c.EndTime, 0, 9999)
+	firstMap := map[int]nats_server.DeviceData_R{}
+	lastMap := map[int]nats_server.DeviceData_R{}
+	if count > 0 {
+		for _, v := range c.T_ids {
+
+			for i := 0; i < len(list); i++ {
+				if afterStartTime {
+					break
+				}
+				if v == list[i].T_id {
+					if list[i].T_time != task.StartTime.String() {
+						data := list[len(list)-1-i]
+						data.T_time = task.StartTime.String()
+						firstMap[v] = data
+						count += 1
 					}
+					break
 				}
 			}
+
+			for i := len(list) - 1; i >= 0; i-- {
+				if beforeEndTime {
+					break
+				}
+				if v == list[i].T_id {
+					if list[i].T_time != task.EndTime.String() && !task.EndTime.Local().IsZero() {
+						data := list[len(list)-1-i]
+						data.T_time = task.EndTime.String()
+						lastMap[v] = data
+						count += 1
+					}
+					break
+				}
+			}
+
 		}
 	}
 

+ 1 - 1
common/actions/create.go

@@ -43,7 +43,7 @@ func CreateAction(control dto.Control) gin.HandlerFunc {
 			response.Error(c, 500, err, "创建失败")
 			return
 		}
-		response.OK(c, object.GetId(), "创建成功")
+		response.OK(c, object.GetId(), "添加成功")
 		c.Next()
 	}
 }

+ 1 - 1
common/actions/update.go

@@ -53,7 +53,7 @@ func UpdateAction(control dto.Control) gin.HandlerFunc {
 			response.Error(c, http.StatusForbidden, nil, "无权更新该数据")
 			return
 		}
-		response.OK(c, object.GetId(), "更新成功")
+		response.OK(c, object.GetId(), "修改成功")
 		c.Next()
 	}
 }

Неке датотеке нису приказане због велике количине промена