|
@@ -11,6 +11,7 @@ import (
|
|
"fmt"
|
|
"fmt"
|
|
"gogs.baozhida.cn/zoie/OAuth-core/service"
|
|
"gogs.baozhida.cn/zoie/OAuth-core/service"
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm"
|
|
|
|
+ "sort"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -58,6 +59,18 @@ func IceRaftNameRecordStatusScopes(status string) func(db *gorm.DB) *gorm.DB {
|
|
return db.Where("ice_raft_record.status = ?", status)
|
|
return db.Where("ice_raft_record.status = ?", status)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+func IceRaftNameRecordIceLockerScopes(status string) func(db *gorm.DB) *gorm.DB {
|
|
|
|
+ return func(db *gorm.DB) *gorm.DB {
|
|
|
|
+ if len(status) == 0 {
|
|
|
|
+ return db.Where("ice_raft_record.status = 1 or ice_raft_record.status =2")
|
|
|
|
+ }
|
|
|
|
+ if status == "0" {
|
|
|
|
+ return db.Where("ice_raft_record.status is null")
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return db.Where("ice_raft_record.status = ?", status)
|
|
|
|
+ }
|
|
|
|
+}
|
|
func IceRaftNameRecordIceLockerIdScopes(iceLockerId int) func(db *gorm.DB) *gorm.DB {
|
|
func IceRaftNameRecordIceLockerIdScopes(iceLockerId int) func(db *gorm.DB) *gorm.DB {
|
|
return func(db *gorm.DB) *gorm.DB {
|
|
return func(db *gorm.DB) *gorm.DB {
|
|
if iceLockerId == 0 {
|
|
if iceLockerId == 0 {
|
|
@@ -75,6 +88,22 @@ func IceRaftNameRecordCoolerBoxIdScopes(coolerBoxId int) func(db *gorm.DB) *gorm
|
|
return db.Where("ice_raft_record.cooler_box_id = ?", coolerBoxId)
|
|
return db.Where("ice_raft_record.cooler_box_id = ?", coolerBoxId)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+func IceRaftStartTimeAndEndTimeScopes(startTime, endtime string) func(db *gorm.DB) *gorm.DB {
|
|
|
|
+ return func(db *gorm.DB) *gorm.DB {
|
|
|
|
+ if len(startTime) == 0 {
|
|
|
|
+ return db
|
|
|
|
+ }
|
|
|
|
+ return db.Where("ice_raft_record.ice_use_time >= ?", startTime).Where("ice_raft_record.ice_use_time <= ?", endtime)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+func CollerStartTimeAndEndTimeScopes(startTime, endtime string) func(db *gorm.DB) *gorm.DB {
|
|
|
|
+ return func(db *gorm.DB) *gorm.DB {
|
|
|
|
+ if len(startTime) == 0 {
|
|
|
|
+ return db
|
|
|
|
+ }
|
|
|
|
+ return db.Where("cooler_box_record.cooler_box_star_time >= ?", startTime).Where("cooler_box_record.cooler_box_star_time <= ?", endtime)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
func (e *IceRaft) GetRecordPage(c *dto.IceRaftGetNewestRecordPageReq, list *[]model.IceRaft, count *int64, p *actions.DataPermission) error {
|
|
func (e *IceRaft) GetRecordPage(c *dto.IceRaftGetNewestRecordPageReq, list *[]model.IceRaft, count *int64, p *actions.DataPermission) error {
|
|
var err error
|
|
var err error
|
|
@@ -368,12 +397,14 @@ func (e *IceRaft) InStorage(c *dto.IceRaftInStorageReq, p *actions.DataPermissio
|
|
IceRaftId: iceRaftModel.Id,
|
|
IceRaftId: iceRaftModel.Id,
|
|
Status: model.IceRaftRecordStatusFreezing,
|
|
Status: model.IceRaftRecordStatusFreezing,
|
|
Label: iceRaftModel.Label,
|
|
Label: iceRaftModel.Label,
|
|
|
|
+ Code: code,
|
|
InStorageTime: model2.Time(time.Now()),
|
|
InStorageTime: model2.Time(time.Now()),
|
|
- FreezeClaim: iceRaftModel.FreezeClaim,
|
|
|
|
|
|
+ //FreezeClaim: iceRaftModel.FreezeClaim,
|
|
DeptBy: model2.DeptBy{
|
|
DeptBy: model2.DeptBy{
|
|
DeptId: p.DeptId,
|
|
DeptId: p.DeptId,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
+ iceRaftRecordModel.FreezeClaim = append(iceRaftRecordModel.FreezeClaim, iceRaftModel.FreezeClaim...)
|
|
err = tx.Create(&iceRaftRecordModel).Error
|
|
err = tx.Create(&iceRaftRecordModel).Error
|
|
if err != nil {
|
|
if err != nil {
|
|
e.Log.Errorf("db error: %s", err)
|
|
e.Log.Errorf("db error: %s", err)
|
|
@@ -418,7 +449,11 @@ func (e *IceRaft) OutStorage(c *dto.IceRaftOutStorageReq, p *actions.DataPermiss
|
|
err = errors.New("保温箱状态异常")
|
|
err = errors.New("保温箱状态异常")
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ var user model.SysUser
|
|
|
|
+ first := e.Orm.Model(&model.SysUser{}).Where("id = ?", p.UserId).First(&user)
|
|
|
|
+ if first.Error != nil {
|
|
|
|
+ return global.GetFailedErr
|
|
|
|
+ }
|
|
for _, code := range c.Code {
|
|
for _, code := range c.Code {
|
|
// 查询冰排是否存在
|
|
// 查询冰排是否存在
|
|
var iceRaftModel model.IceRaft
|
|
var iceRaftModel model.IceRaft
|
|
@@ -452,15 +487,33 @@ func (e *IceRaft) OutStorage(c *dto.IceRaftOutStorageReq, p *actions.DataPermiss
|
|
}
|
|
}
|
|
|
|
|
|
inTime := iceRaftRecordModel.InStorageTime.Local()
|
|
inTime := iceRaftRecordModel.InStorageTime.Local()
|
|
- if inTime.Add(time.Hour * time.Duration(iceRaftRecordModel.FreezeClaim)).After(time.Now()) {
|
|
|
|
- err = errors.New(fmt.Sprintf("冰排【%s】未达到冷冻时长,禁止出库", code))
|
|
|
|
|
|
+ sort.Slice(iceRaftRecordModel.FreezeClaim, func(i, j int) bool {
|
|
|
|
+ return iceRaftRecordModel.FreezeClaim[i] < iceRaftRecordModel.FreezeClaim[j]
|
|
|
|
+ })
|
|
|
|
+ err, sysUser := GetUserProfile(e.Orm, p.UserId)
|
|
|
|
+ if err != nil {
|
|
|
|
+ err = errors.New("获取用户信息失败")
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
+ if sysUser.Dept.IsOutStorage {
|
|
|
|
+ for _, v := range iceRaftRecordModel.FreezeClaim {
|
|
|
|
+ if inTime.Add(time.Hour * time.Duration(v)).After(time.Now()) {
|
|
|
|
+ str := fmt.Sprintf("冰排【%s】未达到冷冻时长【%v】,禁止出库", code, v)
|
|
|
|
+ err = errors.New(str)
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //if inTime.Add(time.Hour * time.Duration(iceRaftRecordModel.FreezeClaim[0])).After(time.Now()) {
|
|
|
|
+ // err = errors.New(fmt.Sprintf("冰排【%s】未达到冷冻时长,禁止出库", code))
|
|
|
|
+ // return err
|
|
|
|
+ //}
|
|
|
|
|
|
iceRaftRecordModel.Status = model.IceRaftRecordStatusUsing
|
|
iceRaftRecordModel.Status = model.IceRaftRecordStatusUsing
|
|
iceRaftRecordModel.CoolerBoxId = coolerBoxModel.Id
|
|
iceRaftRecordModel.CoolerBoxId = coolerBoxModel.Id
|
|
iceRaftRecordModel.OutStorageTime = model2.Time(time.Now())
|
|
iceRaftRecordModel.OutStorageTime = model2.Time(time.Now())
|
|
- iceRaftRecordModel.SuitableForCold = c.SuitableForCold
|
|
|
|
|
|
+ iceRaftRecordModel.IceUseUsers = user.NickName
|
|
|
|
+ iceRaftRecordModel.IceUseTime = model2.Time(time.Now())
|
|
//data, err := nats_server.Read_DeviceTask_List_By_Condition(coolerBoxModel.Sn)
|
|
//data, err := nats_server.Read_DeviceTask_List_By_Condition(coolerBoxModel.Sn)
|
|
//if data.T_State != 1 {
|
|
//if data.T_State != 1 {
|
|
// e.Log.Errorf("该保温箱未启动: %s", err)
|
|
// e.Log.Errorf("该保温箱未启动: %s", err)
|
|
@@ -478,14 +531,81 @@ func (e *IceRaft) OutStorage(c *dto.IceRaftOutStorageReq, p *actions.DataPermiss
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //添加保温箱记录
|
|
|
|
+ var cooler model.CoolerBoxRecord
|
|
|
|
+ cooler.CoolerBoxId = coolerBoxModel.Id
|
|
|
|
+ cooler.CoolerUserTime = model2.Time(time.Now())
|
|
|
|
+ cooler.Sn = coolerBoxModel.Sn
|
|
|
|
+ cooler.Status = "1" //保温箱使用状态变为使用中
|
|
|
|
+ cooler.DeptId = p.DeptId
|
|
|
|
+ cooler.Name = coolerBoxModel.Name
|
|
|
|
+ cooler.HistoryCode = append(cooler.HistoryCode, c.Code...)
|
|
|
|
+ cooler.CoolerUseUsers = user.NickName
|
|
|
|
+ //查询是否有正在使用中的保温箱记录
|
|
|
|
+ var count int64
|
|
|
|
+ err = e.Orm.Model(&model.CoolerBoxRecord{}).Where("id = ?", coolerBoxModel.Id).Where("status = ?", "1").Count(&count).Error
|
|
|
|
+ if err != nil {
|
|
|
|
+ e.Log.Errorf("获取保温箱信息失败: %s", err)
|
|
|
|
+ return errors.New("获取保温箱信息失败")
|
|
|
|
+ }
|
|
|
|
+ //如果有正在使用中的保温箱记录,就更新
|
|
|
|
+ if count > 0 {
|
|
|
|
+ err = e.Orm.Updates(&cooler).Error
|
|
|
|
+ if err != nil {
|
|
|
|
+ e.Log.Errorf("db 更新保温箱记录失败: %s", err)
|
|
|
|
+ return errors.New("更新保温箱记录失败")
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ err = e.Orm.Create(&cooler).Error
|
|
|
|
+ if err != nil {
|
|
|
|
+ e.Log.Errorf("db 创建保温箱记录失败: %s", err)
|
|
|
|
+ return errors.New("创建保温箱记录失败")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// IsOutStorage 判断冰排是否达到冷冻时长
|
|
|
|
+func (e *IceRaft) IsOutStorage(c *dto.IceOutStorageReq, p *actions.DataPermission) (error, string) {
|
|
|
|
+ var err error
|
|
|
|
+ var str string
|
|
|
|
+ // 获取冰排记录
|
|
|
|
+ for _, v := range c.Code {
|
|
|
|
+ var iceRaftRecordModel model.IceRaftRecord
|
|
|
|
+ err = e.Orm.Scopes(actions.Permission(iceRaftRecordModel.TableName(), p)).
|
|
|
|
+ Where("code = ?", v).
|
|
|
|
+ Where("status = ?", model.IceRaftRecordStatusFreezing).Or("status = ?", model.IceRaftRecordStatusWaitUse).
|
|
|
|
+ First(&iceRaftRecordModel).Error
|
|
|
|
+ if err != nil {
|
|
|
|
+ e.Log.Errorf("db error: %s", err)
|
|
|
|
+ return errors.New("获取冰排记录失败,请确认冰排是否入库!"), ""
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if len(iceRaftRecordModel.OutStorageTime.String()) > 0 {
|
|
|
|
+ err = errors.New(fmt.Sprintf("冰排【%s】已出库,禁止出库!", v))
|
|
|
|
+ return err, ""
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ inTime := iceRaftRecordModel.InStorageTime.Local()
|
|
|
|
+ sort.Slice(iceRaftRecordModel.FreezeClaim, func(i, j int) bool {
|
|
|
|
+ return iceRaftRecordModel.FreezeClaim[i] < iceRaftRecordModel.FreezeClaim[j]
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ for _, vs := range iceRaftRecordModel.FreezeClaim {
|
|
|
|
+ if inTime.Add(time.Hour * time.Duration(vs)).After(time.Now()) {
|
|
|
|
+ str = fmt.Sprintf("冰排编号【%s】未达到冷冻时长【%v】小时,已达到冷冻时长【%v】,是否继续出库", v, vs, time.Now().Sub(inTime))
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return nil, str
|
|
|
|
+}
|
|
|
|
+
|
|
// 查询保温箱关联的冰排
|
|
// 查询保温箱关联的冰排
|
|
func (e *IceRaft) GetPageByCoolerBoxId(coolerBoxId int, list *[]string, p *actions.DataPermission) error {
|
|
func (e *IceRaft) GetPageByCoolerBoxId(coolerBoxId int, list *[]string, p *actions.DataPermission) error {
|
|
var data model.IceRaft
|
|
var data model.IceRaft
|
|
err := e.Orm.Model(&data).
|
|
err := e.Orm.Model(&data).
|
|
- Select("code").
|
|
|
|
|
|
+ Select("ice_raft.code").
|
|
Scopes(
|
|
Scopes(
|
|
actions.Permission(data.TableName(), p),
|
|
actions.Permission(data.TableName(), p),
|
|
IceRaftNameRecordStatusScopes(model.IceRaftRecordStatusUsing),
|
|
IceRaftNameRecordStatusScopes(model.IceRaftRecordStatusUsing),
|
|
@@ -686,9 +806,15 @@ func (e *IceRaftRecord) StartForCold(c *dto.IceStartbleForColfTimReq, p *actions
|
|
tx.Commit()
|
|
tx.Commit()
|
|
}
|
|
}
|
|
}()
|
|
}()
|
|
|
|
+ var user model.SysUser
|
|
|
|
+ first := e.Orm.Model(&model.SysUser{}).Where("id = ?", p.UserId).First(&user)
|
|
|
|
+ if first.Error != nil {
|
|
|
|
+ return global.GetFailedErr
|
|
|
|
+ }
|
|
//查询冰排是否存在
|
|
//查询冰排是否存在
|
|
for _, v := range c.Id {
|
|
for _, v := range c.Id {
|
|
var iceRaftRecordModel model.IceRaftRecord
|
|
var iceRaftRecordModel model.IceRaftRecord
|
|
|
|
+ var iceRaft model.IceRaft
|
|
err = e.Orm.Scopes(actions.Permission(iceRaftRecordModel.TableName(), p)).
|
|
err = e.Orm.Scopes(actions.Permission(iceRaftRecordModel.TableName(), p)).
|
|
First(&iceRaftRecordModel, v).Error
|
|
First(&iceRaftRecordModel, v).Error
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -698,7 +824,15 @@ func (e *IceRaftRecord) StartForCold(c *dto.IceStartbleForColfTimReq, p *actions
|
|
}
|
|
}
|
|
return global.UpdateFailedErr
|
|
return global.UpdateFailedErr
|
|
}
|
|
}
|
|
|
|
+ err = e.Orm.Model(&iceRaft).Where("id = ?", iceRaftRecordModel.IceRaftId).Error
|
|
|
|
+ if err != nil {
|
|
|
|
+ return global.GetFailedErr
|
|
|
|
+ }
|
|
iceRaftRecordModel.StartIceColdTime = model2.Time(time.Now())
|
|
iceRaftRecordModel.StartIceColdTime = model2.Time(time.Now())
|
|
|
|
+ iceRaftRecordModel.Status = model.IceRaftRecordReleasedInTheCold //释冷中
|
|
|
|
+ iceRaftRecordModel.IceColdUsers = user.NickName
|
|
|
|
+ iceRaftRecordModel.IceColdAddress = iceRaft.IceColdAddress
|
|
|
|
+ iceRaftRecordModel.SuitableForCold = iceRaft.SuitableForCold
|
|
updates := tx.Where("id = ?", iceRaftRecordModel.Id).Updates(&iceRaftRecordModel)
|
|
updates := tx.Where("id = ?", iceRaftRecordModel.Id).Updates(&iceRaftRecordModel)
|
|
if err = updates.Error; err != nil {
|
|
if err = updates.Error; err != nil {
|
|
e.Log.Errorf("db error: %s", err)
|
|
e.Log.Errorf("db error: %s", err)
|
|
@@ -707,3 +841,40 @@ func (e *IceRaftRecord) StartForCold(c *dto.IceStartbleForColfTimReq, p *actions
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// IceRaftRecordRecording 获取冰排的历史记录
|
|
|
|
+func (e *IceRaft) IceRaftRecordRecording(c *dto.IceRaftRecordRecording, list *[]model.IceRaftRecord, count *int64, p *actions.DataPermission) error {
|
|
|
|
+ var err error
|
|
|
|
+ var data model.IceRaftRecord
|
|
|
|
+ if c.PageSize == 9999 {
|
|
|
|
+ err = e.Orm.Model(&data).
|
|
|
|
+ Scopes(
|
|
|
|
+ cDto.MakeCondition(c.GetNeedSearch()),
|
|
|
|
+ actions.Permission(data.TableName(), p),
|
|
|
|
+ IceRaftStartTimeAndEndTimeScopes(c.StartTime, c.EndTime),
|
|
|
|
+ ).
|
|
|
|
+ Where("status =?", model.IceRaftRecordStatusFinish).
|
|
|
|
+ Preload("IceLocker").
|
|
|
|
+ Preload("CoolerBox").
|
|
|
|
+ Find(list).Limit(-1).Offset(-1).
|
|
|
|
+ Count(count).Error
|
|
|
|
+ } else {
|
|
|
|
+ err = e.Orm.Model(&data).
|
|
|
|
+ Scopes(
|
|
|
|
+ cDto.MakeCondition(c.GetNeedSearch()),
|
|
|
|
+ cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
|
|
|
|
+ actions.Permission(data.TableName(), p),
|
|
|
|
+ IceRaftStartTimeAndEndTimeScopes(c.StartTime, c.EndTime),
|
|
|
|
+ ).
|
|
|
|
+ Where("status =?", model.IceRaftRecordStatusFinish).
|
|
|
|
+ Preload("IceLocker").
|
|
|
|
+ Preload("CoolerBox").
|
|
|
|
+ Find(list).Limit(-1).Offset(-1).
|
|
|
|
+ Count(count).Error
|
|
|
|
+ }
|
|
|
|
+ if err != nil {
|
|
|
|
+ e.Log.Errorf("db error: %s", err)
|
|
|
|
+ return global.GetFailedErr
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+}
|