|
|
@@ -68,6 +68,149 @@ func (c *StockController) Device_List() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+func (c *StockController) Device_Excel() {
|
|
|
+
|
|
|
+ T_state, _ := c.GetInt("T_state")
|
|
|
+ T_name := c.GetString("T_name")
|
|
|
+ T_product_name := c.GetString("T_product_name") // 产品名称
|
|
|
+ T_product_model := c.GetString("T_product_model") // 产品型号
|
|
|
+
|
|
|
+ DeviceDao := Stock.NewDevice(orm.NewOrm())
|
|
|
+ R_List, _ := DeviceDao.Read_Device_List(T_name, T_product_name, T_product_model, T_state, 0, 9999)
|
|
|
+
|
|
|
+ // 生成Excel文件名
|
|
|
+ filename := fmt.Sprintf("设备列表(%s)", lib.GetRandstring(6, "0123456789", 0))
|
|
|
+
|
|
|
+ // 创建Excel文件
|
|
|
+ f := excelize.NewFile()
|
|
|
+
|
|
|
+ // 设置样式
|
|
|
+ Style1, _ := f.NewStyle(
|
|
|
+ &excelize.Style{
|
|
|
+ Font: &excelize.Font{Bold: true, Size: 14, Family: "宋体"},
|
|
|
+ Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
|
|
|
+ })
|
|
|
+
|
|
|
+ Style2, _ := f.NewStyle(
|
|
|
+ &excelize.Style{
|
|
|
+ Font: &excelize.Font{Bold: true, Size: 10, Family: "宋体"},
|
|
|
+ Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
|
|
|
+ Border: []excelize.Border{
|
|
|
+ {Type: "left", Color: "000000", Style: 1},
|
|
|
+ {Type: "top", Color: "000000", Style: 1},
|
|
|
+ {Type: "bottom", Color: "000000", Style: 1},
|
|
|
+ {Type: "right", Color: "000000", Style: 1},
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ Style3, _ := f.NewStyle(
|
|
|
+ &excelize.Style{
|
|
|
+ Font: &excelize.Font{Size: 10, Family: "宋体"},
|
|
|
+ Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
|
|
|
+ Border: []excelize.Border{
|
|
|
+ {Type: "left", Color: "000000", Style: 1},
|
|
|
+ {Type: "top", Color: "000000", Style: 1},
|
|
|
+ {Type: "bottom", Color: "000000", Style: 1},
|
|
|
+ {Type: "right", Color: "000000", Style: 1},
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ // 设置工作表名称
|
|
|
+ f.SetSheetName("Sheet1", "设备列表")
|
|
|
+
|
|
|
+ // 设置标题
|
|
|
+ f.MergeCell("设备列表", "A1", "M1")
|
|
|
+ f.SetRowStyle("设备列表", 1, 1, Style1)
|
|
|
+ f.SetCellValue("设备列表", "A1", "宝智达科技设备列表")
|
|
|
+ f.SetRowHeight("设备列表", 1, 30)
|
|
|
+
|
|
|
+ // 设置表头
|
|
|
+ f.SetCellStyle("设备列表", "A2", "M2", Style2)
|
|
|
+ f.SetRowHeight("设备列表", 2, 20)
|
|
|
+
|
|
|
+ // 设置表头内容
|
|
|
+ f.SetCellValue("设备列表", "A2", "序号")
|
|
|
+ f.SetCellValue("设备列表", "B2", "合同编号")
|
|
|
+ f.SetCellValue("设备列表", "C2", "出库单号")
|
|
|
+ f.SetCellValue("设备列表", "D2", "关联项目")
|
|
|
+ f.SetCellValue("设备列表", "E2", "产品名称")
|
|
|
+ f.SetCellValue("设备列表", "F2", "产品分类")
|
|
|
+ f.SetCellValue("设备列表", "G2", "产品型号")
|
|
|
+ f.SetCellValue("设备列表", "H2", "产品规格")
|
|
|
+ f.SetCellValue("设备列表", "I2", "设备SN")
|
|
|
+ f.SetCellValue("设备列表", "J2", "模组imei")
|
|
|
+ f.SetCellValue("设备列表", "K2", "物联网卡号")
|
|
|
+ f.SetCellValue("设备列表", "L2", "设备编号")
|
|
|
+ f.SetCellValue("设备列表", "M2", "状态")
|
|
|
+
|
|
|
+ // 设置列宽
|
|
|
+ f.SetColWidth("设备列表", "A", "A", 8) // 序号
|
|
|
+ f.SetColWidth("设备列表", "B", "B", 15) // 合同编号
|
|
|
+ f.SetColWidth("设备列表", "C", "C", 15) // 出库单号
|
|
|
+ f.SetColWidth("设备列表", "D", "D", 20) // 关联项目
|
|
|
+ f.SetColWidth("设备列表", "E", "E", 20) // 产品名称
|
|
|
+ f.SetColWidth("设备列表", "F", "F", 15) // 产品分类
|
|
|
+ f.SetColWidth("设备列表", "G", "G", 15) // 产品型号
|
|
|
+ f.SetColWidth("设备列表", "H", "H", 15) // 产品规格
|
|
|
+ f.SetColWidth("设备列表", "I", "I", 20) // 设备SN
|
|
|
+ f.SetColWidth("设备列表", "J", "J", 15) // 模组imei
|
|
|
+ f.SetColWidth("设备列表", "K", "K", 20) // 物联网卡号
|
|
|
+ f.SetColWidth("设备列表", "L", "L", 18) // 设备编号
|
|
|
+ f.SetColWidth("设备列表", "M", "M", 10) // 状态
|
|
|
+
|
|
|
+ // 填充数据
|
|
|
+ for i, device := range R_List {
|
|
|
+ row := i + 3 // 从第3行开始填充数据
|
|
|
+
|
|
|
+ // 状态转换
|
|
|
+ stateText := "未出库"
|
|
|
+ if device.T_State == 1 {
|
|
|
+ stateText = "已出库"
|
|
|
+ }
|
|
|
+
|
|
|
+ f.SetCellStyle("设备列表", fmt.Sprintf("A%d", row), fmt.Sprintf("M%d", row), Style3)
|
|
|
+ //f.SetRowHeight("设备列表", row, 20)
|
|
|
+
|
|
|
+ f.SetCellValue("设备列表", fmt.Sprintf("A%d", row), i+1) // 序号
|
|
|
+ f.SetCellValue("设备列表", fmt.Sprintf("B%d", row), device.T_contract_number) // 合同编号
|
|
|
+ f.SetCellValue("设备列表", fmt.Sprintf("C%d", row), device.T_out_number) // 出库单号
|
|
|
+ f.SetCellValue("设备列表", fmt.Sprintf("D%d", row), device.T_project) // 关联项目
|
|
|
+ f.SetCellValue("设备列表", fmt.Sprintf("E%d", row), device.T_product_name) // 产品名称
|
|
|
+ f.SetCellValue("设备列表", fmt.Sprintf("F%d", row), device.T_product_class_name) // 产品分类
|
|
|
+ f.SetCellValue("设备列表", fmt.Sprintf("G%d", row), device.T_product_model) // 产品型号
|
|
|
+ f.SetCellValue("设备列表", fmt.Sprintf("H%d", row), device.T_product_spec) // 产品规格
|
|
|
+ f.SetCellValue("设备列表", fmt.Sprintf("I%d", row), device.T_sn) // 设备SN
|
|
|
+ f.SetCellValue("设备列表", fmt.Sprintf("J%d", row), device.T_imei) // 模组imei
|
|
|
+ f.SetCellValue("设备列表", fmt.Sprintf("K%d", row), device.T_iccid) // 物联网卡号
|
|
|
+ f.SetCellValue("设备列表", fmt.Sprintf("L%d", row), device.T_device_number) // 设备编号
|
|
|
+ f.SetCellValue("设备列表", fmt.Sprintf("M%d", row), stateText) // 状态
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存文件
|
|
|
+ if err := f.SaveAs("ofile/" + filename + ".xlsx"); err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ }
|
|
|
+ var url string
|
|
|
+ //// 上传 OSS
|
|
|
+ nats := natslibs.NewNats(Nats.Nats, conf.NatsSubj_Prefix)
|
|
|
+ url, is := nats.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+filename+".xlsx", "ofile/"+filename+".xlsx")
|
|
|
+ if !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "oss!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //删除目录
|
|
|
+ err := os.Remove("ofile/" + filename + ".xlsx")
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ }
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
func (c *StockController) Device_Check() {
|
|
|
|
|
|
T_sn := c.GetString("T_sn")
|
|
|
@@ -120,6 +263,162 @@ func (c *StockController) Device_Check() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+func (c *StockController) Device_Take_Stock() {
|
|
|
+
|
|
|
+ T_product_name := c.GetString("T_product_name") // 产品名称
|
|
|
+ T_product_model := c.GetString("T_product_model") // 产品型号
|
|
|
+ T_sn_list := c.GetString("T_sn_list") // sn列表
|
|
|
+ DeviceDao := Stock.NewDevice(orm.NewOrm())
|
|
|
+
|
|
|
+ // 获取库存中的所有设备(如果有产品名称和型号过滤)
|
|
|
+ R_List, _ := DeviceDao.Read_Device_List("", T_product_name, T_product_model, 0, 0, 9999)
|
|
|
+
|
|
|
+ // 创建设备SN到设备信息的映射,用于快速查找
|
|
|
+ deviceMap := make(map[string]Stock.Device_R)
|
|
|
+ // 保存在库设备列表
|
|
|
+ var inStockDevices []Stock.Device_R
|
|
|
+
|
|
|
+ for _, device := range R_List {
|
|
|
+ deviceMap[device.T_sn] = device
|
|
|
+ // 收集所有在库设备(状态为2)
|
|
|
+ if device.T_State == 2 {
|
|
|
+ inStockDevices = append(inStockDevices, device)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建结果数据结构
|
|
|
+ type DeviceCheckResult struct {
|
|
|
+ T_sn string `json:"t_sn"` // 设备SN
|
|
|
+ T_exists bool `json:"t_exists"` // 是否存在于库存
|
|
|
+ T_state int `json:"t_state"` // 设备状态:1-已出库 2-未出库/入库
|
|
|
+ T_state_desc string `json:"t_state_desc"` // 状态描述
|
|
|
+ T_product_id int `json:"t_product_id"` // 产品ID
|
|
|
+ T_product_name string `json:"t_product_name"` // 产品名称
|
|
|
+ T_product_model string `json:"t_product_model"` // 产品型号
|
|
|
+ T_iccid string `json:"t_iccid"` // SIM卡号
|
|
|
+ T_imei string `json:"t_imei"` // 模组IMEI
|
|
|
+ T_in_number string `json:"t_in_number"` // 入库编号
|
|
|
+ T_out_number string `json:"t_out_number"` // 出库编号
|
|
|
+ T_from_input bool `json:"t_from_input"` // 是否来自输入列表
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理每个输入的SN
|
|
|
+ var results []DeviceCheckResult
|
|
|
+ var processedSNs = make(map[string]bool) // 用于跟踪已处理的SN
|
|
|
+
|
|
|
+ // 解析输入的SN列表(如果有)
|
|
|
+ var snList []string
|
|
|
+ if len(T_sn_list) > 0 {
|
|
|
+ snList = lib.SplitString(T_sn_list, ",")
|
|
|
+
|
|
|
+ for _, sn := range snList {
|
|
|
+ sn = strings.TrimSpace(sn)
|
|
|
+ if len(sn) == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ result := DeviceCheckResult{
|
|
|
+ T_sn: sn,
|
|
|
+ T_exists: false,
|
|
|
+ T_from_input: true, // 标记为来自输入列表
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查设备是否存在于库存
|
|
|
+ if device, exists := deviceMap[sn]; exists {
|
|
|
+ result.T_exists = true
|
|
|
+ result.T_state = device.T_State
|
|
|
+ result.T_product_id = device.T_product_id
|
|
|
+ result.T_product_name = device.T_product_name
|
|
|
+ result.T_product_model = device.T_product_model
|
|
|
+ result.T_iccid = device.T_iccid
|
|
|
+ result.T_imei = device.T_imei
|
|
|
+ result.T_in_number = device.T_in_number
|
|
|
+ result.T_out_number = device.T_out_number
|
|
|
+
|
|
|
+ // 设置状态描述
|
|
|
+ if device.T_State == 1 {
|
|
|
+ result.T_state_desc = "已出库"
|
|
|
+ } else if device.T_State == 2 {
|
|
|
+ result.T_state_desc = "在库"
|
|
|
+ } else {
|
|
|
+ result.T_state_desc = "未知状态"
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 设备不存在于库存
|
|
|
+ result.T_state_desc = "未入库"
|
|
|
+ }
|
|
|
+
|
|
|
+ results = append(results, result)
|
|
|
+ processedSNs[sn] = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加所有在库设备(如果还没有处理过)
|
|
|
+ for _, device := range inStockDevices {
|
|
|
+ // 如果这个SN已经处理过(来自输入列表),则跳过
|
|
|
+ if _, processed := processedSNs[device.T_sn]; processed {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ result := DeviceCheckResult{
|
|
|
+ T_sn: device.T_sn,
|
|
|
+ T_exists: true,
|
|
|
+ T_state: device.T_State,
|
|
|
+ T_state_desc: "在库",
|
|
|
+ T_product_id: device.T_product_id,
|
|
|
+ T_product_name: device.T_product_name,
|
|
|
+ T_product_model: device.T_product_model,
|
|
|
+ T_iccid: device.T_iccid,
|
|
|
+ T_imei: device.T_imei,
|
|
|
+ T_in_number: device.T_in_number,
|
|
|
+ T_out_number: device.T_out_number,
|
|
|
+ T_from_input: false, // 标记为不是来自输入列表
|
|
|
+ }
|
|
|
+
|
|
|
+ results = append(results, result)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 统计结果
|
|
|
+ totalInputCount := 0
|
|
|
+ existsCount := 0
|
|
|
+ inStockCount := 0
|
|
|
+ outStockCount := 0
|
|
|
+ notExistsCount := 0
|
|
|
+
|
|
|
+ for _, result := range results {
|
|
|
+ if result.T_from_input {
|
|
|
+ totalInputCount++
|
|
|
+ if result.T_exists {
|
|
|
+ existsCount++
|
|
|
+ if result.T_state == 2 {
|
|
|
+ inStockCount++
|
|
|
+ } else if result.T_state == 1 {
|
|
|
+ outStockCount++
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ notExistsCount++
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 组装返回数据
|
|
|
+ r_jsons := map[string]interface{}{
|
|
|
+ "devices": results,
|
|
|
+ "stats": map[string]interface{}{
|
|
|
+ "total_input": totalInputCount,
|
|
|
+ "exists": existsCount,
|
|
|
+ "in_stock": inStockCount,
|
|
|
+ "out_stock": outStockCount,
|
|
|
+ "not_exists": notExistsCount,
|
|
|
+ "total_in_stock": len(inStockDevices),
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "盘点完成", Data: r_jsons}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
func (c *StockController) Stock_List() {
|
|
|
|
|
|
// 分页参数 初始化
|
|
|
@@ -777,6 +1076,7 @@ func (c *StockController) StockIn_Add() {
|
|
|
T_iccid: mqtt.Iccid,
|
|
|
T_imei: mqtt.Imei,
|
|
|
T_State: 2,
|
|
|
+ T_batch_number: T_batch_number,
|
|
|
CreateTime: date,
|
|
|
}
|
|
|
_, err = DeviceDao.AddOrUpdate_Device(device, 2)
|
|
|
@@ -830,6 +1130,15 @@ func (c *StockController) StockIn_Add() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 批量更新所有相关设备的批次号
|
|
|
+ err = DeviceDao.Update_Device_BatchNumber_ByInNumber(T_number, T_batch_number)
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: "更新设备批次号失败"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
o.Commit()
|
|
|
StockIn_Edit_StockMonth(T_date, T_depot_id, allProductList)
|
|
|
|
|
|
@@ -948,7 +1257,6 @@ func (c *StockController) StockIn_Edit() {
|
|
|
return
|
|
|
}
|
|
|
T_old_date := stockIn.T_date
|
|
|
- T_old_batch_number := stockIn.T_batch_number
|
|
|
|
|
|
// 查询入库产品信息
|
|
|
productOldList := StockInProductDao.Read_StockInProduct_List_ByT_number(stockIn.T_number)
|
|
|
@@ -1057,6 +1365,7 @@ func (c *StockController) StockIn_Edit() {
|
|
|
T_iccid: mqtt.Iccid,
|
|
|
T_imei: mqtt.Imei,
|
|
|
T_State: 2,
|
|
|
+ T_batch_number: T_batch_number,
|
|
|
CreateTime: date,
|
|
|
UpdateTime: stockIn.UpdateTime,
|
|
|
}
|
|
|
@@ -1272,10 +1581,11 @@ func (c *StockController) StockIn_Edit() {
|
|
|
StockInProductDao.Update_StockInProduct_T_date(stockIn.T_number, T_date)
|
|
|
DeviceDao.Update_Device_CreateTimeByT_in_number(stockIn.T_number, T_date)
|
|
|
}
|
|
|
- if len(T_batch_number) > 0 && T_old_batch_number != T_batch_number {
|
|
|
- // 修改出库产品日期
|
|
|
- StockInProductDao.Update_StockInProduct_T_batch_number(stockIn.T_number, T_date)
|
|
|
- }
|
|
|
+
|
|
|
+ // 修改出库产品日期
|
|
|
+ StockInProductDao.Update_StockInProduct_T_batch_number(stockIn.T_number, T_batch_number)
|
|
|
+ // 修改设备批次号
|
|
|
+ DeviceDao.Update_Device_BatchNumber_ByInNumber(stockIn.T_number, T_batch_number)
|
|
|
|
|
|
// 更新月份统计表
|
|
|
allProductList := []int{}
|
|
|
@@ -2102,12 +2412,18 @@ func (c *StockController) StockOut_Add() {
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
- // 2、更新设备状态为已出库
|
|
|
if len(T_relation_sn) > 0 {
|
|
|
snList := lib.SplitString(T_relation_sn, ",")
|
|
|
num = len(snList)
|
|
|
for _, sn := range snList {
|
|
|
mqtt := Stock.Read_MqttUser(sn)
|
|
|
+
|
|
|
+ // 根据IMEI查询上次入库的批次号
|
|
|
+ batchNumber, err := DeviceDao.Read_Device_BatchNumber_ByImei(mqtt.Imei)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ }
|
|
|
+
|
|
|
device := Stock.Device{
|
|
|
T_contract_number: T_contract_number,
|
|
|
T_product_id: product_id,
|
|
|
@@ -2117,6 +2433,7 @@ func (c *StockController) StockOut_Add() {
|
|
|
T_imei: mqtt.Imei,
|
|
|
T_State: 1,
|
|
|
T_project: T_project,
|
|
|
+ T_batch_number: batchNumber,
|
|
|
CreateTime: date,
|
|
|
}
|
|
|
_, err = DeviceDao.AddOrUpdate_Device(device, 1)
|
|
|
@@ -2134,7 +2451,7 @@ func (c *StockController) StockOut_Add() {
|
|
|
T_product_id: product_id,
|
|
|
T_depot_id: T_depot_id,
|
|
|
T_num: num, // 出库数量
|
|
|
- T_date: T_date, // 出库数量
|
|
|
+ T_date: T_date, // 出库日期
|
|
|
T_relation_sn: T_relation_sn,
|
|
|
T_state: 1,
|
|
|
}
|
|
|
@@ -2553,6 +2870,7 @@ func (c *StockController) StockOut_Edit() {
|
|
|
if len(diff.T_add_relation_sn) > 0 {
|
|
|
for _, sn := range diff.T_add_relation_sn {
|
|
|
mqtt := Stock.Read_MqttUser(sn)
|
|
|
+
|
|
|
// 添加设备
|
|
|
device := Stock.Device{
|
|
|
T_contract_number: "",
|
|
|
@@ -3906,37 +4224,45 @@ func (c *StockController) StockOut_Warehouse() {
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
+ if len(T_relation_sn) > 0 {
|
|
|
+ snList := strings.Split(T_relation_sn, ",")
|
|
|
+ if product.T_relation_sn == 1 && num != len(snList) {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("%s SN数量与出库数量不一致,请核查!", product.T_name)}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- snList := strings.Split(T_relation_sn, ",")
|
|
|
- if product.T_relation_sn == 1 && num != len(snList) {
|
|
|
- o.Rollback()
|
|
|
- c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("%s SN数量与出库数量不一致,请核查!", product.T_name)}
|
|
|
- c.ServeJSON()
|
|
|
- return
|
|
|
- }
|
|
|
+ if len(snList) > 0 {
|
|
|
|
|
|
- // 2、更新设备状态为已出库
|
|
|
- if len(snList) > 0 {
|
|
|
+ for _, sn := range snList {
|
|
|
+ mqtt := Stock.Read_MqttUser(sn)
|
|
|
|
|
|
- for _, sn := range snList {
|
|
|
- mqtt := Stock.Read_MqttUser(sn)
|
|
|
- device := Stock.Device{
|
|
|
- T_contract_number: StockOut.T_contract_number,
|
|
|
- T_product_id: product_id,
|
|
|
- T_out_number: T_number,
|
|
|
- T_sn: sn,
|
|
|
- T_iccid: mqtt.Iccid,
|
|
|
- T_imei: mqtt.Imei,
|
|
|
- T_State: 1,
|
|
|
- T_project: StockOut.T_project,
|
|
|
- CreateTime: date,
|
|
|
- }
|
|
|
- _, err = DeviceDao.AddOrUpdate_Device(device, 1)
|
|
|
- if err != nil {
|
|
|
- o.Rollback()
|
|
|
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "出库失败"}
|
|
|
- c.ServeJSON()
|
|
|
- return
|
|
|
+ // 根据IMEI查询上次入库的批次号
|
|
|
+ batchNumber, err := DeviceDao.Read_Device_BatchNumber_ByImei(mqtt.Imei)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ }
|
|
|
+
|
|
|
+ device := Stock.Device{
|
|
|
+ T_contract_number: StockOut.T_contract_number,
|
|
|
+ T_product_id: product_id,
|
|
|
+ T_out_number: T_number,
|
|
|
+ T_sn: sn,
|
|
|
+ T_iccid: mqtt.Iccid,
|
|
|
+ T_imei: mqtt.Imei,
|
|
|
+ T_State: 1,
|
|
|
+ T_project: StockOut.T_project,
|
|
|
+ T_batch_number: batchNumber,
|
|
|
+ CreateTime: date,
|
|
|
+ }
|
|
|
+ _, err = DeviceDao.AddOrUpdate_Device(device, 1)
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "出库失败"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|