作者 yangfu

feat: 工时审核

正在显示 28 个修改的文件 包含 1224 行增加42 行删除
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type ApproveAttendanceCommand struct {
  12 + // 考勤记录ID
  13 + ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"`
  14 + // 工时
  15 + WorkTimeAfter float64 `cname:"工时" json:"workTimeAfter,omitempty"`
  16 + // 审核人Id
  17 + ApproveUserId int `json:"approveUserId,omitempty"`
  18 +}
  19 +
  20 +func (approveAttendanceCommand *ApproveAttendanceCommand) Valid(validation *validation.Validation) {
  21 + //validation.SetError("CustomValid", "未实现的自定义认证")
  22 +}
  23 +
  24 +func (approveAttendanceCommand *ApproveAttendanceCommand) ValidateCommand() error {
  25 + valid := validation.Validation{}
  26 + b, err := valid.Valid(approveAttendanceCommand)
  27 + if err != nil {
  28 + return err
  29 + }
  30 + if !b {
  31 + elem := reflect.TypeOf(approveAttendanceCommand).Elem()
  32 + for _, validErr := range valid.Errors {
  33 + field, isExist := elem.FieldByName(validErr.Field)
  34 + if isExist {
  35 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  36 + } else {
  37 + return fmt.Errorf(validErr.Message)
  38 + }
  39 + }
  40 + }
  41 + return nil
  42 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 + "time"
  8 +
  9 + "github.com/beego/beego/v2/core/validation"
  10 +)
  11 +
  12 +type CreateAttendanceCommand struct {
  13 + // 考勤记录ID
  14 + //ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"`
  15 + // 考勤类型 1.正常 2.支援
  16 + AttendanceType int `json:"attendanceType,omitempty"`
  17 + // 生产班组Id
  18 + ProductGroupId int `json:"productGroupId,omitempty" valid:"Required"`
  19 + // 生产工人
  20 + ProductWorkerId int `json:"productWorkerId,omitempty" valid:"Required"`
  21 + // 车间ID
  22 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  23 + // 生产线ID
  24 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  25 + // 工段ID
  26 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  27 + // 签到
  28 + SignIn time.Time `json:"signIn,omitempty"`
  29 + // 签退
  30 + SignOut time.Time `json:"signOut,omitempty"`
  31 + // 考勤状态 1.未审核 2:已审核 3.自动审核
  32 + //AttendanceStatus int `json:"attendanceStatus,omitempty"`
  33 +}
  34 +
  35 +func (createAttendanceCommand *CreateAttendanceCommand) Valid(validation *validation.Validation) {
  36 + //validation.SetError("CustomValid", "未实现的自定义认证")
  37 +}
  38 +
  39 +func (createAttendanceCommand *CreateAttendanceCommand) ValidateCommand() error {
  40 + valid := validation.Validation{}
  41 + b, err := valid.Valid(createAttendanceCommand)
  42 + if err != nil {
  43 + return err
  44 + }
  45 + if !b {
  46 + elem := reflect.TypeOf(createAttendanceCommand).Elem()
  47 + for _, validErr := range valid.Errors {
  48 + field, isExist := elem.FieldByName(validErr.Field)
  49 + if isExist {
  50 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  51 + } else {
  52 + return fmt.Errorf(validErr.Message)
  53 + }
  54 + }
  55 + }
  56 + return nil
  57 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type RemoveAttendanceCommand struct {
  12 + // 考勤记录ID
  13 + ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"`
  14 +}
  15 +
  16 +func (removeAttendanceCommand *RemoveAttendanceCommand) Valid(validation *validation.Validation) {
  17 + //validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (removeAttendanceCommand *RemoveAttendanceCommand) ValidateCommand() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(removeAttendanceCommand)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(removeAttendanceCommand).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type UpdateAttendanceCommand struct {
  12 + // 考勤记录ID
  13 + ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"`
  14 +}
  15 +
  16 +func (updateAttendanceCommand *UpdateAttendanceCommand) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (updateAttendanceCommand *UpdateAttendanceCommand) ValidateCommand() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(updateAttendanceCommand)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(updateAttendanceCommand).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package dto
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  5 +)
  6 +
  7 +type AttendanceRecordDto struct {
  8 + // 考勤记录ID
  9 + ProductAttendanceId int `json:"productAttendanceId"`
  10 + // 企业id
  11 + //CompanyId int `json:"companyId,omitempty"`
  12 + // 组织ID
  13 + //OrgId int `json:"orgId,omitempty"`
  14 + // 考勤类型 1.正常 2.支援
  15 + AttendanceType int `json:"attendanceType,omitempty"`
  16 + // 生产工人
  17 + ProductWorker *domain.User `json:"productWorker,omitempty"`
  18 + *domain.ProductAttendanceRecordExt
  19 + // 工作位置
  20 + *domain.WorkStation
  21 + // 签到
  22 + SignIn string `json:"signIn"`
  23 + // 签退
  24 + SignOut string `json:"signOut"`
  25 + // 考勤状态 1.未审核 2:已审核 3.自动审核
  26 + AttendanceStatus int `json:"attendanceStatus"`
  27 + // 工时(审核前)
  28 + WorkTimeBefore float64 `json:"workTimeBefore"`
  29 + // 工时(审核后)
  30 + WorkTimeAfter float64 `json:"workTimeAfter"`
  31 + // 签到日期
  32 + SignDate string `json:"signDate"`
  33 + // 组织名称
  34 + OrgName string `json:"orgName"`
  35 + // 权限标识 (当前登录组织匹配为true,否则false)
  36 + AuthFlag bool `json:"authFlag"`
  37 +}
  38 +
  39 +func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId int) *AttendanceRecordDto {
  40 + d.ProductAttendanceId = m.ProductAttendanceId
  41 + d.AttendanceType = m.AttendanceType
  42 + d.ProductWorker = m.ProductWorker
  43 + d.WorkStation = m.WorkStation
  44 + if !m.SignIn.IsZero() {
  45 + d.SignIn = m.SignIn.Format("15:04:05")
  46 + d.SignDate = m.SignIn.Format("2006-01-02")
  47 + }
  48 + if !m.SignOut.IsZero() {
  49 + d.SignOut = m.SignOut.Format("15:04:05")
  50 + }
  51 + d.WorkTimeBefore = m.WorkTimeBefore
  52 + d.WorkTimeAfter = m.WorkTimeAfter
  53 + d.AttendanceStatus = m.AttendanceStatus
  54 + d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
  55 + if m.Ext != nil {
  56 + d.OrgName = m.Ext.OrgName
  57 + d.ProductAttendanceRecordExt = m.Ext.AttendanceExt
  58 + }
  59 + return d
  60 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type GetAttendanceQuery struct {
  12 + // 考勤记录ID
  13 + ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"`
  14 +}
  15 +
  16 +func (getAttendanceQuery *GetAttendanceQuery) Valid(validation *validation.Validation) {
  17 + //validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (getAttendanceQuery *GetAttendanceQuery) ValidateQuery() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(getAttendanceQuery)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(getAttendanceQuery).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type ListAttendanceQuery struct {
  12 + // 查询偏离量
  13 + Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
  14 + // 查询限制
  15 + Limit int `cname:"查询限制" json:"limit" valid:"Required"`
  16 +}
  17 +
  18 +func (listAttendanceQuery *ListAttendanceQuery) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (listAttendanceQuery *ListAttendanceQuery) ValidateQuery() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(listAttendanceQuery)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(listAttendanceQuery).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  6 + "reflect"
  7 + "strings"
  8 +
  9 + "github.com/beego/beego/v2/core/validation"
  10 +)
  11 +
  12 +type SearchAttendanceQuery struct {
  13 + // 查询偏离量
  14 + Offset int `cname:"查询偏离量" json:"offset"`
  15 + // 查询限制
  16 + Limit int `cname:"查询限制" json:"limit"`
  17 + // 当前公司
  18 + CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
  19 + // 当前登录的组织
  20 + OrgId int `cname:"当前登录的组织" json:"orgId,omitempty" `
  21 + // 匹配多个组织
  22 + InOrgIds []int `cname:"匹配多个组织" json:"inOrgIds,omitempty" `
  23 + // 页码
  24 + PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
  25 + // 页数
  26 + PageSize int `cname:"页数" json:"pageSize,omitempty"`
  27 + // 车间名称
  28 + WorkshopName string `cname:"车间名称" json:"workshopName,omitempty"`
  29 + // 姓名
  30 + UserName string `cname:"姓名" json:"userName,omitempty"`
  31 + // 考勤状态 1.未审核 2:已审核 3.自动审核
  32 + AttendanceStatus int `cname:"考勤状态 1.未审核 2:已审核 3.自动审核" json:"attendanceStatus,omitempty"`
  33 +}
  34 +
  35 +func (cmd *SearchAttendanceQuery) Valid(validation *validation.Validation) {
  36 + cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize)
  37 +}
  38 +
  39 +func (cmd *SearchAttendanceQuery) ValidateQuery() error {
  40 + valid := validation.Validation{}
  41 + b, err := valid.Valid(cmd)
  42 + if err != nil {
  43 + return err
  44 + }
  45 + if !b {
  46 + elem := reflect.TypeOf(cmd).Elem()
  47 + for _, validErr := range valid.Errors {
  48 + field, isExist := elem.FieldByName(validErr.Field)
  49 + if isExist {
  50 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  51 + } else {
  52 + return fmt.Errorf(validErr.Message)
  53 + }
  54 + }
  55 + }
  56 + return nil
  57 +}
  1 +package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/command"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/dto"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/query"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
  12 + "time"
  13 +)
  14 +
  15 +type AttendanceService struct {
  16 +}
  17 +
  18 +// 审核工时
  19 +func (attendanceService *AttendanceService) ApproveAttendance(cmd *command.ApproveAttendanceCommand) (interface{}, error) {
  20 + if err := cmd.ValidateCommand(); err != nil {
  21 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  22 + }
  23 + transactionContext, err := factory.CreateTransactionContext(nil)
  24 + if err != nil {
  25 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  26 + }
  27 + if err := transactionContext.StartTransaction(); err != nil {
  28 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  29 + }
  30 + defer func() {
  31 + transactionContext.RollbackTransaction()
  32 + }()
  33 + var productAttendanceRecordRepository domain.ProductAttendanceRecordRepository
  34 + var attendance *domain.ProductAttendanceRecord
  35 + productAttendanceRecordRepository, attendance, err = factory.FastPgAttendance(transactionContext, cmd.ProductAttendanceId)
  36 + if err != nil {
  37 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  38 + }
  39 +
  40 + var user *domain.User
  41 + userService := domainService.NewUserService()
  42 + user, err = userService.User(cmd.ApproveUserId)
  43 + if err != nil {
  44 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  45 + }
  46 +
  47 + if err = attendance.Approve(user, cmd.WorkTimeAfter); err != nil {
  48 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  49 + }
  50 +
  51 + if _, err := productAttendanceRecordRepository.Save(attendance); err != nil {
  52 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  53 + }
  54 +
  55 + if err := transactionContext.CommitTransaction(); err != nil {
  56 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  57 + }
  58 + return struct{}{}, nil
  59 +}
  60 +
  61 +// 创建
  62 +func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain.OperateInfo, cmd *command.CreateAttendanceCommand) (interface{}, error) {
  63 + if err := cmd.ValidateCommand(); err != nil {
  64 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  65 + }
  66 + transactionContext, err := factory.CreateTransactionContext(nil)
  67 + if err != nil {
  68 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  69 + }
  70 + if err := transactionContext.StartTransaction(); err != nil {
  71 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  72 + }
  73 + defer func() {
  74 + transactionContext.RollbackTransaction()
  75 + }()
  76 +
  77 + var user *domain.User
  78 + userService := domainService.NewUserService()
  79 + user, err = userService.User(cmd.ProductWorkerId)
  80 + if err != nil {
  81 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  82 + }
  83 +
  84 + var workStation *domain.WorkStation
  85 + _, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)
  86 + if err != nil {
  87 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  88 + }
  89 +
  90 + var org *domain.Org
  91 + org, err = userService.Organization(operateInfo.OrgId)
  92 + if err != nil {
  93 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  94 + }
  95 +
  96 + var productGroup *domain.ProductGroup
  97 + _, productGroup, err = factory.FastPgProductGroup(transactionContext, cmd.ProductGroupId)
  98 + if err != nil {
  99 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  100 + }
  101 + newAttendance := &domain.ProductAttendanceRecord{
  102 + //ProductAttendanceId: cmd.ProductAttendanceId,
  103 + CompanyId: operateInfo.CompanyId,
  104 + OrgId: operateInfo.OrgId,
  105 + AttendanceType: cmd.AttendanceType,
  106 + ProductWorker: user,
  107 + WorkStation: workStation,
  108 + SignIn: cmd.SignIn,
  109 + SignOut: cmd.SignOut,
  110 + AttendanceStatus: domain.AttendanceNotApprove,
  111 + WorkTimeBefore: 0,
  112 + WorkTimeAfter: 0,
  113 + CreatedAt: time.Now(),
  114 + UpdatedAt: time.Now(),
  115 + Ext: domain.NewExt(org.OrgName).WithAttendanceExt(&domain.ProductAttendanceRecordExt{
  116 + GroupName: productGroup.GroupName,
  117 + ProductGroupId: productGroup.ProductGroupId,
  118 + }),
  119 + }
  120 + var attendanceRepository domain.ProductAttendanceRecordRepository
  121 +
  122 + attendanceRepository, _, _ = factory.FastPgAttendance(transactionContext, 0)
  123 +
  124 + if attendance, err := attendanceRepository.Save(newAttendance); err != nil {
  125 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  126 + } else {
  127 + if err := transactionContext.CommitTransaction(); err != nil {
  128 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  129 + }
  130 + return attendance, nil
  131 + }
  132 +}
  133 +
  134 +// 返回
  135 +func (attendanceService *AttendanceService) GetAttendance(getAttendanceQuery *query.GetAttendanceQuery) (interface{}, error) {
  136 + if err := getAttendanceQuery.ValidateQuery(); err != nil {
  137 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  138 + }
  139 + transactionContext, err := factory.CreateTransactionContext(nil)
  140 + if err != nil {
  141 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  142 + }
  143 + if err := transactionContext.StartTransaction(); err != nil {
  144 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  145 + }
  146 + defer func() {
  147 + transactionContext.RollbackTransaction()
  148 + }()
  149 + //var attendanceRepository domain.ProductAttendanceRecordRepository
  150 + var attendance *domain.ProductAttendanceRecord
  151 + _, attendance, err = factory.FastPgAttendance(transactionContext, getAttendanceQuery.ProductAttendanceId)
  152 + if err != nil {
  153 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  154 + }
  155 +
  156 + if err := transactionContext.CommitTransaction(); err != nil {
  157 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  158 + }
  159 + result := &dto.AttendanceRecordDto{}
  160 + result.LoadDto(attendance, 0)
  161 + return result, nil
  162 +}
  163 +
  164 +// 返回列表
  165 +func (attendanceService *AttendanceService) ListAttendance(listAttendanceQuery *query.ListAttendanceQuery) (interface{}, error) {
  166 + if err := listAttendanceQuery.ValidateQuery(); err != nil {
  167 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  168 + }
  169 + transactionContext, err := factory.CreateTransactionContext(nil)
  170 + if err != nil {
  171 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  172 + }
  173 + if err := transactionContext.StartTransaction(); err != nil {
  174 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  175 + }
  176 + defer func() {
  177 + transactionContext.RollbackTransaction()
  178 + }()
  179 + //var attendanceRepository attendance.AttendanceRepository
  180 + //if value, err := factory.CreateAttendanceRepository(map[string]interface{}{
  181 + // "transactionContext": transactionContext,
  182 + //}); err != nil {
  183 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  184 + //} else {
  185 + // attendanceRepository = value
  186 + //}
  187 + //if count, attendances, err := attendanceRepository.Find(tool_funs.SimpleStructToMap(listAttendanceQuery)); err != nil {
  188 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  189 + //} else {
  190 + // if err := transactionContext.CommitTransaction(); err != nil {
  191 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  192 + // }
  193 + // return map[string]interface{}{
  194 + // "count": count,
  195 + // "attendances": attendances,
  196 + // }, nil
  197 + //}
  198 + return nil, nil
  199 +}
  200 +
  201 +// 移除
  202 +func (attendanceService *AttendanceService) RemoveAttendance(removeAttendanceCommand *command.RemoveAttendanceCommand) (interface{}, error) {
  203 + if err := removeAttendanceCommand.ValidateCommand(); err != nil {
  204 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  205 + }
  206 + transactionContext, err := factory.CreateTransactionContext(nil)
  207 + if err != nil {
  208 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  209 + }
  210 + if err := transactionContext.StartTransaction(); err != nil {
  211 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  212 + }
  213 + defer func() {
  214 + transactionContext.RollbackTransaction()
  215 + }()
  216 + var attendanceRepository domain.ProductAttendanceRecordRepository
  217 + var attendance *domain.ProductAttendanceRecord
  218 +
  219 + attendanceRepository, attendance, err = factory.FastPgAttendance(transactionContext, removeAttendanceCommand.ProductAttendanceId)
  220 + if err != nil {
  221 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  222 + }
  223 +
  224 + if attendance, err := attendanceRepository.Remove(attendance); err != nil {
  225 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  226 + } else {
  227 + if err := transactionContext.CommitTransaction(); err != nil {
  228 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  229 + }
  230 + return attendance, nil
  231 + }
  232 +}
  233 +
  234 +// 更新
  235 +func (attendanceService *AttendanceService) UpdateAttendance(updateAttendanceCommand *command.UpdateAttendanceCommand) (interface{}, error) {
  236 + if err := updateAttendanceCommand.ValidateCommand(); err != nil {
  237 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  238 + }
  239 + transactionContext, err := factory.CreateTransactionContext(nil)
  240 + if err != nil {
  241 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  242 + }
  243 + if err := transactionContext.StartTransaction(); err != nil {
  244 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  245 + }
  246 + defer func() {
  247 + transactionContext.RollbackTransaction()
  248 + }()
  249 + //var attendanceRepository attendance.AttendanceRepository
  250 + //if value, err := factory.CreateAttendanceRepository(map[string]interface{}{
  251 + // "transactionContext": transactionContext,
  252 + //}); err != nil {
  253 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  254 + //} else {
  255 + // attendanceRepository = value
  256 + //}
  257 + //attendance, err := attendanceRepository.FindOne(map[string]interface{}{"attendanceId": updateAttendanceCommand.AttendanceId})
  258 + //if err != nil {
  259 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  260 + //}
  261 + //if attendance == nil {
  262 + // return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateAttendanceCommand.AttendanceId)))
  263 + //}
  264 + //if err := attendance.Update(tool_funs.SimpleStructToMap(updateAttendanceCommand)); err != nil {
  265 + // return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  266 + //}
  267 + //if attendance, err := attendanceRepository.Save(attendance); err != nil {
  268 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  269 + //} else {
  270 + // if err := transactionContext.CommitTransaction(); err != nil {
  271 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  272 + // }
  273 + // return attendance, nil
  274 + //}
  275 + return nil, nil
  276 +}
  277 +
  278 +// 返回列表
  279 +func (attendanceService *AttendanceService) SearchAttendance(operateInfo *domain.OperateInfo, cmd *query.SearchAttendanceQuery) (int64, interface{}, error) {
  280 + if err := cmd.ValidateQuery(); err != nil {
  281 + return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
  282 + }
  283 + transactionContext, err := factory.CreateTransactionContext(nil)
  284 + if err != nil {
  285 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  286 + }
  287 + if err := transactionContext.StartTransaction(); err != nil {
  288 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  289 + }
  290 + defer func() {
  291 + transactionContext.RollbackTransaction()
  292 + }()
  293 + var attendanceRepository domain.ProductAttendanceRecordRepository
  294 + attendanceRepository, _, _ = factory.FastPgAttendance(transactionContext, 0)
  295 +
  296 + queryOptions := utils.ObjectToMap(cmd)
  297 +
  298 + count, attendances, err := attendanceRepository.Find(queryOptions)
  299 + if err != nil {
  300 + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  301 + }
  302 + if err := transactionContext.CommitTransaction(); err != nil {
  303 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  304 + }
  305 + var result = make([]*dto.AttendanceRecordDto, 0)
  306 + for i := range attendances {
  307 + newItem := &dto.AttendanceRecordDto{}
  308 + result = append(result, newItem.LoadDto(attendances[i], operateInfo.OrgId))
  309 + }
  310 + return count, result, nil
  311 +}
  312 +
  313 +func NewAttendanceService(options map[string]interface{}) *AttendanceService {
  314 + newAttendanceService := &AttendanceService{}
  315 + return newAttendanceService
  316 +}
@@ -283,6 +283,32 @@ func FastPgProductPlan(transactionContext application.TransactionContext, id int @@ -283,6 +283,32 @@ func FastPgProductPlan(transactionContext application.TransactionContext, id int
283 return rep, mod, err 283 return rep, mod, err
284 } 284 }
285 285
  286 +// FastPgAttendance 快速返回考勤记录
  287 +//
  288 +// transactionContext 事务
  289 +// id 对象唯一标识
  290 +func FastPgAttendance(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductAttendanceRecordRepository, *domain.ProductAttendanceRecord, error) {
  291 + var rep domain.ProductAttendanceRecordRepository
  292 + var mod *domain.ProductAttendanceRecord
  293 + var err error
  294 + if value, err := CreateProductAttendanceRecordRepository(map[string]interface{}{
  295 + "transactionContext": transactionContext,
  296 + }); err != nil {
  297 + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  298 + } else {
  299 + rep = value
  300 + }
  301 + if id > 0 {
  302 + if mod, err = rep.FindOne(map[string]interface{}{"productAttendanceRecordId": id}); err != nil {
  303 + if err == domain.ErrorNotFound {
  304 + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该考勤记录不存在")
  305 + }
  306 + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  307 + }
  308 + }
  309 + return rep, mod, err
  310 +}
  311 +
286 /***** 2.配置 *****/ 312 /***** 2.配置 *****/
287 313
288 type FastOptions struct { 314 type FastOptions struct {
@@ -30,6 +30,17 @@ type ProductJobDto struct { @@ -30,6 +30,17 @@ type ProductJobDto struct {
30 //OrgName string `json:"orgName"` 30 //OrgName string `json:"orgName"`
31 // 权限标识 (当前登录组织匹配为true,否则false) 31 // 权限标识 (当前登录组织匹配为true,否则false)
32 //AuthFlag bool `json:"authFlag"` 32 //AuthFlag bool `json:"authFlag"`
  33 + // 关联设备列表
  34 + RelatedDevices []DeviceDto `json:"relatedDevices,omitempty"`
  35 +}
  36 +
  37 +type DeviceDto struct {
  38 + // 设备Id
  39 + DeviceId int `json:"deviceId,omitempty"`
  40 + // 设备编号
  41 + DeviceCode string `json:"deviceCode,omitempty"`
  42 + // 设备名称
  43 + DeviceName string `json:"deviceName,omitempty"`
33 } 44 }
34 45
35 func (d *ProductJobDto) LoadDto(job *domain.ProductJob, orgId int) { 46 func (d *ProductJobDto) LoadDto(job *domain.ProductJob, orgId int) {
@@ -42,3 +53,14 @@ func (d *ProductJobDto) LoadDto(job *domain.ProductJob, orgId int) { @@ -42,3 +53,14 @@ func (d *ProductJobDto) LoadDto(job *domain.ProductJob, orgId int) {
42 // d.OrgName = job.Ext.OrgName 53 // d.OrgName = job.Ext.OrgName
43 //} 54 //}
44 } 55 }
  56 +
  57 +func (d *ProductJobDto) WithRelatedDevices(devices []*domain.Device) *ProductJobDto {
  58 + for i := range devices {
  59 + d.RelatedDevices = append(d.RelatedDevices, DeviceDto{
  60 + DeviceName: devices[i].DeviceName,
  61 + DeviceId: devices[i].DeviceId,
  62 + DeviceCode: devices[i].DeviceCode,
  63 + })
  64 + }
  65 + return d
  66 +}
@@ -97,9 +97,23 @@ func (productJobService *ProductJobService) GetProductJob(getProductJobQuery *qu @@ -97,9 +97,23 @@ func (productJobService *ProductJobService) GetProductJob(getProductJobQuery *qu
97 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 97 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
98 } 98 }
99 productJob.WorkStation, _ = workshop.FindWorkStation(productJob.WorkStation.WorkshopId, productJob.WorkStation.LineId, productJob.WorkStation.SectionId) 99 productJob.WorkStation, _ = workshop.FindWorkStation(productJob.WorkStation.WorkshopId, productJob.WorkStation.LineId, productJob.WorkStation.SectionId)
  100 +
100 newJobDto := &dto.ProductJobDto{} 101 newJobDto := &dto.ProductJobDto{}
101 newJobDto.LoadDto(productJob, 0) 102 newJobDto.LoadDto(productJob, 0)
102 103
  104 + if len(productJob.RelatedDevices) > 0 {
  105 + deviceRepository, _, _ := factory.FastPgDevice(transactionContext, 0)
  106 + _, devices, err := deviceRepository.Find(map[string]interface{}{
  107 + "companyId": productJob.CompanyId,
  108 + "orgId": productJob.OrgId,
  109 + "inDeviceId": productJob.RelatedDevices,
  110 + })
  111 + if err != nil {
  112 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  113 + }
  114 + newJobDto.WithRelatedDevices(devices)
  115 + }
  116 +
103 if err := transactionContext.CommitTransaction(); err != nil { 117 if err := transactionContext.CommitTransaction(); err != nil {
104 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 118 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
105 } 119 }
@@ -4,7 +4,6 @@ import ( @@ -4,7 +4,6 @@ import (
4 "fmt" 4 "fmt"
5 "os" 5 "os"
6 "strconv" 6 "strconv"
7 - "strings"  
8 ) 7 )
9 8
10 var SERVICE_NAME = "allied-creation-manufacture" 9 var SERVICE_NAME = "allied-creation-manufacture"
@@ -37,21 +36,21 @@ func init() { @@ -37,21 +36,21 @@ func init() {
37 if os.Getenv("LOG_LEVEL") != "" { 36 if os.Getenv("LOG_LEVEL") != "" {
38 LOG_LEVEL = os.Getenv("LOG_LEVEL") 37 LOG_LEVEL = os.Getenv("LOG_LEVEL")
39 } 38 }
40 - if os.Getenv("CUSTOMER_ACCOUNT") != "" {  
41 - account := os.Getenv("CUSTOMER_ACCOUNT")  
42 - accounts := strings.Split(account, CUSTOMER_ACCOUNT_DELIMITER)  
43 - var tmpAccounts []int64  
44 - for i := range accounts {  
45 - v, err := strconv.ParseInt(accounts[i], 10, 64)  
46 - if err != nil {  
47 - panic(err)  
48 - }  
49 - tmpAccounts = append(tmpAccounts, v)  
50 - }  
51 - if len(tmpAccounts) > 0 {  
52 - CUSTOMER_ACCOUNT = tmpAccounts  
53 - }  
54 - } 39 + //if os.Getenv("CUSTOMER_ACCOUNT") != "" {
  40 + // account := os.Getenv("CUSTOMER_ACCOUNT")
  41 + // accounts := strings.Split(account, CUSTOMER_ACCOUNT_DELIMITER)
  42 + // var tmpAccounts []int64
  43 + // for i := range accounts {
  44 + // v, err := strconv.ParseInt(accounts[i], 10, 64)
  45 + // if err != nil {
  46 + // panic(err)
  47 + // }
  48 + // tmpAccounts = append(tmpAccounts, v)
  49 + // }
  50 + // if len(tmpAccounts) > 0 {
  51 + // CUSTOMER_ACCOUNT = tmpAccounts
  52 + // }
  53 + //}
55 54
56 if os.Getenv("ALLIED_CREATION_BASIC_HOST") != "" { 55 if os.Getenv("ALLIED_CREATION_BASIC_HOST") != "" {
57 ALLIED_CREATION_BASIC_HOST = os.Getenv("ALLIED_CREATION_BASIC_HOST") 56 ALLIED_CREATION_BASIC_HOST = os.Getenv("ALLIED_CREATION_BASIC_HOST")
@@ -6,7 +6,10 @@ type Ext struct { @@ -6,7 +6,10 @@ type Ext struct {
6 OrgName string `json:"orgName,omitempty"` 6 OrgName string `json:"orgName,omitempty"`
7 7
8 // 设备扩展数据 8 // 设备扩展数据
9 - DeviceExt *DeviceExt `json:"deviceExt"` 9 + DeviceExt *DeviceExt `json:"deviceExt,omitempty"`
  10 +
  11 + // 考勤记录扩展
  12 + AttendanceExt *ProductAttendanceRecordExt `json:"attendanceExt,omitempty"`
10 } 13 }
11 14
12 func NewExt(orgName string) *Ext { 15 func NewExt(orgName string) *Ext {
@@ -19,3 +22,8 @@ func (e *Ext) WithDeviceExt(deviceExt *DeviceExt) *Ext { @@ -19,3 +22,8 @@ func (e *Ext) WithDeviceExt(deviceExt *DeviceExt) *Ext {
19 e.DeviceExt = deviceExt 22 e.DeviceExt = deviceExt
20 return e 23 return e
21 } 24 }
  25 +
  26 +func (e *Ext) WithAttendanceExt(ext *ProductAttendanceRecordExt) *Ext {
  27 + e.AttendanceExt = ext
  28 + return e
  29 +}
1 package domain 1 package domain
2 2
3 -import "time" 3 +import (
  4 + "errors"
  5 + "time"
  6 +)
  7 +
  8 +const (
  9 + AttendanceNotApprove = 1 // 未审核
  10 + AttendanceApproved = 2 // 已审核
  11 +)
4 12
5 // 生产考勤记录 13 // 生产考勤记录
6 type ProductAttendanceRecord struct { 14 type ProductAttendanceRecord struct {
@@ -125,3 +133,17 @@ func (productAttendanceRecord *ProductAttendanceRecord) Update(data map[string]i @@ -125,3 +133,17 @@ func (productAttendanceRecord *ProductAttendanceRecord) Update(data map[string]i
125 } 133 }
126 return nil 134 return nil
127 } 135 }
  136 +
  137 +func (productAttendanceRecord *ProductAttendanceRecord) Approve(approveUser *User, workTimeAfter float64) error {
  138 + if productAttendanceRecord.AttendanceStatus == AttendanceApproved {
  139 + return errors.New("已审核")
  140 + }
  141 + productAttendanceRecord.AttendanceStatus = AttendanceApproved
  142 + productAttendanceRecord.WorkTimeAfter = workTimeAfter
  143 + if productAttendanceRecord.Ext != nil && productAttendanceRecord.Ext.AttendanceExt != nil {
  144 + productAttendanceRecord.Ext.AttendanceExt.ApproveUserId = approveUser.UserId
  145 + productAttendanceRecord.Ext.AttendanceExt.ApproveUserName = approveUser.UserName
  146 + productAttendanceRecord.Ext.AttendanceExt.ApproveAt = time.Now().Unix()
  147 + }
  148 + return nil
  149 +}
  1 +package domain
  2 +
  3 +// ProductAttendanceRecordExt 生产考勤扩展
  4 +type ProductAttendanceRecordExt struct {
  5 + // 生产小组ID
  6 + ProductGroupId int `json:"productGroupId,omitempty"`
  7 + // 班组名称
  8 + GroupName string `json:"groupName,omitempty"`
  9 + // 审核人Id
  10 + ApproveUserId int `json:"approveUserId,omitempty"`
  11 + // 审核人名称
  12 + ApproveUserName string `json:"approveUserName,omitempty"`
  13 + // 审核时间
  14 + ApproveAt int64 `json:"approveAt,omitempty"`
  15 +}
@@ -8,7 +8,7 @@ import ( @@ -8,7 +8,7 @@ import (
8 type ProductAttendanceRecord struct { 8 type ProductAttendanceRecord struct {
9 tableName string `comment:"生产考勤记录" pg:"manufacture.product_attendance_record,alias:product_attendance_record"` 9 tableName string `comment:"生产考勤记录" pg:"manufacture.product_attendance_record,alias:product_attendance_record"`
10 // 考勤记录ID 10 // 考勤记录ID
11 - ProductAttendanceId int `comment:"考勤记录ID"` 11 + ProductAttendanceId int `comment:"考勤记录ID" pg:"pk:product_attendance_id"`
12 // 企业id 12 // 企业id
13 CompanyId int `comment:"企业id"` 13 CompanyId int `comment:"企业id"`
14 // 组织ID 14 // 组织ID
@@ -171,6 +171,9 @@ func (repository *DeviceRepository) Find(queryOptions map[string]interface{}) (i @@ -171,6 +171,9 @@ func (repository *DeviceRepository) Find(queryOptions map[string]interface{}) (i
171 if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 { 171 if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 {
172 query.Where(`org_id in (?)`, pg.In(v)) 172 query.Where(`org_id in (?)`, pg.In(v))
173 } 173 }
  174 + if v, ok := queryOptions["inDeviceId"]; ok && len(v.([]int)) > 0 {
  175 + query.Where(`device_id in (?)`, pg.In(v))
  176 + }
174 query.SetWhereByQueryOption("device_code = ?", "deviceCode") 177 query.SetWhereByQueryOption("device_code = ?", "deviceCode")
175 query.SetWhereByQueryOption("device_status = ?", "deviceStatus") 178 query.SetWhereByQueryOption("device_status = ?", "deviceStatus")
176 if v, ok := queryOptions["deviceName"]; ok && len(v.(string)) > 0 { 179 if v, ok := queryOptions["deviceName"]; ok && len(v.(string)) > 0 {
@@ -28,7 +28,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor @@ -28,7 +28,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
28 sqlBuildFields := []string{ 28 sqlBuildFields := []string{
29 "product_attendance_id", 29 "product_attendance_id",
30 "org_id", 30 "org_id",
31 - "product_id", 31 + "company_id",
32 "attendance_type", 32 "attendance_type",
33 "product_worker", 33 "product_worker",
34 "work_station", 34 "work_station",
@@ -42,24 +42,18 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor @@ -42,24 +42,18 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
42 "deleted_at", 42 "deleted_at",
43 "ext", 43 "ext",
44 } 44 }
45 - insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)  
46 - insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) 45 + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_attendance_id", "deleted_at"))
  46 + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_attendance_id", "deleted_at"))
47 returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) 47 returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
48 - updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "productAttendanceRecord_id") 48 + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_attendance_id", "deleted_at")
49 updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) 49 updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
50 tx := repository.transactionContext.PgTx 50 tx := repository.transactionContext.PgTx
51 if productAttendanceRecord.Identify() == nil { 51 if productAttendanceRecord.Identify() == nil {
52 - productAttendanceRecordId, err := repository.nextIdentify()  
53 - if err != nil {  
54 - return productAttendanceRecord, err  
55 - } else {  
56 - productAttendanceRecord.ProductAttendanceId = int(productAttendanceRecordId)  
57 - }  
58 if _, err := tx.QueryOne( 52 if _, err := tx.QueryOne(
59 pg.Scan( 53 pg.Scan(
60 &productAttendanceRecord.ProductAttendanceId, 54 &productAttendanceRecord.ProductAttendanceId,
61 &productAttendanceRecord.OrgId, 55 &productAttendanceRecord.OrgId,
62 - &productAttendanceRecord.ProductId, 56 + &productAttendanceRecord.CompanyId,
63 &productAttendanceRecord.AttendanceType, 57 &productAttendanceRecord.AttendanceType,
64 &productAttendanceRecord.ProductWorker, 58 &productAttendanceRecord.ProductWorker,
65 &productAttendanceRecord.WorkStation, 59 &productAttendanceRecord.WorkStation,
@@ -73,10 +67,10 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor @@ -73,10 +67,10 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
73 &productAttendanceRecord.DeletedAt, 67 &productAttendanceRecord.DeletedAt,
74 &productAttendanceRecord.Ext, 68 &productAttendanceRecord.Ext,
75 ), 69 ),
76 - fmt.Sprintf("INSERT INTO product_attendance_records (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),  
77 - productAttendanceRecord.ProductAttendanceId, 70 + fmt.Sprintf("INSERT INTO manufacture.product_attendance_record (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
  71 + //productAttendanceRecord.ProductAttendanceId,
78 productAttendanceRecord.OrgId, 72 productAttendanceRecord.OrgId,
79 - productAttendanceRecord.ProductId, 73 + productAttendanceRecord.CompanyId,
80 productAttendanceRecord.AttendanceType, 74 productAttendanceRecord.AttendanceType,
81 productAttendanceRecord.ProductWorker, 75 productAttendanceRecord.ProductWorker,
82 productAttendanceRecord.WorkStation, 76 productAttendanceRecord.WorkStation,
@@ -87,7 +81,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor @@ -87,7 +81,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
87 productAttendanceRecord.WorkTimeAfter, 81 productAttendanceRecord.WorkTimeAfter,
88 productAttendanceRecord.CreatedAt, 82 productAttendanceRecord.CreatedAt,
89 productAttendanceRecord.UpdatedAt, 83 productAttendanceRecord.UpdatedAt,
90 - productAttendanceRecord.DeletedAt, 84 + //productAttendanceRecord.DeletedAt,
91 productAttendanceRecord.Ext, 85 productAttendanceRecord.Ext,
92 ); err != nil { 86 ); err != nil {
93 return productAttendanceRecord, err 87 return productAttendanceRecord, err
@@ -97,7 +91,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor @@ -97,7 +91,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
97 pg.Scan( 91 pg.Scan(
98 &productAttendanceRecord.ProductAttendanceId, 92 &productAttendanceRecord.ProductAttendanceId,
99 &productAttendanceRecord.OrgId, 93 &productAttendanceRecord.OrgId,
100 - &productAttendanceRecord.ProductId, 94 + &productAttendanceRecord.CompanyId,
101 &productAttendanceRecord.AttendanceType, 95 &productAttendanceRecord.AttendanceType,
102 &productAttendanceRecord.ProductWorker, 96 &productAttendanceRecord.ProductWorker,
103 &productAttendanceRecord.WorkStation, 97 &productAttendanceRecord.WorkStation,
@@ -111,10 +105,10 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor @@ -111,10 +105,10 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
111 &productAttendanceRecord.DeletedAt, 105 &productAttendanceRecord.DeletedAt,
112 &productAttendanceRecord.Ext, 106 &productAttendanceRecord.Ext,
113 ), 107 ),
114 - fmt.Sprintf("UPDATE product_attendance_records SET %s WHERE product_attendance_record_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),  
115 - productAttendanceRecord.ProductAttendanceId, 108 + fmt.Sprintf("UPDATE manufacture.product_attendance_record SET %s WHERE product_attendance_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
  109 + //productAttendanceRecord.ProductAttendanceId,
116 productAttendanceRecord.OrgId, 110 productAttendanceRecord.OrgId,
117 - productAttendanceRecord.ProductId, 111 + productAttendanceRecord.CompanyId,
118 productAttendanceRecord.AttendanceType, 112 productAttendanceRecord.AttendanceType,
119 productAttendanceRecord.ProductWorker, 113 productAttendanceRecord.ProductWorker,
120 productAttendanceRecord.WorkStation, 114 productAttendanceRecord.WorkStation,
@@ -125,7 +119,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor @@ -125,7 +119,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
125 productAttendanceRecord.WorkTimeAfter, 119 productAttendanceRecord.WorkTimeAfter,
126 productAttendanceRecord.CreatedAt, 120 productAttendanceRecord.CreatedAt,
127 productAttendanceRecord.UpdatedAt, 121 productAttendanceRecord.UpdatedAt,
128 - productAttendanceRecord.DeletedAt, 122 + //productAttendanceRecord.DeletedAt,
129 productAttendanceRecord.Ext, 123 productAttendanceRecord.Ext,
130 productAttendanceRecord.Identify(), 124 productAttendanceRecord.Identify(),
131 ); err != nil { 125 ); err != nil {
@@ -147,7 +141,7 @@ func (repository *ProductAttendanceRecordRepository) FindOne(queryOptions map[st @@ -147,7 +141,7 @@ func (repository *ProductAttendanceRecordRepository) FindOne(queryOptions map[st
147 tx := repository.transactionContext.PgTx 141 tx := repository.transactionContext.PgTx
148 productAttendanceRecordModel := new(models.ProductAttendanceRecord) 142 productAttendanceRecordModel := new(models.ProductAttendanceRecord)
149 query := sqlbuilder.BuildQuery(tx.Model(productAttendanceRecordModel), queryOptions) 143 query := sqlbuilder.BuildQuery(tx.Model(productAttendanceRecordModel), queryOptions)
150 - query.SetWhereByQueryOption("product_attendance_record.product_attendance_record_id = ?", "productAttendanceRecordId") 144 + query.SetWhereByQueryOption("product_attendance_record.product_attendance_id = ?", "productAttendanceRecordId")
151 if v, ok := queryOptions["includeDeleted"]; ok && v.(bool) { 145 if v, ok := queryOptions["includeDeleted"]; ok && v.(bool) {
152 query.AllWithDeleted() 146 query.AllWithDeleted()
153 } 147 }
@@ -169,8 +163,20 @@ func (repository *ProductAttendanceRecordRepository) Find(queryOptions map[strin @@ -169,8 +163,20 @@ func (repository *ProductAttendanceRecordRepository) Find(queryOptions map[strin
169 var productAttendanceRecordModels []*models.ProductAttendanceRecord 163 var productAttendanceRecordModels []*models.ProductAttendanceRecord
170 productAttendanceRecords := make([]*domain.ProductAttendanceRecord, 0) 164 productAttendanceRecords := make([]*domain.ProductAttendanceRecord, 0)
171 query := sqlbuilder.BuildQuery(tx.Model(&productAttendanceRecordModels), queryOptions) 165 query := sqlbuilder.BuildQuery(tx.Model(&productAttendanceRecordModels), queryOptions)
172 - query.SetOffsetAndLimit(20)  
173 - query.SetOrderDirect("product_attendance_record_id", "DESC") 166 + query.SetWhereByQueryOption("company_id = ?", "companyId")
  167 + query.SetWhereByQueryOption("org_id = ?", "orgId")
  168 + query.SetWhereByQueryOption("attendance_status = ?", "attendanceStatus")
  169 + if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 {
  170 + query.Where(`org_id in (?)`, pg.In(v))
  171 + }
  172 + if v, ok := queryOptions["userName"]; ok && len(v.(string)) > 0 {
  173 + query.Where(fmt.Sprintf(`product_worker->>'userName' like '%%%v%%'`, v))
  174 + }
  175 + if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 {
  176 + query.Where(fmt.Sprintf(`work_station->>'workshopName' like '%%%v%%'`, v))
  177 + }
  178 + query.SetOffsetAndLimit(domain.MaxQueryRow)
  179 + query.SetOrderDirect("product_attendance_id", "DESC")
174 if count, err := query.SelectAndCount(); err != nil { 180 if count, err := query.SelectAndCount(); err != nil {
175 return 0, productAttendanceRecords, err 181 return 0, productAttendanceRecords, err
176 } else { 182 } else {
  1 +package controllers
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/web/beego"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/command"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/query"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/service"
  8 +)
  9 +
  10 +type AttendanceController struct {
  11 + beego.BaseController
  12 +}
  13 +
  14 +func (controller *AttendanceController) CreateAttendance() {
  15 + attendanceService := service.NewAttendanceService(nil)
  16 + createAttendanceCommand := &command.CreateAttendanceCommand{}
  17 + controller.Unmarshal(createAttendanceCommand)
  18 + data, err := attendanceService.CreateAttendance(ParseOperateInfo(controller.BaseController), createAttendanceCommand)
  19 + controller.Response(data, err)
  20 +}
  21 +
  22 +func (controller *AttendanceController) UpdateAttendance() {
  23 + attendanceService := service.NewAttendanceService(nil)
  24 + updateAttendanceCommand := &command.UpdateAttendanceCommand{}
  25 + controller.Unmarshal(updateAttendanceCommand)
  26 + productAttendanceId, _ := controller.GetInt(":productAttendanceId")
  27 + updateAttendanceCommand.ProductAttendanceId = productAttendanceId
  28 + data, err := attendanceService.UpdateAttendance(updateAttendanceCommand)
  29 + controller.Response(data, err)
  30 +}
  31 +
  32 +func (controller *AttendanceController) GetAttendance() {
  33 + attendanceService := service.NewAttendanceService(nil)
  34 + getAttendanceQuery := &query.GetAttendanceQuery{}
  35 + productAttendanceId, _ := controller.GetInt(":productAttendanceId")
  36 + getAttendanceQuery.ProductAttendanceId = productAttendanceId
  37 + data, err := attendanceService.GetAttendance(getAttendanceQuery)
  38 + controller.Response(data, err)
  39 +}
  40 +
  41 +func (controller *AttendanceController) RemoveAttendance() {
  42 + attendanceService := service.NewAttendanceService(nil)
  43 + removeAttendanceCommand := &command.RemoveAttendanceCommand{}
  44 + controller.Unmarshal(removeAttendanceCommand)
  45 + productAttendanceId, _ := controller.GetInt(":productAttendanceId")
  46 + removeAttendanceCommand.ProductAttendanceId = productAttendanceId
  47 + data, err := attendanceService.RemoveAttendance(removeAttendanceCommand)
  48 + controller.Response(data, err)
  49 +}
  50 +
  51 +func (controller *AttendanceController) ListAttendance() {
  52 + attendanceService := service.NewAttendanceService(nil)
  53 + listAttendanceQuery := &query.ListAttendanceQuery{}
  54 + offset, _ := controller.GetInt("offset")
  55 + listAttendanceQuery.Offset = offset
  56 + limit, _ := controller.GetInt("limit")
  57 + listAttendanceQuery.Limit = limit
  58 + data, err := attendanceService.ListAttendance(listAttendanceQuery)
  59 + controller.Response(data, err)
  60 +}
  61 +
  62 +func (controller *AttendanceController) ApproveAttendance() {
  63 + attendanceService := service.NewAttendanceService(nil)
  64 + approveAttendanceCommand := &command.ApproveAttendanceCommand{}
  65 + controller.Unmarshal(approveAttendanceCommand)
  66 + data, err := attendanceService.ApproveAttendance(approveAttendanceCommand)
  67 + controller.Response(data, err)
  68 +}
  69 +
  70 +func (controller *AttendanceController) SearchAttendance() {
  71 + attendanceService := service.NewAttendanceService(nil)
  72 + cmd := &query.SearchAttendanceQuery{}
  73 + controller.Unmarshal(cmd)
  74 + operateInfo := ParseOperateInfo(controller.BaseController)
  75 + //cmd.OrgId = operateInfo.OrgId
  76 + cmd.CompanyId = operateInfo.CompanyId
  77 + cmd.InOrgIds = operateInfo.OrgIds
  78 + total, data, err := attendanceService.SearchAttendance(operateInfo, cmd)
  79 + ResponseGrid(controller.BaseController, total, data, err)
  80 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/beego/beego/v2/server/web"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego/controllers"
  6 +)
  7 +
  8 +func init() {
  9 + web.Router("/attendances/", &controllers.AttendanceController{}, "Post:CreateAttendance")
  10 + web.Router("/attendances/:productAttendanceId", &controllers.AttendanceController{}, "Put:UpdateAttendance")
  11 + web.Router("/attendances/:productAttendanceId", &controllers.AttendanceController{}, "Get:GetAttendance")
  12 + web.Router("/attendances/:productAttendanceId", &controllers.AttendanceController{}, "Delete:RemoveAttendance")
  13 + web.Router("/attendances/", &controllers.AttendanceController{}, "Get:ListAttendance")
  14 + web.Router("/attendances/approve", &controllers.AttendanceController{}, "Post:ApproveAttendance")
  15 + web.Router("/attendances/search", &controllers.AttendanceController{}, "Post:SearchAttendance")
  16 +}
  1 +package attendance
  2 +
  3 +import (
  4 + "github.com/go-pg/pg/v10"
  5 + "net/http"
  6 +
  7 + "github.com/gavv/httpexpect"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("审核工时", func() {
  14 + var productAttendanceRecordId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&productAttendanceRecordId),
  18 + "INSERT INTO product_attendance_records (product_attendance_id, org_id, product_id, attendance_type, product_worker, work_station, sign_in, sign_out, attendance_status, work_time_before, work_time_after, created_at, updated_at, deleted_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING product_attendance_record_id",
  19 + "testProductAttendanceId", "testOrgId", "testProductId", "testAttendanceType", "testProductWorker", "testWorkStation", "testSignIn", "testSignOut", "testAttendanceStatus", "testWorkTimeBefore", "testWorkTimeAfter", "testCreatedAt", "testUpdatedAt", "testDeletedAt")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("审核工时", func() {
  23 + Context("", func() {
  24 + It("", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + body := map[string]interface{}{
  27 + "productAttendanceId": "int",
  28 + "workTimeAfter": "float64",
  29 + }
  30 + httpExpect.POST("/attendances/approve").
  31 + WithJSON(body).
  32 + Expect().
  33 + Status(http.StatusOK).
  34 + JSON().
  35 + Object().
  36 + ContainsKey("code").ValueEqual("code", 0).
  37 + ContainsKey("msg").ValueEqual("msg", "ok").
  38 + ContainsKey("data").Value("data").Object()
  39 + })
  40 + })
  41 + })
  42 + AfterEach(func() {
  43 + _, err := pG.DB.Exec("DELETE FROM product_attendance_records WHERE true")
  44 + Expect(err).NotTo(HaveOccurred())
  45 + })
  46 +})
  1 +package attendance
  2 +
  3 +import (
  4 + "net/http"
  5 + "net/http/httptest"
  6 + "testing"
  7 +
  8 + "github.com/beego/beego/v2/server/web"
  9 + . "github.com/onsi/ginkgo"
  10 + . "github.com/onsi/gomega"
  11 + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application"
  12 + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
  13 + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego"
  14 +)
  15 +
  16 +func TestAttendance(t *testing.T) {
  17 + RegisterFailHandler(Fail)
  18 + RunSpecs(t, "Beego Port Attendance Correlations Test Case Suite")
  19 +}
  20 +
  21 +var handler http.Handler
  22 +var server *httptest.Server
  23 +
  24 +var _ = BeforeSuite(func() {
  25 + handler = web.BeeApp.Handlers
  26 + server = httptest.NewServer(handler)
  27 +})
  28 +
  29 +var _ = AfterSuite(func() {
  30 + server.Close()
  31 +})
  1 +package attendance
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + . "github.com/onsi/ginkgo"
  8 + . "github.com/onsi/gomega"
  9 + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
  10 +)
  11 +
  12 +var _ = Describe("创建", func() {
  13 + Describe("提交数据创建", func() {
  14 + Context("提交正确的新生产考勤记录数据", func() {
  15 + It("返回生产考勤记录数据", func() {
  16 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  17 + body := map[string]interface{}{
  18 + "productAttendanceId": "int",
  19 + }
  20 + httpExpect.POST("/attendances/").
  21 + WithJSON(body).
  22 + Expect().
  23 + Status(http.StatusOK).
  24 + JSON().
  25 + Object().
  26 + ContainsKey("code").ValueEqual("code", 0).
  27 + ContainsKey("msg").ValueEqual("msg", "ok").
  28 + ContainsKey("data").Value("data").Object().
  29 + ContainsKey("productAttendanceRecordId").ValueNotEqual("productAttendanceRecordId", BeZero())
  30 + })
  31 + })
  32 + })
  33 + AfterEach(func() {
  34 + _, err := pG.DB.Exec("DELETE FROM product_attendance_records WHERE true")
  35 + Expect(err).NotTo(HaveOccurred())
  36 + })
  37 +})
  1 +package attendance
  2 +
  3 +import (
  4 + "github.com/go-pg/pg/v10"
  5 + "net/http"
  6 +
  7 + "github.com/gavv/httpexpect"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("返回", func() {
  14 + var productAttendanceRecordId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&productAttendanceRecordId),
  18 + "INSERT INTO product_attendance_records (product_attendance_id, org_id, product_id, attendance_type, product_worker, work_station, sign_in, sign_out, attendance_status, work_time_before, work_time_after, created_at, updated_at, deleted_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING product_attendance_record_id",
  19 + "testProductAttendanceId", "testOrgId", "testProductId", "testAttendanceType", "testProductWorker", "testWorkStation", "testSignIn", "testSignOut", "testAttendanceStatus", "testWorkTimeBefore", "testWorkTimeAfter", "testCreatedAt", "testUpdatedAt", "testDeletedAt")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据productAttendanceRecordId参数返回生产考勤记录", func() {
  23 + Context("传入有效的productAttendanceRecordId", func() {
  24 + It("返回生产考勤记录数据", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.GET("/attendances/{productAttendanceId}").
  27 + Expect().
  28 + Status(http.StatusOK).
  29 + JSON().
  30 + Object().
  31 + ContainsKey("code").ValueEqual("code", 0).
  32 + ContainsKey("msg").ValueEqual("msg", "ok").
  33 + ContainsKey("data").Value("data").Object()
  34 + })
  35 + })
  36 + })
  37 + AfterEach(func() {
  38 + _, err := pG.DB.Exec("DELETE FROM product_attendance_records WHERE true")
  39 + Expect(err).NotTo(HaveOccurred())
  40 + })
  41 +})
  1 +package attendance
  2 +
  3 +import (
  4 + "github.com/go-pg/pg/v10"
  5 + "net/http"
  6 +
  7 + "github.com/gavv/httpexpect"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("返回列表", func() {
  14 + var productAttendanceRecordId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&productAttendanceRecordId),
  18 + "INSERT INTO product_attendance_records (product_attendance_id, org_id, product_id, attendance_type, product_worker, work_station, sign_in, sign_out, attendance_status, work_time_before, work_time_after, created_at, updated_at, deleted_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING product_attendance_record_id",
  19 + "testProductAttendanceId", "testOrgId", "testProductId", "testAttendanceType", "testProductWorker", "testWorkStation", "testSignIn", "testSignOut", "testAttendanceStatus", "testWorkTimeBefore", "testWorkTimeAfter", "testCreatedAt", "testUpdatedAt", "testDeletedAt")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据参数返回生产考勤记录列表", func() {
  23 + Context("传入有效的参数", func() {
  24 + It("返回生产考勤记录数据列表", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.GET("/attendances/").
  27 + WithQuery("offset", "int").
  28 + WithQuery("limit", "int").
  29 + Expect().
  30 + Status(http.StatusOK).
  31 + JSON().
  32 + Object().
  33 + ContainsKey("code").ValueEqual("code", 0).
  34 + ContainsKey("msg").ValueEqual("msg", "ok").
  35 + ContainsKey("data").Value("data").Object().
  36 + ContainsKey("count").ValueEqual("count", 1).
  37 + ContainsKey("productAttendanceRecords").Value("productAttendanceRecords").Array()
  38 + })
  39 + })
  40 + })
  41 + AfterEach(func() {
  42 + _, err := pG.DB.Exec("DELETE FROM product_attendance_records WHERE true")
  43 + Expect(err).NotTo(HaveOccurred())
  44 + })
  45 +})
  1 +package attendance
  2 +
  3 +import (
  4 + "github.com/go-pg/pg/v10"
  5 + "net/http"
  6 +
  7 + "github.com/gavv/httpexpect"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("移除", func() {
  14 + var productAttendanceRecordId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&productAttendanceRecordId),
  18 + "INSERT INTO product_attendance_records (product_attendance_id, org_id, product_id, attendance_type, product_worker, work_station, sign_in, sign_out, attendance_status, work_time_before, work_time_after, created_at, updated_at, deleted_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING product_attendance_record_id",
  19 + "testProductAttendanceId", "testOrgId", "testProductId", "testAttendanceType", "testProductWorker", "testWorkStation", "testSignIn", "testSignOut", "testAttendanceStatus", "testWorkTimeBefore", "testWorkTimeAfter", "testCreatedAt", "testUpdatedAt", "testDeletedAt")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据参数移除", func() {
  23 + Context("传入有效的productAttendanceRecordId", func() {
  24 + It("返回被移除生产考勤记录的数据", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.DELETE("/attendances/{productAttendanceId}").
  27 + Expect().
  28 + Status(http.StatusOK).
  29 + JSON().
  30 + Object().
  31 + ContainsKey("code").ValueEqual("code", 0).
  32 + ContainsKey("msg").ValueEqual("msg", "ok").
  33 + ContainsKey("data").Value("data").Object()
  34 + })
  35 + })
  36 + })
  37 + AfterEach(func() {
  38 + _, err := pG.DB.Exec("DELETE FROM product_attendance_records WHERE true")
  39 + Expect(err).NotTo(HaveOccurred())
  40 + })
  41 +})
  1 +package attendance
  2 +
  3 +import (
  4 + "github.com/go-pg/pg/v10"
  5 + "net/http"
  6 +
  7 + "github.com/gavv/httpexpect"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("更新", func() {
  14 + var productAttendanceRecordId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&productAttendanceRecordId),
  18 + "INSERT INTO product_attendance_records (product_attendance_id, org_id, product_id, attendance_type, product_worker, work_station, sign_in, sign_out, attendance_status, work_time_before, work_time_after, created_at, updated_at, deleted_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING product_attendance_record_id",
  19 + "testProductAttendanceId", "testOrgId", "testProductId", "testAttendanceType", "testProductWorker", "testWorkStation", "testSignIn", "testSignOut", "testAttendanceStatus", "testWorkTimeBefore", "testWorkTimeAfter", "testCreatedAt", "testUpdatedAt", "testDeletedAt")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("提交数据更新", func() {
  23 + Context("提交正确的生产考勤记录数据", func() {
  24 + It("返回更新后的生产考勤记录数据", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + body := map[string]interface{}{}
  27 + httpExpect.PUT("/attendances/{productAttendanceId}").
  28 + WithJSON(body).
  29 + Expect().
  30 + Status(http.StatusOK).
  31 + JSON().
  32 + Object().
  33 + ContainsKey("code").ValueEqual("code", 0).
  34 + ContainsKey("msg").ValueEqual("msg", "ok").
  35 + ContainsKey("data").Value("data").Object().
  36 + ContainsKey("productAttendanceRecordId").ValueEqual("productAttendanceRecordId", productAttendanceRecordId)
  37 + })
  38 + })
  39 + })
  40 + AfterEach(func() {
  41 + _, err := pG.DB.Exec("DELETE FROM product_attendance_records WHERE true")
  42 + Expect(err).NotTo(HaveOccurred())
  43 + })
  44 +})