Browse Source

设备预约资格、优先权,会议室预约按天预约方法

jianglw 4 years ago
parent
commit
8e736fa439

+ 13 - 4
config/config.toml

@@ -1,10 +1,10 @@
 # 应用系统设置
 [setting]
 #    logpath = "/tmp/log/admin"
-    bind-addr = "192.168.0.63:18090"
+    bind-addr = "192.168.0.37:18090"
 #    advertise-addr = "81.68.138.114:19922"
     need-advertise-addr = false
-    srv-name = "dashoo.lims.adapter-0.1-guodj"
+    srv-name = "dashoo.lims.adapter-0.1-jlw"
     env = "dev"
 
 # 预约相关
@@ -12,6 +12,8 @@
     time_split = 30
     begin_at = "00:00:00"
     end_at = "24:00:00"
+    begin = "08:00:00"
+    end = "20:00:00"
     weekday = "1,2,3,4,5,6,7"
 
 [nsq]
@@ -32,12 +34,19 @@
         link = "mysql:root:Dashoo#190801@ali@tcp(192.168.0.252:3306)/lims_dev"
     [[database.CU7zm9WhZm]]
         Debug = true
-        link = "mysql:root:Dashoo#190801@ali@tcp(192.168.0.252:3306)/lims_dev"
+        link = "mysql:root:Dashoo#190801@ali@tcp(192.168.0.252:3306)/lims_test"
     [[database.EmGVD5szuT]]
         Debug = true
-        link = "mysql:root:Dashoo#190801@ali@tcp(192.168.0.252:3306)/lims_test"
+        link = "mysql:root:Dashoo#190801@ali@tcp(192.168.0.252:3306)/lims_dev"
 
 [micro_srv]
     auth = "dashoo.labsop.auth-2.1"
 #    admin = "dashoo.labsop.admin-2.1"
     admin ="dashoo.labsop.admin-2.1,192.168.0.252:19932"
+
+[gfcli]
+    [[gfcli.gen.dao]]
+        link   = "mysql:root:Dashoo#190801@ali@tcp(192.168.0.252:3306)/lims_dev"
+        group  = "default"
+        prefix = ""
+        tables = "base_itemdetails"

+ 3 - 0
dao/internal/base_equipment_qualification.go

@@ -28,6 +28,7 @@ type baseEquipmentQualificationColumns struct {
 	Id             string // 主键
 	EquipmentId    string // 设备Id
 	Qualification  string // 预约资格:1普通资格,2资深资格
+	UserId		   string // 用户Id
 	AuthorizeTime  string // 授权时间
 	CreateOn       string //
 	CreateUserId   string //
@@ -47,6 +48,7 @@ var (
 			Id:             "Id",
 			EquipmentId:    "EquipmentId",
 			Qualification:  "Qualification",
+			UserId:			"UserId",
 			AuthorizeTime:  "AuthorizeTime",
 			CreateOn:       "CreateOn",
 			CreateUserId:   "CreateUserId",
@@ -68,6 +70,7 @@ func NewBaseEquipmentQualificationDao(tenant string) BaseEquipmentQualificationD
 			Id:             "Id",
 			EquipmentId:    "EquipmentId",
 			Qualification:  "Qualification",
+			UserId:			"UserId",
 			AuthorizeTime:  "AuthorizeTime",
 			CreateOn:       "CreateOn",
 			CreateUserId:   "CreateUserId",

+ 266 - 18
handler/equipment.go

@@ -3,29 +3,277 @@ package handler
 import (
 	"context"
 	"dashoo.cn/common_definition/comm_def"
+	"dashoo.cn/micro_libary/micro_srv"
+	"dashoo.cn/micro_libary/myerrors"
+	"errors"
+	"github.com/gogf/gf/frame/g"
 	"lims_adapter/model"
+	"lims_adapter/service/equipment"
+	"strconv"
 )
 
 // 设备
 type Equipment struct{}
 
-// AppointmentList 设备预约资格列表查询
-
-func (e *Equipment) AppointmentList(ctx context.Context, req *model.ListReq, rsp *comm_def.CommonMsg) error {
-	//tenant, err := micro_srv.GetTenant(ctx)
-	//if err != nil {
-	//	return err
-	//}
-	//g.Log().Info("Received Equipment.AppointmentList request @ " + tenant)
-	//if req.Size == 0 {
-	//	req.Size = DefaultPageNum
-	//}
-	//if req.Current < 0 {
-	//	req.Current = DefaultPageCurrent
-	//}
-	//list, total, err := equipment.NewSrv(tenant)
-	//rsp.Code = code
-	//rsp.Msg = msg
-	//rsp.Data = g.Map{"total": total, "list": list}
+// AppointmentQualificationList 设备预约资格列表查询
+func (e *Equipment) AppointmentQualificationList(ctx context.Context, req *model.QualificationListReq, rsp *comm_def.CommonMsg) error {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return err
+	}
+	g.Log().Info("Received Equipment.AppointmentQualificationList request @ " + tenant)
+	if req.Size == 0 {
+		req.Size = DefaultPageNum
+	}
+	if req.Current < 0 {
+		req.Current = DefaultPageCurrent
+	}
+	list, total, err := equipment.NewSrv(tenant).AppointmentQualificationList(req)
+	_, err, code, msg := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	rsp.Code = code
+	rsp.Msg = msg
+	rsp.Data = g.Map{"total": total, "tableData": list}
+	return nil
+}
+
+// AppointmentQualificationList 优先预约权资格列表查询
+func (e *Equipment) AdvanceList(ctx context.Context, req *model.QualificationListReq, rsp *comm_def.CommonMsg) error {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return err
+	}
+	g.Log().Info("Received Equipment.AdvanceList request @ " + tenant)
+	if req.Size == 0 {
+		req.Size = DefaultPageNum
+	}
+	if req.Current < 0 {
+		req.Current = DefaultPageCurrent
+	}
+	list, total, err := equipment.NewSrv(tenant).AdvanceList(req)
+	_, err, code, msg := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	rsp.Code = code
+	rsp.Msg = msg
+	rsp.Data = g.Map{"total": total, "tableData": list}
+	return nil
+}
+
+// AddOrUpdateQualification 新增、修改预约资格名单
+func (e *Equipment) AddOrUpdateQualification(ctx context.Context, req *model.AddOrUpdateQualification, rsp *comm_def.CommonMsg) error {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return err
+	}
+	info, err := micro_srv.GetUserInfo(ctx)
+	if err != nil {
+		return err
+	}
+	g.Log().Info("Received Equipment.AddOrUpdateQualification request @ " + tenant)
+	if strconv.Itoa(req.InstrumentId) == "" {
+		return errors.New("设备Id为空!")
+	}
+	if len(req.Ids) == 0 {
+		return errors.New("选择授权的用户Id为空")
+	}
+	err = equipment.NewSrv(tenant).AddOrUpdateQualification(req, info)
+	_, err, code, msg := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	rsp.Code = code
+	rsp.Msg = msg
+	return nil
+}
+
+// DeleteQualification 删除预约资格
+func(e *Equipment) DeleteQualification(ctx context.Context, req *model.IdReq, rsp *comm_def.CommonMsg) error {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return err
+	}
+	info, err := micro_srv.GetUserInfo(ctx)
+	if err != nil {
+		return err
+	}
+	g.Log().Info("Received Equipment.DeleteQualification request @ " + tenant)
+	if err != nil {
+		return err
+	}
+	if strconv.Itoa(req.UserId) == "" && strconv.Itoa(req.EquipmentId) == "" {
+		return errors.New("未传入删除资格参数不完整,请核对后再试")
+	}
+	err = equipment.NewSrv(tenant).DeleteQualification(req, info)
+	_, err, code, msg := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	rsp.Code = code
+	rsp.Msg = msg
+	return nil
+}
+
+// DeleteAdvance 删除优先预约资格
+func(e *Equipment) DeleteAdvance(ctx context.Context, req *model.IdReq, rsp *comm_def.CommonMsg) error {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return err
+	}
+	g.Log().Info("Received Equipment.DeleteAdvance request @ " + tenant)
+	if strconv.Itoa(req.UserId) == "" && strconv.Itoa(req.EquipmentId) == "" {
+		return errors.New("未传入删除资格参数不完整,请核对后再试")
+	}
+	err = equipment.NewSrv(tenant).DeleteAdvance(req)
+	_, err, code, msg := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	rsp.Code = code
+	rsp.Msg = msg
+	return nil
+}
+
+// SearchAdvanceTime 查看设备优先预约时间段
+func(e *Equipment) SearchAdvanceTime(ctx context.Context, req *model.QualificationListReq, rsp *comm_def.CommonMsg) error {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return err
+	}
+	g.Log().Info("Received Equipment.SearchAdvanceTime request @ " + tenant)
+	if req.Size == 0 {
+		req.Size = DefaultPageNum
+	}
+	if req.Current < 0 {
+		req.Current = DefaultPageCurrent
+	}
+	equipmentId := req.InstrumentId
+	if strconv.Itoa(equipmentId) == "" {
+		return errors.New("设备Id为空,请检查传入参数")
+	}
+	list, total, err := equipment.NewSrv(tenant).SearchAdvanceTime(req)
+	_, err, code, msg := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	rsp.Code = code
+	rsp.Msg = msg
+	rsp.Data = g.Map{"total": total, "tableData": list}
+	return nil
+}
+
+// AddAdvanceTime 添加设备优先预约时间段
+func(e *Equipment) AddAdvanceTime(ctx context.Context, req *model.AdvanceTimeReq, rsp *comm_def.CommonMsg) error {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return err
+	}
+	info, err := micro_srv.GetUserInfo(ctx)
+	if err != nil {
+		return err
+	}
+	g.Log().Info("Received Equipment.AddAdvanceTime request @ " + tenant)
+	equipmentId := req.EquipmentId
+	if strconv.Itoa(equipmentId) == "" {
+		return errors.New("设备Id为空,请检查传入参数")
+	}
+	err = equipment.NewSrv(tenant).AddAdvanceTime(req, info)
+	_, err, code, _ := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	rsp.Code = code
+	rsp.Msg = "添加优先预约时间段成功"
+	return nil
+}
+
+// DeleteAdvanceTime 删除设备预约时间段
+func(e *Equipment) DeleteAdvanceTime(ctx context.Context, req *model.IdReq, rsp *comm_def.CommonMsg) error {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return err
+	}
+	g.Log().Info("Received Equipment.DeleteAdvanceTime request @ " + tenant)
+	if strconv.Itoa(req.Id) == "" {
+		return errors.New("未传入删除id")
+	}
+	err = equipment.NewSrv(tenant).DeleteAdvanceTime(req.Id)
+	_, err, code, _ := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	rsp.Code = code
+	return nil
+}
+
+// AppointmentTime 设备预约时间段
+func(e *Equipment) AppointmentTime(ctx context.Context, req *model.IdReq, rsp *comm_def.CommonMsg) error {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return err
+	}
+	g.Log().Info("Received Equipment.AppointmentTime request @ " + tenant)
+	equipmentId := req.EquipmentId
+	if strconv.Itoa(equipmentId) == "" {
+		return errors.New("设备Id为空,请检查传入参数")
+	}
+	if strconv.Itoa(req.UserId) == "" {
+		return errors.New("人员Id为空,请检查传入参数")
+	}
+	equipment.NewSrv(tenant).AppointmentTime(req)
+	return nil
+}
+
+// SearchNoAppointment 查看不能预约时间段信息
+func (e *Equipment) SearchNoAppointment(ctx context.Context, req *model.IdReq, rsp *comm_def.CommonMsg) error {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return err
+	}
+	info, err := micro_srv.GetUserInfo(ctx)
+	if err != nil {
+		return err
+	}
+	g.Log().Info("Received Equipment.SearchNoAppointment request @ " + tenant)
+	equipmentId := req.EquipmentId
+	if strconv.Itoa(equipmentId) == "" {
+		return errors.New("设备Id为空,请检查传入参数")
+	}
+	if req.Date == "" {
+		return errors.New("日期为空,请检查传入参数")
+	}
+	appointment, err := equipment.NewSrv(tenant).SearchNoAppointment(req, info)
+	_, err, code, _ := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	rsp.Code = code
+	rsp.Data = appointment
+	return nil
+}
+
+// ChangeInstrStauts 修改设备所属
+func(e *Equipment) ChangeBelongs(ctx context.Context, req *model.IdReq, rsp *comm_def.CommonMsg) error {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return err
+	}
+	g.Log().Info("Received Equipment.ChangeBelongs request @ " + tenant)
+	equipmentId := req.EquipmentId
+	if strconv.Itoa(equipmentId) == "" {
+		return errors.New("设备Id为空,请检查传入参数")
+	}
+	if req.Belongs == "" {
+		return errors.New("设备所属为空")
+	}
+	err = equipment.NewSrv(tenant).ChangeBelongs(req)
+	_, err, code, _ := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	rsp.Code = code
 	return nil
 }

+ 22 - 0
handler/reservation.go

@@ -118,6 +118,28 @@ func (r *Reservation) OverviewList(ctx context.Context, req *model.OverviewReq,
 	return nil
 }
 
+// OverviewListByDay 预约概况
+func (r *Reservation) OverviewListByDay(ctx context.Context, req *model.OverviewReq, rsp *comm_def.CommonMsg) error {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return err
+	}
+	g.Log().Info("Received Reservation.OverviewListByDay request @ " + tenant)
+	// 校验
+	if req.Date.String() == "" {
+		return NoParamsErr
+	}
+	data, err := reservation.NewSrv(tenant).OverviewListByDay(ctx, *req)
+	_, err, code, msg := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	rsp.Data = data
+	rsp.Code = code
+	rsp.Msg = msg
+	return nil
+}
+
 // ReserveInfo 预约信息
 func (r *Reservation) ReserveInfo(ctx context.Context, req *model.ReserveReq, rsp *comm_def.CommonMsg) error {
 	tenant, err := micro_srv.GetTenant(ctx)

+ 52 - 0
handler/system.go

@@ -0,0 +1,52 @@
+package handler
+
+import (
+	"context"
+	"dashoo.cn/common_definition/comm_def"
+	"dashoo.cn/micro_libary/micro_srv"
+	"dashoo.cn/micro_libary/myerrors"
+	"errors"
+	"github.com/gogf/gf/frame/g"
+	"lims_adapter/model"
+	"lims_adapter/service/system"
+)
+
+type System struct{}
+
+// DictInfo 获取字典数据
+func (s *System) DictInfo(ctx context.Context, req *model.DictReq, rsp *comm_def.CommonMsg) error {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return err
+	}
+	g.Log().Info("Received DictInfo request @ " + tenant)
+	if req.DictCode == "" {
+		return errors.New("字典类型不能为空")
+	}
+	dictInfo, err := system.NewSrv(tenant).DictInfo(req)
+	_, err, code, _ := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	rsp.Code = code
+	rsp.Data = dictInfo
+	return nil
+}
+
+// UserList 获取用户信息
+func (s *System) UserList(ctx context.Context, req *model.UserInfoReq, rsp *comm_def.CommonMsg) error {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return err
+	}
+	g.Log().Info("Received UserList request @ " + tenant)
+	userList, err := system.NewSrv(tenant).UserList(req)
+	_, err, code, _ := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	rsp.Code = code
+	rsp.Msg = ""
+	rsp.Data = userList
+	return nil
+}

+ 2 - 0
main.go

@@ -19,6 +19,8 @@ func main() {
 	// 注册服务对象
 	s.RegisterName("Meeting", new(handler.Meeting), "")
 	s.RegisterName("Reservation", new(handler.Reservation), "")
+	s.RegisterName("Equipment", new(handler.Equipment), "")
+	s.RegisterName("System", new(handler.System), "")
 
 	// 注册auth处理
 	s.AuthFunc = handleAuth

+ 25 - 0
model/base_equipment_qualification.go

@@ -12,3 +12,28 @@ import (
 type BaseEquipmentQualification internal.BaseEquipmentQualification
 
 // Fill with you ideas below.
+
+// 添加、修改预约资格
+type AddOrUpdateQualification struct {
+	Ids []int `json:"ids"` // 用户Id列表
+	InstrumentId int `json:"instrument_id"` // 设备Id
+	QualificationType string `json:"qualification_type"` // 预约资格:"normal"普通资格,"senior"资深资格
+}
+
+// 预约资格分页查询
+type QualificationListReq struct {
+	Current 	 int 	`json:"current"`
+	Size 		 int 	`json:"size"`
+	Enabled 	 int 	`json:"enabled"` // 用户是否启用 0 禁用 1 启用
+	InstrumentId int 	`json:"instrument_id"` // 设备Id
+	Type 		 int	`json:"type"'` // 1、预约资格,2、优先预约权
+}
+
+// 删除预约资格
+type IdReq struct {
+	Id          int  `json:"id"`
+	UserId  	int  `json:"user_id"`
+	EquipmentId int `json:"equipment_id"`
+	Date 		string `json:"date"`
+	Belongs   	string		`json:"belongs"`
+}

+ 2 - 1
model/internal/base_equipment_qualification.go

@@ -12,7 +12,8 @@ import (
 type BaseEquipmentQualification struct {
 	Id             int         `orm:"Id,primary"     json:"id"`             // 主键
 	EquipmentId    int         `orm:"EquipmentId"    json:"equipmentId"`    // 设备Id
-	Qualification  string      `orm:"Qualification"  json:"qualification"`  // 预约资格:1普通资格,2资深资格
+	UserId		   int		   `orm:"EquipmentIdUserId" json:"user_id"`     // 用户Id
+	Qualification  string      `orm:"Qualification"  json:"qualification"`  // 预约资格:1普通资格,2资深资格, 3优先使用权
 	AuthorizeTime  *gtime.Time `orm:"AuthorizeTime"  json:"authorizeTime"`  // 授权时间
 	CreateOn       *gtime.Time `orm:"CreateOn"       json:"createOn"`       //
 	CreateUserId   string      `orm:"CreateUserId"   json:"createUserId"`   //

+ 2 - 0
model/meeting_reservation.go

@@ -85,6 +85,8 @@ type ReserveReq struct {
 
 // ReservationList 预约详情
 type ReservationList struct {
+	EntityId      int    `json:"entity_id"`		 // 会议室ID
+	Title         string `json:"title"`     		 // 会议名称
 	ReservationId int    `json:"reservation_id"` // 预约ID
 	Day           int    `json:"day"`            // 日期
 	Dept          string `json:"dept"`           // 部门

+ 300 - 1
service/equipment/equipment.go

@@ -1,6 +1,18 @@
 package equipment
 
-import "lims_adapter/dao"
+import (
+	"dashoo.cn/micro_libary/request"
+	"errors"
+	"fmt"
+	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/os/gtime"
+	"github.com/gogf/gf/util/gconv"
+	"lims_adapter/dao"
+	"lims_adapter/model"
+	"strconv"
+	"strings"
+	"time"
+)
 
 // Service 设备
 type Service struct {
@@ -12,3 +24,290 @@ type Service struct {
 func NewSrv(tenant string) Service {
 	return Service{Dao: dao.NewBaseEquipmentQualificationDao(tenant), Tenant: tenant}
 }
+
+// AppointmentQualificationList 预约资格分页查询
+func (s Service) AppointmentQualificationList(req *model.QualificationListReq) ([]model.UserQualification, int, error) {
+	var current = req.Current
+	var size = req.Size
+	var enabled = req.Enabled
+	var instrumentId = req.InstrumentId
+	var reqType = req.Type
+	entity := s.Dao.DB.Model("base_user a")
+	var userInfo []model.UserQualification
+	where := "a.Enabled = " + strconv.Itoa(enabled) + " and b.EquipmentId = " + strconv.Itoa(instrumentId)
+
+	if reqType == 1 { // 预约资格查询条件
+		where += " and (b.Qualification = 1 or b.Qualification = 2)"
+	} else if reqType == 2 { // 优先预约权查询条件
+		where += " and b.Qualification = 3"
+	}
+	entity.LeftJoin("base_equipment_qualification b", "a.id = b.UserId").
+		Where(where)
+	count, _:= entity.Count()
+	err := entity.Fields("a.Id, a.UserName, a.RealName, a.Mobile, b.Qualification, b.AuthorizeTime").
+		Page(current, size).Scan(&userInfo)
+	if err != nil {
+		return nil, 0, err
+	}
+	return userInfo, count, nil
+}
+
+// AdvanceList 优先预约权资格列表查询
+func (s Service) AdvanceList(req *model.QualificationListReq) ([]model.UserQualification, int, error) {
+	var current = req.Current
+	var size = req.Size
+	var enabled = req.Enabled
+	var instrumentId = req.InstrumentId
+	entity := s.Dao.DB.Model("base_user a")
+	var userInfo []model.UserQualification
+	entity.LeftJoin("base_equipment_qualification b", "a.id = b.UserId").
+		Where("a.Enabled = " + strconv.Itoa(enabled) + " and b.EquipmentId = " + strconv.Itoa(instrumentId))
+	count, _ := entity.Count()
+	err := entity.Fields("a.Id, a.UserName, a.RealName, a.Mobile, b.AuthorizeTime").
+		Page(current, size).Scan(&userInfo)
+	if err != nil {
+		return nil, 0, err
+	}
+	return userInfo, count, nil
+}
+
+// AddOrUpdateQualification 新增、修改预约资格名单;新增优先预约权名单
+func (s Service) AddOrUpdateQualification(req *model.AddOrUpdateQualification, userInfo request.UserInfo) (err error) {
+	entity := s.Dao.M
+	var instrumentId = req.InstrumentId
+	var ids = req.Ids
+	var qualification = 1
+	if req.QualificationType == "normal" {
+		qualification = 1
+	} else if req.QualificationType == "senior" {
+		qualification = 2
+	} else if req.QualificationType == "advance" {
+		qualification = 3
+	}
+	//if qualification == 1 || qualification == 2 { // 预约资格
+	for _, v := range ids {
+		where := "EquipmentId = " + strconv.Itoa(instrumentId) + " and UserId = " +
+			strconv.Itoa(v)
+		if qualification == 1 || qualification == 2 { // 预约资格
+			where += " and Qualification != 3"
+		} else if qualification ==3 { // 优先预约权
+			// 先判断是否有预约资格,没有则不更新操作
+			count, _ := s.Dao.DB.Model("base_equipment_qualification").Where("EquipmentId = " +
+				strconv.Itoa(instrumentId) + " and Qualification != 0" + " and UserId = " +
+				strconv.Itoa(v)).Count()
+			if count == 0 {
+
+				continue
+			}
+			where += " and Qualification = 3"
+		}
+			var qualificationInfo model.BaseEquipmentQualification
+		entity.Where(where).Scan(&qualificationInfo)
+		entity.Data(g.Map{"Id": qualificationInfo.Id,"EquipmentId": instrumentId, "UserId": v, "Qualification": qualification, "CreateOn": gtime.Now(),
+			"AuthorizeTime": gtime.Now(), "CreateUserId": userInfo.Id, "CreateBy": userInfo.RealName}).Save()
+
+	}
+	//} else if qualification ==3 { // 优先预约权
+	//	for _, v := range ids {
+	//		var qualificationInfo model.BaseEquipmentQualification
+	//		entity.Where("EquipmentId = " + strconv.Itoa(instrumentId) + " and UserId = " +
+	//			strconv.Itoa(v) ).Scan(&qualificationInfo)
+	//		entity.Data(g.Map{"Id": qualificationInfo.Id,"EquipmentId": instrumentId, "UserId": v, "CreateOn": gtime.Now(),
+	//			"AuthorizeTime": gtime.Now(), "CreateUserId": userInfo.Id, "CreateBy": userInfo.RealName}).Save()
+	//	}
+	//}
+	return err
+}
+
+// DeleteQualification 删除预约资格
+func (s Service) DeleteQualification(req *model.IdReq, info request.UserInfo) error {
+	_, err := s.Dao.M.Update(g.Map{"Qualification": 0, "ModifiedOn": gtime.Now(),
+		"ModifiedUserId": info.Id, "ModifiedBy": info.RealName}, "UserId = " + strconv.Itoa(req.UserId) +
+		" and EquipmentId = " + strconv.Itoa(req.EquipmentId) + " and Qualification != 3")
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// DeleteAdvance 删除优先预约权人员
+func (s Service) DeleteAdvance(req *model.IdReq) error {
+	_, err := s.Dao.M.Delete("UserId = " + strconv.Itoa(req.UserId) +
+		" and EquipmentId = " + strconv.Itoa(req.EquipmentId) + " and Qualification = 3")
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// SearchAdvanceTime 查看设备优先预约时间段
+func (s Service) SearchAdvanceTime(req *model.QualificationListReq) (advanceTime []model.BaseEquipmentAdvanceTime, count int, err error) {
+	entity := s.Dao.DB.Model("base_equipment_advance_time")
+	err = entity.Where("EquipmentId = " + strconv.Itoa(req.InstrumentId)).Scan(&advanceTime)
+	count, _ = entity.CountColumn("1")
+	err = entity.Fields("Week, StartTime,EndTime").Order("Week").Page(req.Current, req.Size).Scan(&advanceTime)
+	if err != nil {
+		return advanceTime, count, err
+	}
+	return advanceTime, count, nil
+}
+
+// AddAdvanceTime 添加设备优先预约时间段
+func (s Service) AddAdvanceTime(req *model.AdvanceTimeReq, info request.UserInfo) error {
+	//for _, v := range domains {
+	//	count, err := s.Dao.DB.Model("base_equipment_advance_time").Where("Week = '" + v.Week +
+	//		"' and StartTime = '" + v.StartTime + "' and EndTime = '" + v.EndTime + "'").Count()
+	//	if err != nil{
+	//		return err
+	//	}
+	//	if count == 0 {
+	//		week, _ := strconv.Atoi(v.Week)
+	//		saveEntity := model.BaseEquipmentAdvanceTime{
+	//			EquipmentId: equipmentId,
+	//			Week: week,
+	//			StartTime: v.StartTime,
+	//			EndTime: v.EndTime,
+	//			CreateOn: gtime.Now(),
+	//			CreateUserId: gconv.Int(info.Id),
+	//			CreateBy: info.RealName,
+	//		}
+	//		s.Dao.DB.Model("base_equipment_advance_time").Insert(saveEntity)
+	//	}
+	//}
+	count, err := s.Dao.DB.Model("base_equipment_advance_time").Where("EquipmentId = " +
+		strconv.Itoa(req.EquipmentId) + " and Week = " + req.Week +
+		" and StartTime = '" + req.StartTime + "' and EndTime = '" + req.EndTime + "'").Count()
+	if err != nil{
+		return err
+	}
+	if count > 0 {
+		return errors.New("该时间段已存在,请重新输入!")
+	}
+	week, _ := strconv.Atoi(req.Week)
+	saveEntity := model.BaseEquipmentAdvanceTime{
+		EquipmentId: req.EquipmentId,
+		Week: week,
+		StartTime: req.StartTime,
+		EndTime: req.EndTime,
+		CreateOn: gtime.Now(),
+		CreateUserId: gconv.Int(info.Id),
+		CreateBy: info.RealName,
+	}
+	_, err = s.Dao.DB.Model("base_equipment_advance_time").Insert(saveEntity)
+	if err != nil{
+		return err
+	}
+	return nil
+}
+
+// DeleteAdvanceTime 删除设备预约时间段
+func (s Service) DeleteAdvanceTime(id int) error {
+	_, err := s.Dao.DB.Model("base_equipment_advance_time").Delete("Id = " + strconv.Itoa(id))
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// AppointmentTime 设备预约时间段
+func (s Service) AppointmentTime(req *model.IdReq) error{
+	// 先查该人员的预约资格、优先使用权
+	var qualificationInfo []model.BaseEquipmentQualification
+	s.Dao.DB.Model("base_equipment_qualification").Where("EquipmentId = " +
+		strconv.Itoa(req.EquipmentId)).Order("Qualification").Scan(&qualificationInfo)
+	// 如果是普通预约资格,筛选出周末时间段
+	if qualificationInfo[0].Qualification == "1" {
+		// TODO 时间获取
+	}
+	// 如果有预约资格但没有优先使用权,查询优先使用权时间段
+	if len(qualificationInfo) ==2 && qualificationInfo[1].Qualification == "3"{
+		var appointmentInfo []model.BaseEquipmentAdvanceTime
+		s.Dao.DB.Model("base_equipment_advance_time").Where("EquipmentId = " +
+			strconv.Itoa(req.EquipmentId) + " and UserId").Scan(&appointmentInfo)
+	}
+	return nil
+}
+
+// SearchNoAppointment 查看不能预约时间段信息
+func (s Service) SearchNoAppointment(req *model.IdReq, info request.UserInfo) ([]model.NoReservationInfo, error) {
+	// 普通资格限制周末时间
+	var qualificationInfo []model.BaseEquipmentQualification
+	var noAppointmentInfos []model.NoReservationInfo
+	s.Dao.DB.Model("base_equipment_qualification").Where("EquipmentId = " +
+		strconv.Itoa(req.EquipmentId) + " and UserId = " +
+		strconv.Itoa(gconv.Int(info.Id))).Order("Qualification").Scan(&qualificationInfo)
+	if len(qualificationInfo) >= 1 && qualificationInfo[0].Qualification == "1" { // 只有普通预约资格,限制周末预约时间段
+		// 查询设备可预约时间段
+		var equipmentInfo model.Instrument
+		s.Dao.DB.Model("instrument").Fields("BeginAt, EndAt").
+			Where("Id = " + strconv.Itoa(req.EquipmentId)).Scan(&equipmentInfo)
+		startTime := equipmentInfo.BeginAt
+		endTime := equipmentInfo.EndAt
+		// 设备当天预约时间总长度h
+		timeLong := endTime.Sub(startTime).Hours()
+		saturdayTime := noReservationInfo(startTime, timeLong, req.Date, 6)
+		sundayTime := noReservationInfo(startTime, timeLong, req.Date, 7)
+		noAppointmentInfos = append(saturdayTime, sundayTime...)
+	}
+	if len(qualificationInfo) == 1 && qualificationInfo[0].Qualification != "3" { // 没有优先预约权,限制优先预约时间段
+		var advanceTimeList []model.BaseEquipmentAdvanceTime
+		s.Dao.DB.Model("base_equipment_advance_time").
+			Where("EquipmentId = " + strconv.Itoa(req.EquipmentId)).Scan(&advanceTimeList)
+		for _, v := range advanceTimeList {
+			// TODO 遍历获取不能预约时间段
+			startTime, _ := gtime.StrToTime(strings.Trim(v.StartTime, " "), "H:i")
+			endTime, _ := gtime.StrToTime(strings.Trim(v.EndTime, " "), "H:i")
+			timeLong := endTime.Sub(startTime).Hours()
+			saturdayTime := noReservationInfo(startTime, timeLong, req.Date, v.Week)
+			noAppointmentInfos = append(noAppointmentInfos, saturdayTime...)
+		}
+	}
+	return noAppointmentInfos, nil
+}
+
+// ChangeInstrStauts 修改设备所属
+func (s Service) ChangeBelongs(req *model.IdReq) error{
+	_, err := s.Dao.DB.Model("Instrument").
+		Update("Belongs = " + req.Belongs, "Id = "+strconv.Itoa(req.EquipmentId))
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// noReservationInfo 不可预约时间段处理 startTime开始时间 timeLong 时间间隔 Date 前端传入日期 week 星期几
+func noReservationInfo(startTime *gtime.Time, timeLong float64, Date string, week int) (noAppointmentInfo []model.NoReservationInfo) {
+	date, _ := gtime.StrToTime(Date, "Y-m-d")
+	// 获取当前星期对应的日期
+	day := GetDate(date, week)
+	grids := int(timeLong * 2)
+	for i := 0; i < grids; i++ {
+		// 开始时间
+		start_time := startTime.Add(time.Duration(i) * 30 * time.Minute)
+		//fmt.Println("day:", day, "week:", week, "start_time", fmt.Sprintf("%02d", start_time.Hour()) + ":"+fmt.Sprintf("%02d", start_time.Minute()), "status:", status)
+		noAppointmentInfo = append(noAppointmentInfo, model.NoReservationInfo{
+			Day : day,
+			Week : week,
+			StartTime : fmt.Sprintf("%02d", start_time.Hour()) + ":"+fmt.Sprintf("%02d", start_time.Minute()),
+			Status : 3,
+		})
+	}
+	return noAppointmentInfo
+}
+
+// 获取当前星期对应的日期
+func GetDate(Date *gtime.Time, week int) int{
+	weekday := Date.Weekday().String()
+	var targetDay  *gtime.Time
+	switch weekday {
+		case "Monday": 		targetDay = Date.AddDate(0, 0, week - 1)
+		case "Tuesday":		targetDay = Date.AddDate(0, 0, week - 2)
+		case "Wednesday": 	targetDay = Date.AddDate(0, 0, week - 3)
+		case "Thursday": 	targetDay = Date.AddDate(0, 0, week - 4)
+		case "Friday": 		targetDay = Date.AddDate(0, 0, week - 5)
+		case "Saturday": 	targetDay = Date.AddDate(0, 0, week - 6)
+		case "Sunday": 		targetDay = Date.AddDate(0, 0, week - 7)
+	}
+	_, _, day := targetDay.Date()
+	return day
+}

+ 1 - 1
service/meeting/meeting.go

@@ -52,7 +52,7 @@ func (m Service) List(req model.ListReq) ([]model.Meeting, int, error) {
 	if req.Value != "" {
 		entityModel = entityModel.Order(common.Snake2Orm(model.Meeting{}, req.Value), req.Type)
 	} else {
-		entityModel = entityModel.Order(service.DefaultSortField, service.DefaultSortType, ",", m.Dao.Columns.CreatedAt, "DESC")
+		entityModel = entityModel.Order(service.DefaultSortField)
 	}
 	res, err := entityModel.Page(req.Current, req.Size).FindAll()
 	if err != nil {

+ 82 - 3
service/reservation/reservation.go

@@ -134,7 +134,7 @@ func (s Service) Cancel(userInfo request.UserInfo, id int) error {
 
 // OverviewList 预约概况
 func (s Service) OverviewList(req model.OverviewReq) (g.Map, error) {
-	dates := s.getCurrentWeekDay(req.Date)
+	dates := getCurrentWeekDay(req.Date)
 	meetingList, err := meeting.NewSrv(s.Tenant).ShortList()
 	if err != nil {
 		return nil, err
@@ -151,13 +151,36 @@ func (s Service) OverviewList(req model.OverviewReq) (g.Map, error) {
 
 }
 
+// OverviewListByDay 按天预约概况
+func (s Service) OverviewListByDay(ctx context.Context, req model.OverviewReq) (g.Map, error) {
+	beginAt := g.Cfg().GetString("reservation.begin")
+	endAt := g.Cfg().GetString("reservation.end")
+	period := s.getCurrentPeriod(beginAt, endAt)
+	dates := getCurrentWeekDay(req.Date)
+	meetingList, err := meeting.NewSrv(s.Tenant).ShortList()
+	if err != nil {
+		return nil, err
+	}
+	reservationList, err := s.getCurrentDayReservation(ctx,meetingList, req.Date)
+	if err != nil {
+		return nil, err
+	}
+	return g.Map{
+		"period":      period,
+		"dates":       dates,
+		"meeting":     meetingList,
+		"reservation": reservationList,
+	}, nil
+
+}
+
 // ReserveInfo 预约信息
 func (s Service) ReserveInfo(ctx context.Context, req model.ReserveReq) (g.Map, error) {
 	// 常规信息
 	beginAt := g.Cfg().GetString("reservation.begin_at")
 	endAt := g.Cfg().GetString("reservation.end_at")
 	period := s.getCurrentPeriod(beginAt, endAt)
-	dates := s.getCurrentWeekDay(req.Date)
+	dates := getCurrentWeekDay(req.Date)
 	weekday := g.Cfg().GetString("reservation.weekday")
 	// 预约信息
 	list, err := s.getCurrentWeekReservation(ctx, req)
@@ -283,7 +306,7 @@ func (s Service) check(req model.ReservationReq) error {
 }
 
 // getCurrentWeekDay 返回当前日期的周信息
-func (s Service) getCurrentWeekDay(current *gtime.Time) []model.CurrentDate {
+func getCurrentWeekDay(current *gtime.Time) []model.CurrentDate {
 	startOfWeek := common.GetCNStartOfWeek(current)
 	dates := make([]model.CurrentDate, 0)
 	for i := 0; i <= 6; i++ {
@@ -404,3 +427,59 @@ func (s Service) getCurrentWeekReservation(ctx context.Context, req model.Reserv
 	}
 	return resultList, nil
 }
+
+// getCurrentWeekReservation 返回本周预约信息
+func (s Service) getCurrentDayReservation(ctx context.Context,meetingList []model.ShortMeeting, reqDate *gtime.Time) ([]model.ReservationList, error) {
+	// 获取符合条件的预约信息
+	resultList := make([]model.ReservationList, 0)
+	for _, value := range meetingList {
+		list, err := s.Dao.Where(s.Dao.Columns.EntityId, value.Id).
+			Where(s.Dao.Columns.Status, 1).
+			Where(s.Dao.Columns.StartTime+">=", reqDate).
+			Where(s.Dao.Columns.EndTime+"<=", reqDate.AddDate(0, 0, 1)).
+			FindAll()
+		if err != nil {
+			return nil, err
+		}
+		if len(list) == 0 {
+			continue
+		}
+		uIds := make([]int64, 0)
+		uMap := make(map[int]struct{})
+		for _, v := range list {
+			if _, ok := uMap[v.UserId]; !ok {
+				uIds = append(uIds, int64(v.UserId))
+				uMap[v.UserId] = struct{}{}
+			}
+		}
+		// 获取用户信息
+		userList, err := srv.GetUserList(ctx, uIds, s.Tenant)
+		usersMap := make(map[int]user_def.UserInfoList)
+		for _, v := range userList {
+			usersMap[v.Id] = v
+		}
+		for _, v := range list {
+			timeLong := v.EndTime.Sub(v.StartTime).Hours()
+			if v.SignOutTime.String() != "" && v.EndTime.Sub(v.SignOutTime) > 0 {
+				timeLong = common.GetNextTimeNode(v.SignOutTime).Sub(v.StartTime).Hours()
+			}
+			grid := timeLong * 2
+			for i := 0; i < int(grid); i++ {
+				startAt := v.StartTime.Add(time.Duration(i) * 30 * time.Minute)
+				resultList = append(resultList, model.ReservationList{
+					EntityId:      value.Id,
+					ReservationId: int(v.Id),
+					Title:         v.Title,
+					Day:           v.StartTime.Day(),
+					Dept:          usersMap[v.UserId].DepartmentName,
+					StartTime:     fmt.Sprintf("%.2v:%.2v", startAt.Hour(), startAt.Minute()),
+					Tel:           usersMap[v.UserId].Mobile,
+					Uid:           v.UserId,
+					Uname:         usersMap[v.UserId].Realname,
+					Week:          common.GetCNWeekday(v.StartTime),
+				})
+			}
+		}
+	}
+	return resultList, nil
+}

+ 63 - 0
service/system/system.go

@@ -0,0 +1,63 @@
+package system
+
+import (
+	"lims_adapter/dao"
+	"lims_adapter/model"
+	"strconv"
+)
+
+type Service struct {
+	Dao    *dao.BaseItemdetailsDao
+	Tenant string
+}
+
+// NewSrv 服务初始化
+func NewSrv(tenant string) Service {
+	return Service{Dao: dao.NewBaseItemdetailsDao(tenant), Tenant: tenant}
+}
+
+// DictInfo 获取字典数据
+func(s Service) DictInfo(req *model.DictReq) (dictInfo []model.BaseItemdetails, err error) {
+	where := "DictCode = '" + req.DictCode + "' and Enabled = 1"
+	if req.ItemName != "" {
+		where += " and ItemName = '" + req.ItemName + "'"
+	}
+	if req.ItemValue != "" {
+		where += " and ItemValue = '" + req.ItemValue + "'"
+	}
+	if req.SortCode != "" {
+		where += " and SortCode = '" + req.SortCode + "'"
+	}
+	err = s.Dao.M.Where(where).Scan(&dictInfo)
+	if err != nil {
+		return dictInfo, err
+	}
+	return dictInfo, nil
+}
+
+// UserList 获取用户信息
+func (s Service) UserList(req *model.UserInfoReq) (userInfos model.UserInfoRsp,err error) {
+	where := "Enabled = 1"
+	departmentId := strconv.Itoa(req.DepartmentId)
+	instrumentId := strconv.Itoa(req.InstrumentId)
+	current:= req.PageNun
+	size:= req.PageSize
+	count := 0
+	model := s.Dao.DB.Model("base_user a")
+	if departmentId != "" && departmentId != "0"{
+		where += " and DepartmentId = " + departmentId
+	}
+	if req.ReqType == 1 { // 预约资格
+		count, err = model.Where(where).Count()
+	}else if req.ReqType == 2 { // 优先预约权
+		where += " and Id not in(select UserId from base_equipment_qualification where EquipmentId = "+
+			instrumentId +" and Qualification in (0,3))"
+		count, err = model.Where(where).Count()
+	}
+	if err != nil {
+		return userInfos, err
+	}
+	userInfos.Total = count
+	model.Page(current, size).Scan(&userInfos.Records)
+	return userInfos, nil
+}