caipin 4 anni fa
parent
commit
966c187dfa
1 ha cambiato i file con 71 aggiunte e 0 eliminazioni
  1. 71 0
      services/group_service.go

+ 71 - 0
services/group_service.go

@@ -0,0 +1,71 @@
+/*
+ * @description: 管理员组
+ * @Author: CP
+ * @Date: 2021-06-01 14:56:44
+ * @FilePath: \construction_management\services\group_service.go
+ */
+package services
+
+import (
+	"strconv"
+
+	"go.mod/comm"
+	"go.mod/conf"
+	"go.mod/dao"
+	"go.mod/datasource"
+	"go.mod/models"
+	"go.mod/web/viewmodels"
+)
+
+//定义管理员Service接口
+type GroupService interface {
+	GetAll() (dataList []viewmodels.Group, total int64)
+	// CountAll() int64
+	// Get(id int) *viewmodels.Manager
+	// Update(data *models.CmManager, columns []string) error
+	// Create(data *models.CmManager) error
+	// Enable(id int, canLogin int) error
+}
+
+//返回service操作类
+type groupService struct {
+	dao *dao.GroupDao
+}
+
+//创建管理员service
+func NewGroupService() GroupService {
+	return &groupService{
+		dao: dao.NewGroupDao(datasource.InstanceDbMaster()),
+	}
+}
+
+//实现getall接口
+func (s *groupService) GetAll() (data []viewmodels.Group, total int64) {
+
+	datalist := make([]viewmodels.Group, 0)
+	result, total := s.dao.GetAll()
+
+	for _, item := range result {
+		projectVM := makeGroupVM(&item)
+		datalist = append(datalist, projectVM)
+	}
+
+	return datalist, total
+}
+
+// 构造视图层models
+func makeGroupVM(projectCM *models.CmGroup) viewmodels.Group {
+	modelsVM := viewmodels.Group{}
+	id, _ := comm.AesEncrypt(strconv.Itoa(projectCM.Id), conf.SignSecret)
+	// userId, _ := comm.AesEncrypt(strconv.Itoa(projectCM.UserId), conf.SignSecret)
+
+	modelsVM.Id = id
+	modelsVM.Name = projectCM.Name
+	modelsVM.Remark = projectCM.Remark
+
+	if !projectCM.CreateTime.IsZero() {
+		modelsVM.CreateTime = projectCM.CreateTime.Format(conf.SysTimeform)
+	}
+
+	return modelsVM
+}