domain.go 3.0 KB
package domain

import (
	"fmt"
	"strings"
)

const MaxQueryRow = 10000

// 班次
const (
	WorkOnFullDay = 1 //全天
	WorkOnDay     = 2 //白班
	WorkOnMidDay  = 4 //中班
	WorkOnNight   = 8 //夜班
)

const WorkOn = WorkOnFullDay | WorkOnDay | WorkOnMidDay | WorkOnNight

var (
	ErrorNotFound = fmt.Errorf("没有此资源")
)

// excel 编码
var (
	ExcelImportProduct = "MANUFACTURE_EXCEL_IMPORT_PRODUCT"
	ExcelExportProduct = "MANUFACTURE_EXCEL_EXPORT_PRODUCT"
)

/*****   1.数据权限  *****/
// DataAuthor 数据验证器
type DataAuthor interface {
	DataAuth(options OperateInfo, data AuthedData) error
}

// AuthedData 需要认证的数据
type AuthedData interface {
	// 数据所属组织
	BelongOrg() int64
}

// 验证参数
type OperateInfo struct {
	// 当前操作人
	UserId int
	// 当前公司
	CompanyId int
	// 当前登录的组织
	OrgId int
	// 菜单模块
	MenuCode string
	// 匹配多个组织
	OrgIds []int
}

func NewCheckOptions(optUser, org int) OperateInfo {
	return OperateInfo{
		UserId: optUser,
		OrgId:  org,
	}
}

func (info OperateInfo) Valid() bool {
	if info.UserId == 0 || info.CompanyId == 0 || info.OrgId == 0 {
		return false
	}
	return true
}

func (info OperateInfo) GetCompanyId(companyId int) int {
	if companyId != 0 {
		return companyId
	}
	return info.CompanyId
}

func (info OperateInfo) GetOrgId(orgId int) int {
	if orgId != 0 {
		return orgId
	}
	return info.OrgId
}

func (info OperateInfo) GetUserId(userId int) int {
	if userId != 0 {
		return userId
	}
	return info.UserId
}

func (info OperateInfo) String() string {
	return fmt.Sprintf("UserId: %v OrgId:%v CompanyId:%v", info.UserId, info.OrgId, info.CompanyId)
}

func Pagination(pageNumber, pageSize int) (offset int, limit int) {
	if pageSize != 0 {
		offset = (pageNumber - 1) * pageSize
		limit = pageSize
	}
	return
}

func ValidWorkOn(workOn int) error {
	if (workOn & WorkOn) == 0 {
		return fmt.Errorf("班次有误")
	}
	return nil
}

func WorkOnDescription(workOn int) []string {
	result := make([]string, 0)
	if workOn&WorkOnFullDay > 0 {
		result = append(result, "全天")
	}
	if workOn&WorkOnDay > 0 {
		result = append(result, "白班")
	}
	if workOn&WorkOnMidDay > 0 {
		result = append(result, "中班")
	}
	if workOn&WorkOnNight > 0 {
		result = append(result, "夜班")
	}
	return result
}

func WorkOnDescriptions(workOn int) string {
	r := WorkOnDescription(workOn)
	return strings.Join(r, ",")
}

func EmployeeTypeDescription(employeeType int) string {
	if employeeType == 1 {
		return "固定"
	}
	if employeeType == 2 {
		return "派遣"
	}
	if employeeType == 3 {
		return "临时"
	}
	return "固定"
}

func ParticipateTypeDescription(participateType int) string {
	if participateType == 1 {
		return "正常"
	}
	if participateType == 2 {
		return "支援"
	}
	return "正常"
}

func AttendanceStatusDescription(status int) string {
	if status == 1 {
		return "未审核"
	}
	if status == 2 {
		return "已审核"
	}
	if status == 4 {
		return "自动审核"
	}
	return "已审核"
}