Explorar el Código

feature: 添加非优先预约人员可预约时间限制

liuyaqi hace 2 años
padre
commit
2694495b72
Se han modificado 5 ficheros con 40 adiciones y 2 borrados
  1. 2 2
      config/config.toml
  2. 16 0
      handler/equipment.go
  3. 6 0
      model/equipment/instrument.go
  4. 15 0
      service/equipment/equipment.go
  5. 1 0
      sql/tmp.sql

+ 2 - 2
config/config.toml

@@ -12,8 +12,8 @@
     time_split = 30
     begin_at = "00:00:00"
     end_at = "24:00:00"
-    begin = "08:00:00"
-    end = "20:00:00"
+    begin = "00:00:00"
+    end = "24:00:00"
     weekday = "1,2,3,4,5,6,7"
 
 [appointment]

+ 16 - 0
handler/equipment.go

@@ -389,3 +389,19 @@ func (e *Equipment) RateChange(ctx context.Context, req *equipment2.InstrumentId
 	rsp.Msg = msg
 	return nil
 }
+
+func (e *Equipment) UpdateFurtherLimit(ctx context.Context, req *equipment2.UpdateFurtherLimitReq, rsp *comm_def.CommonMsg) error {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return err
+	}
+	g.Log().Info("Received Equipment.UpdateFurtherLimit request @ " + tenant)
+	if strconv.Itoa(req.InstrumentId) == "" || strconv.Itoa(req.FurtherLimit) == "" {
+		return errors.New("请输入完成参数!")
+	}
+	err = equipment.NewSrv(tenant).UpdateFurtherLimit(req.InstrumentId, req.FurtherLimit)
+	_, err, code, msg := myerrors.CheckError(err)
+	rsp.Code = code
+	rsp.Msg = msg
+	return nil
+}

+ 6 - 0
model/equipment/instrument.go

@@ -19,6 +19,12 @@ type InstrumentId struct {
 	UnitCount    float64 `json:"unit_count"`    // 计费单价
 	Rate         int     `json:"rate"`          // 优惠比例
 }
+
+type UpdateFurtherLimitReq struct {
+	InstrumentId int     `json:"instrument_id"` // 设备Id
+	FurtherLimit int     `json:"further_limit"` // 非优先预约人员可预约时间/小时
+}
+
 type InstrumentEntity struct {
 	Instrument Instrument
 	CountType  string `json:"countType"`

+ 15 - 0
service/equipment/equipment.go

@@ -256,6 +256,7 @@ type AppointTimeInfoInstrument struct {
 	IsAppointAvailable int // 是否默认可预约 1是 2否
 	InAdvance          int // 需要提前预约时间 单位小时
 	FurtherRange       int // 未来可预约范围 单位周
+	FurtherLimit       int // 非优先预约人员可预约时间/小时
 
 }
 
@@ -347,6 +348,7 @@ func (s Service) AppointTimeInfo(req *equipment2.AppointTimeInfoReq, userinfo re
 	if err != nil {
 		return nil, err
 	}
+	var furtherLimit *gtime.Time
 	if qualificationCount == 0 {
 		err := s.Dao.DB.Model("base_equipment_advance_time").
 			Where("EquipmentId = ?", req.InstrumentId).
@@ -357,6 +359,9 @@ func (s Service) AppointTimeInfo(req *equipment2.AppointTimeInfoReq, userinfo re
 		if err != nil {
 			return nil, err
 		}
+		if instr.FurtherLimit != 0 {
+			furtherLimit = gtime.Now().Add(time.Hour * time.Duration(instr.FurtherLimit))
+		}
 	}
 
 	unavailable := []TimeSpan{}
@@ -434,6 +439,7 @@ func (s Service) AppointTimeInfo(req *equipment2.AppointTimeInfoReq, userinfo re
 	}
 
 	return map[string]interface{}{
+		"further_limit": furtherLimit,
 		"further_range": instr.FurtherRange,
 		"time_split":    timesplit,
 		"begin_at":      instr.BeginAt.Time.Format("15:04:05"),
@@ -522,6 +528,15 @@ func (s Service) RateChange(InstrumentId, rate int) error {
 	return nil
 }
 
+func (s Service) UpdateFurtherLimit(id, limit int) error {
+	_, err := s.Dao.DB.Model("Instrument").Update("FurtherLimit = "+strconv.Itoa(limit), "Id = "+
+		strconv.Itoa(id))
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
 // IsAdvance 是否有优先预约资格
 func (s Service) IsAdvance(id int32, instrumentId int) (isAdvance int, err error) {
 	equipmentQualification := equipment2.BaseEquipmentQualification{}

+ 1 - 0
sql/tmp.sql

@@ -61,3 +61,4 @@ CREATE TABLE `announcement_read_record` (
 alter table instrument add `InAdvance` int(11) DEFAULT NULL COMMENT '需要提前预约时间 单位小时' after EndAt;
 alter table instrument add `FurtherRange` int(11) DEFAULT NULL COMMENT '未来可预约范围 单位周' after EndAt;
 alter table instrument modify `Responsible` varchar(2048) DEFAULT NULL COMMENT '责任人';
+alter table instrument add  `FurtherLimit` int(11) DEFAULT NULL COMMENT '非优先预约人员可预约时间/小时' after Rate;