/*
 * @description: 项目相关数据处理
 * @Author: CP
 * @Date: 2020-09-04 14:42:27
 * @FilePath: \construction_management\services\project_message_service.go
 */
package services

import (
	"go.mod/comm"
	"go.mod/conf"
	"go.mod/dao"
	"go.mod/datasource"
	"go.mod/web/viewmodels"
)

//定义项目Service接口
type ProjectMessageService interface {
	GetAll(projectId int, accountId int) []*viewmodels.ProjectMessageVM
}

//返回service操作类
type projectMessageService struct {
	projectMessagedao *dao.ProjectMessageDao
}

//创建项目service
func NewProjectMessageService() ProjectMessageService {
	return &projectMessageService{
		projectMessagedao: dao.NewProjectMessageDao(datasource.InstanceDbMaster()),
	}
}

// 获得需要关注人
func (s *projectMessageService) GetAll(projectId int, accountId int) []*viewmodels.ProjectMessageVM {
	dataList := s.projectMessagedao.GetAll(projectId, accountId)

	projectMessageVM := make([]*viewmodels.ProjectMessageVM, 0)
	for _, item := range dataList {
		viewProjectMessage := &viewmodels.ProjectMessageVM{}
		id, _ := comm.AesEncrypt(item.Id, conf.SignSecret)
		projectId, _ := comm.AesEncrypt(item.ProjectId, conf.SignSecret)
		bidsectionId, _ := comm.AesEncrypt(item.BidsectionId, conf.SignSecret)
		accountId, _ := comm.AesEncrypt(item.AccountId, conf.SignSecret)
		dataId, _ := comm.AesEncrypt(item.DataId, conf.SignSecret)

		viewProjectMessage.Id = id
		viewProjectMessage.ProjectId = projectId
		viewProjectMessage.BidsectionId = bidsectionId
		viewProjectMessage.AccountId = accountId
		viewProjectMessage.DataType = item.DataType
		viewProjectMessage.DataId = dataId
		viewProjectMessage.Title = item.Title
		viewProjectMessage.Content = item.Content
		viewProjectMessage.CreateTime = item.CreateTime
		viewProjectMessage.BidsectionName = item.BidsectionName

		projectMessageVM = append(projectMessageVM, viewProjectMessage)
	}
	// data, err := s.permissionDao.GetPermissionWithAccountId(accountId, bidsectionId)
	return projectMessageVM
}
