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

fix(账单): 未出账单实际上机时间优化

likai пре 4 година
родитељ
комит
81761a7cd1

+ 50 - 0
model/account/settle_account_main.go

@@ -58,4 +58,54 @@ type MainInfo struct {
 	SettleAccountMain
 	SignInTime         *gtime.Time `orm:"SignInTime"         json:"sign_in_time"`         // 签到时间
 	SignOutTime        *gtime.Time `orm:"SignOutTime"        json:"sign_out_time"`        // 签退时间
+}
+
+type Instrument struct {
+	Id                      int         `orm:"Id,primary"              json:"id"`                        //
+	RoomId                  int         `orm:"RoomId"                  json:"room_id"`                   // 所属房间id
+	Code                    string      `orm:"Code"                    json:"code"`                      // 设备编码
+	Name                    string      `orm:"Name"                    json:"name"`                      // 设备名称
+	InstrImgId              int         `orm:"InstrImgId"              json:"instr_img_id"`              // 设备图片id
+	InstrImgUrl             string      `orm:"InstrImgUrl"             json:"instr_img_url"`             // 设备图片Url
+	SupplierId              int         `orm:"SupplierId"              json:"supplier_id"`               // 供应商
+	FactoryNum              string      `orm:"FactoryNum"              json:"factory_num"`               // 出厂编号
+	Model                   string      `orm:"Model"                   json:"model"`                     // 型号
+	Brand                   string      `orm:"Brand"                   json:"brand"`                     // 设备品牌
+	InstrType               int         `orm:"InstrType"               json:"instr_type"`                // 设备类别
+	Belongs                 int         `orm:"Belongs"                 json:"belongs"`                   // 设备所属 1内部 2外部
+	BelongsName             string      `orm:"BelongsName"             json:"belongs_name"`              // 设备所属名称
+	Status                  int         `orm:"Status"                  json:"status"`                    // 设备状态
+	Location                string      `orm:"Location"                json:"location"`                  // 设备所在位置
+	Remark                  string      `orm:"Remark"                  json:"remark"`                    // 备注
+	IsFixedPoint            int         `orm:"IsFixedPoint"            json:"is_fixed_point"`            // 参与点检:
+	CalibrationAt           *gtime.Time `orm:"CalibrationAt"           json:"calibration_at"`            // 校准时间
+	CalibrationDeadline     int         `orm:"CalibrationDeadline"     json:"calibration_deadline"`      // 校准使用期限
+	CalibrationDeadlineType int         `orm:"CalibrationDeadlineType" json:"calibration_deadline_type"` // 期限类型
+	MaintenCycle            int         `orm:"MaintenCycle"            json:"mainten_cycle"`             // 维护周期数
+	CycleType               int         `orm:"CycleType"               json:"cycle_type"`                // 期限类型
+	HeartbeatAt             *gtime.Time `orm:"HeartbeatAt"             json:"heartbeat_at"`              // 心跳时间
+	Spec                    string      `orm:"Spec"                    json:"spec"`                      // 规格
+	CreatedAt               string      `orm:"CreatedAt"               json:"created_at"`                // 创建时间
+	CreatedBy               int         `orm:"CreatedBy"               json:"created_by"`                // 创建人
+	UpdatedAt               *gtime.Time `orm:"UpdatedAt"               json:"updated_at"`                // 更新时间
+	UpdatedBy               int         `orm:"UpdatedBy"               json:"updated_by"`                // 更新人
+	TimeNotification        int         `orm:"TimeNotification"        json:"time_notification"`         // 有效期提醒
+	Sharable                int         `orm:"Sharable"                json:"sharable"`                  // 是否共享(可预约)
+	EndTime                 *gtime.Time `orm:"EndTime"                 json:"end_time"`                  // 截止日期
+	Responsible             string      `orm:"Responsible"             json:"responsible"`               // 责任人
+	MaintenTime             *gtime.Time `orm:"MaintenTime"             json:"mainten_time"`              // 最后维护时间
+	PurchaseTime            *gtime.Time `orm:"PurchaseTime"            json:"purchase_time"`             // 采购日期
+	JoinPlan                int         `orm:"JoinPlan"                json:"join_plan"`                 // 计划
+	IsAppoint               int         `orm:"IsAppoint"               json:"is_appoint"`                // 是否需要预约
+	IsAppointAvailable      string      `orm:"IsAppointAvailable"      json:"IsAppointAvailable"`        // 是否默认可预约 1是 2否
+	DeletedAt               *gtime.Time `orm:"DeletedAt"               json:"deleted_at"`                // 删除时间
+	Weekday                 string      `orm:"Weekday"                 json:"weekday"`                   // 每周可预约日
+	BeginAt                 *gtime.Time `orm:"BeginAt"                 json:"begin_at"`                  // 预约开始时段
+	EndAt                   *gtime.Time `orm:"EndAt"                   json:"end_at"`                    // 预约结束时间
+	MediaIds                string      `orm:"MediaIds"                json:"media_ids"`                 // 文件ID
+	IsOpen                  int         `orm:"IsOpen"                  json:"is_open"`                   // 是否开启预约  1开启 2未开启
+	Instructions            string      `orm:"Instructions"            json:"instructions"`              // 使用说明
+	Terminal                string      `orm:"Terminal"                json:"terminal"`                  // 信息终端
+	RoleId                  int         `orm:"RoleId"                  json:"role_id"`                   // 自动审批角色
+	Sort                    int         `json:"sort" orm:"Sort"`                                         // 排序
 }

+ 27 - 3
service/settle_account_main/settle_account_main.go

@@ -164,6 +164,7 @@ func (s Service) List(req model.ListReq, user request.UserInfo) ([]accountModel.
 func (s Service) Add(req accountModel.AccountMainAddReq, user request.UserInfo) error {
 	now := gtime.Now() // 获取当前时间
 	var baseAccount accountModel.BaseAccount
+	var instrument accountModel.Instrument
 
 	// 更新必要信息
 	req.Main.CreateUserId = int(user.Id)
@@ -172,9 +173,11 @@ func (s Service) Add(req accountModel.AccountMainAddReq, user request.UserInfo)
 	req.Main.UpdateUserId = int(user.Id)
 	req.Main.UpdateBy = user.RealName
 	req.Main.UpdateOn = now
-	req.Main.ActualStartDate = req.Main.AppointStartDate
-	req.Main.ActualEndDate = req.Main.AppointEndDate
-	span := req.Main.ActualEndDate.Sub(req.Main.ActualStartDate)
+
+	req.Main.ActualStartDate = nil  // 默认有信息终端
+	req.Main.ActualEndDate = nil    // 默认有信息终端
+
+	span := req.Main.AppointEndDate.Sub(req.Main.AppointStartDate)
 	req.Main.FeeTime = int(math.Ceil(span.Minutes()))
 	req.Main.ActualMachineHour = req.Main.FeeTime
 	req.Main.Status = "0"
@@ -187,9 +190,30 @@ func (s Service) Add(req accountModel.AccountMainAddReq, user request.UserInfo)
 		return err
 	}
 	err = result1.Struct(&baseAccount)
+	if err != nil {
+		if err == sql.ErrNoRows {
+			return errors.New("无可用账户")
+		}
+		return err
+	}
+
+	// 获取设备
+	result1, err = s.Dao.DB.Model("instrument").Where(fmt.Sprintf("Id='%v'", req.Main.InstrumentId)).FindOne()
 	if err != nil {
 		return err
 	}
+	err = result1.Struct(&instrument)
+	if err != nil {
+		if err == sql.ErrNoRows {
+			return errors.New("无可用设备")
+		}
+		return err
+	}
+
+	if instrument.Terminal == "" { // 无信息终端时,按预约时间计算
+		req.Main.ActualStartDate = req.Main.AppointStartDate
+		req.Main.ActualEndDate = req.Main.AppointEndDate
+	}
 
 	tx, err := s.Dao.DB.Begin()
 	if err != nil {