作者 tangxuhui

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…

…ion-manufacture into dev
正在显示 30 个修改的文件 包含 1328 行增加151 行删除
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ApproveAttendanceCommand struct {
// 考勤记录ID
ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"`
// 工时
WorkTimeAfter float64 `cname:"工时" json:"workTimeAfter,omitempty"`
// 审核人Id
ApproveUserId int `json:"approveUserId,omitempty"`
}
func (approveAttendanceCommand *ApproveAttendanceCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (approveAttendanceCommand *ApproveAttendanceCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(approveAttendanceCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(approveAttendanceCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type CreateAttendanceCommand struct {
// 考勤记录ID
//ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"`
// 考勤类型 1.正常 2.支援
AttendanceType int `json:"attendanceType,omitempty"`
// 生产班组Id
ProductGroupId int `json:"productGroupId,omitempty" valid:"Required"`
// 生产工人
ProductWorkerId int `json:"productWorkerId,omitempty" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 签到
SignIn time.Time `json:"signIn,omitempty"`
// 签退
SignOut time.Time `json:"signOut,omitempty"`
// 考勤状态 1.未审核 2:已审核 3.自动审核
//AttendanceStatus int `json:"attendanceStatus,omitempty"`
}
func (createAttendanceCommand *CreateAttendanceCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createAttendanceCommand *CreateAttendanceCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createAttendanceCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createAttendanceCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RemoveAttendanceCommand struct {
// 考勤记录ID
ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"`
}
func (removeAttendanceCommand *RemoveAttendanceCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeAttendanceCommand *RemoveAttendanceCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeAttendanceCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeAttendanceCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type UpdateAttendanceCommand struct {
// 考勤记录ID
ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"`
}
func (updateAttendanceCommand *UpdateAttendanceCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateAttendanceCommand *UpdateAttendanceCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateAttendanceCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateAttendanceCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
type AttendanceRecordDto struct {
// 考勤记录ID
ProductAttendanceId int `json:"productAttendanceId"`
// 企业id
//CompanyId int `json:"companyId,omitempty"`
// 组织ID
//OrgId int `json:"orgId,omitempty"`
// 考勤类型 1.正常 2.支援
AttendanceType int `json:"attendanceType,omitempty"`
// 生产工人
ProductWorker *domain.User `json:"productWorker,omitempty"`
*domain.ProductAttendanceRecordExt
// 工作位置
*domain.WorkStation
// 签到
SignIn string `json:"signIn"`
// 签退
SignOut string `json:"signOut"`
// 考勤状态 1.未审核 2:已审核 3.自动审核
AttendanceStatus int `json:"attendanceStatus"`
// 工时(审核前)
WorkTimeBefore float64 `json:"workTimeBefore"`
// 工时(审核后)
WorkTimeAfter float64 `json:"workTimeAfter"`
// 签到日期
SignDate string `json:"signDate"`
// 组织名称
OrgName string `json:"orgName"`
// 权限标识 (当前登录组织匹配为true,否则false)
AuthFlag bool `json:"authFlag"`
}
func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId int) *AttendanceRecordDto {
d.ProductAttendanceId = m.ProductAttendanceId
d.AttendanceType = m.AttendanceType
d.ProductWorker = m.ProductWorker
d.WorkStation = m.WorkStation
if !m.SignIn.IsZero() {
d.SignIn = m.SignIn.Format("15:04:05")
d.SignDate = m.SignIn.Format("2006-01-02")
}
if !m.SignOut.IsZero() {
d.SignOut = m.SignOut.Format("15:04:05")
}
d.WorkTimeBefore = m.WorkTimeBefore
d.WorkTimeAfter = m.WorkTimeAfter
d.AttendanceStatus = m.AttendanceStatus
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
d.ProductAttendanceRecordExt = m.Ext.AttendanceExt
}
return d
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetAttendanceQuery struct {
// 考勤记录ID
ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"`
}
func (getAttendanceQuery *GetAttendanceQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getAttendanceQuery *GetAttendanceQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getAttendanceQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getAttendanceQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ListAttendanceQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listAttendanceQuery *ListAttendanceQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listAttendanceQuery *ListAttendanceQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listAttendanceQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listAttendanceQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package query
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type SearchAttendanceQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset"`
// 查询限制
Limit int `cname:"查询限制" json:"limit"`
// 当前公司
CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
// 当前登录的组织
OrgId int `cname:"当前登录的组织" json:"orgId,omitempty" `
// 匹配多个组织
InOrgIds []int `cname:"匹配多个组织" json:"inOrgIds,omitempty" `
// 页码
PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
// 页数
PageSize int `cname:"页数" json:"pageSize,omitempty"`
// 车间名称
WorkshopName string `cname:"车间名称" json:"workshopName,omitempty"`
// 姓名
UserName string `cname:"姓名" json:"userName,omitempty"`
// 考勤状态 1.未审核 2:已审核 3.自动审核
AttendanceStatus int `cname:"考勤状态 1.未审核 2:已审核 3.自动审核" json:"attendanceStatus,omitempty"`
}
func (cmd *SearchAttendanceQuery) Valid(validation *validation.Validation) {
cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize)
}
func (cmd *SearchAttendanceQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(cmd)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(cmd).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"time"
)
type AttendanceService struct {
}
// 审核工时
func (attendanceService *AttendanceService) ApproveAttendance(cmd *command.ApproveAttendanceCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var productAttendanceRecordRepository domain.ProductAttendanceRecordRepository
var attendance *domain.ProductAttendanceRecord
productAttendanceRecordRepository, attendance, err = factory.FastPgAttendance(transactionContext, cmd.ProductAttendanceId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var user *domain.User
userService := domainService.NewUserService()
user, err = userService.User(cmd.ApproveUserId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err = attendance.Approve(user, cmd.WorkTimeAfter); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if _, err := productAttendanceRecordRepository.Save(attendance); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct{}{}, nil
}
// 创建
func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain.OperateInfo, cmd *command.CreateAttendanceCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var user *domain.User
userService := domainService.NewUserService()
user, err = userService.User(cmd.ProductWorkerId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var workStation *domain.WorkStation
_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var org *domain.Org
org, err = userService.Organization(operateInfo.OrgId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var productGroup *domain.ProductGroup
_, productGroup, err = factory.FastPgProductGroup(transactionContext, cmd.ProductGroupId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
newAttendance := &domain.ProductAttendanceRecord{
//ProductAttendanceId: cmd.ProductAttendanceId,
CompanyId: operateInfo.CompanyId,
OrgId: operateInfo.OrgId,
AttendanceType: cmd.AttendanceType,
ProductWorker: user,
WorkStation: workStation,
SignIn: cmd.SignIn,
SignOut: cmd.SignOut,
AttendanceStatus: domain.AttendanceNotApprove,
WorkTimeBefore: 0,
WorkTimeAfter: 0,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Ext: domain.NewExt(org.OrgName).WithAttendanceExt(&domain.ProductAttendanceRecordExt{
GroupName: productGroup.GroupName,
ProductGroupId: productGroup.ProductGroupId,
}),
}
var attendanceRepository domain.ProductAttendanceRecordRepository
attendanceRepository, _, _ = factory.FastPgAttendance(transactionContext, 0)
if attendance, err := attendanceRepository.Save(newAttendance); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return attendance, nil
}
}
// 返回
func (attendanceService *AttendanceService) GetAttendance(getAttendanceQuery *query.GetAttendanceQuery) (interface{}, error) {
if err := getAttendanceQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
//var attendanceRepository domain.ProductAttendanceRecordRepository
var attendance *domain.ProductAttendanceRecord
_, attendance, err = factory.FastPgAttendance(transactionContext, getAttendanceQuery.ProductAttendanceId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
result := &dto.AttendanceRecordDto{}
result.LoadDto(attendance, 0)
return result, nil
}
// 返回列表
func (attendanceService *AttendanceService) ListAttendance(listAttendanceQuery *query.ListAttendanceQuery) (interface{}, error) {
if err := listAttendanceQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
//var attendanceRepository attendance.AttendanceRepository
//if value, err := factory.CreateAttendanceRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// attendanceRepository = value
//}
//if count, attendances, err := attendanceRepository.Find(tool_funs.SimpleStructToMap(listAttendanceQuery)); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// return map[string]interface{}{
// "count": count,
// "attendances": attendances,
// }, nil
//}
return nil, nil
}
// 移除
func (attendanceService *AttendanceService) RemoveAttendance(removeAttendanceCommand *command.RemoveAttendanceCommand) (interface{}, error) {
if err := removeAttendanceCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var attendanceRepository domain.ProductAttendanceRecordRepository
var attendance *domain.ProductAttendanceRecord
attendanceRepository, attendance, err = factory.FastPgAttendance(transactionContext, removeAttendanceCommand.ProductAttendanceId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if attendance, err := attendanceRepository.Remove(attendance); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return attendance, nil
}
}
// 更新
func (attendanceService *AttendanceService) UpdateAttendance(updateAttendanceCommand *command.UpdateAttendanceCommand) (interface{}, error) {
if err := updateAttendanceCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
//var attendanceRepository attendance.AttendanceRepository
//if value, err := factory.CreateAttendanceRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// attendanceRepository = value
//}
//attendance, err := attendanceRepository.FindOne(map[string]interface{}{"attendanceId": updateAttendanceCommand.AttendanceId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if attendance == nil {
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateAttendanceCommand.AttendanceId)))
//}
//if err := attendance.Update(tool_funs.SimpleStructToMap(updateAttendanceCommand)); err != nil {
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
//}
//if attendance, err := attendanceRepository.Save(attendance); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// return attendance, nil
//}
return nil, nil
}
// 返回列表
func (attendanceService *AttendanceService) SearchAttendance(operateInfo *domain.OperateInfo, cmd *query.SearchAttendanceQuery) (int64, interface{}, error) {
if err := cmd.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var attendanceRepository domain.ProductAttendanceRecordRepository
attendanceRepository, _, _ = factory.FastPgAttendance(transactionContext, 0)
queryOptions := utils.ObjectToMap(cmd)
count, attendances, err := attendanceRepository.Find(queryOptions)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var result = make([]*dto.AttendanceRecordDto, 0)
for i := range attendances {
newItem := &dto.AttendanceRecordDto{}
result = append(result, newItem.LoadDto(attendances[i], operateInfo.OrgId))
}
return count, result, nil
}
func NewAttendanceService(options map[string]interface{}) *AttendanceService {
newAttendanceService := &AttendanceService{}
return newAttendanceService
}
... ...
... ... @@ -283,6 +283,32 @@ func FastPgProductPlan(transactionContext application.TransactionContext, id int
return rep, mod, err
}
// FastPgAttendance 快速返回考勤记录
//
// transactionContext 事务
// id 对象唯一标识
func FastPgAttendance(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductAttendanceRecordRepository, *domain.ProductAttendanceRecord, error) {
var rep domain.ProductAttendanceRecordRepository
var mod *domain.ProductAttendanceRecord
var err error
if value, err := CreateProductAttendanceRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productAttendanceRecordId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该考勤记录不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
return rep, mod, err
}
/***** 2.配置 *****/
type FastOptions struct {
... ...
... ... @@ -30,6 +30,17 @@ type ProductJobDto struct {
//OrgName string `json:"orgName"`
// 权限标识 (当前登录组织匹配为true,否则false)
//AuthFlag bool `json:"authFlag"`
// 关联设备列表
RelatedDevices []DeviceDto `json:"relatedDevices,omitempty"`
}
type DeviceDto struct {
// 设备Id
DeviceId int `json:"deviceId,omitempty"`
// 设备编号
DeviceCode string `json:"deviceCode,omitempty"`
// 设备名称
DeviceName string `json:"deviceName,omitempty"`
}
func (d *ProductJobDto) LoadDto(job *domain.ProductJob, orgId int) {
... ... @@ -42,3 +53,14 @@ func (d *ProductJobDto) LoadDto(job *domain.ProductJob, orgId int) {
// d.OrgName = job.Ext.OrgName
//}
}
func (d *ProductJobDto) WithRelatedDevices(devices []*domain.Device) *ProductJobDto {
for i := range devices {
d.RelatedDevices = append(d.RelatedDevices, DeviceDto{
DeviceName: devices[i].DeviceName,
DeviceId: devices[i].DeviceId,
DeviceCode: devices[i].DeviceCode,
})
}
return d
}
... ...
... ... @@ -97,9 +97,23 @@ func (productJobService *ProductJobService) GetProductJob(getProductJobQuery *qu
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
productJob.WorkStation, _ = workshop.FindWorkStation(productJob.WorkStation.WorkshopId, productJob.WorkStation.LineId, productJob.WorkStation.SectionId)
newJobDto := &dto.ProductJobDto{}
newJobDto.LoadDto(productJob, 0)
if len(productJob.RelatedDevices) > 0 {
deviceRepository, _, _ := factory.FastPgDevice(transactionContext, 0)
_, devices, err := deviceRepository.Find(map[string]interface{}{
"companyId": productJob.CompanyId,
"orgId": productJob.OrgId,
"inDeviceId": productJob.RelatedDevices,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
newJobDto.WithRelatedDevices(devices)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -159,27 +159,6 @@ func (productPlanService *ProductPlanService) ListProductPlan(listProductPlanQue
}
}
// 领料
func (productPlanService *ProductPlanService) ReceiveMaterial(receiveMaterialCommand *command.ReceiveMaterialCommand) (interface{}, error) {
if err := receiveMaterialCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 移除生产计划服务
func (productPlanService *ProductPlanService) RemoveProductPlan(removeProductPlanCommand *command.RemoveProductPlanCommand) (interface{}, error) {
if err := removeProductPlanCommand.ValidateCommand(); err != nil {
... ... @@ -220,9 +199,9 @@ func (productPlanService *ProductPlanService) RemoveProductPlan(removeProductPla
}
}
// 退料
func (productPlanService *ProductPlanService) ReturnMaterial(returnMaterialCommand *command.ReturnMaterialCommand) (interface{}, error) {
if err := returnMaterialCommand.ValidateCommand(); err != nil {
// 更新生产计划服务
func (productPlanService *ProductPlanService) UpdateProductPlan(cmd *command.UpdateProductPlanCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -235,10 +214,79 @@ func (productPlanService *ProductPlanService) ReturnMaterial(returnMaterialComma
defer func() {
transactionContext.RollbackTransaction()
}()
var productPlanRepository domain.ProductPlanRepository
var productPlan *domain.ProductPlan
productPlanRepository, productPlan, err = factory.FastPgProductPlan(transactionContext, cmd.ProductPlanId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//if productPlan.Workshop.WorkshopId != cmd.WorkshopId{
// // 检查批次号是否有重复的
// if item, err := productPlanRepository.FindOne(map[string]interface{}{"companyId": cmd.CompanyId, "orgId": cmd.OrgId, "batchNumber": cmd.BatchNumber}); err == nil && item != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "批次号重复")
// }
//}
_, workshop, err := factory.FastPgWorkshop(transactionContext, cmd.WorkshopId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
productPlan.Workshop = workshop.CloneSample()
if err := productPlan.Update(tool_funs.SimpleStructToMap(cmd)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if productPlan, err = productPlanRepository.Save(productPlan); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
result := &dto.ProductPlanDto{}
return result.LoadDto(productPlan, cmd.OrgId), nil
}
// 搜索生产计划服务列表
func (productPlanService *ProductPlanService) SearchProductPlan(operateInfo *domain.OperateInfo, cmd *query.SearchProductPlanQuery) (int64, interface{}, error) {
if err := cmd.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var productPlanRepository domain.ProductPlanRepository
if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productPlanRepository = value
}
count, productPlans, err := productPlanRepository.Find(utils.ObjectToMap(cmd))
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var result = make([]*dto.ProductPlanDto, 0)
for i := range productPlans {
item := productPlans[i]
newItem := &dto.ProductPlanDto{}
newItem.LoadDto(item, operateInfo.OrgId)
result = append(result, newItem)
}
return count, result, nil
}
// 计划下线
... ... @@ -331,27 +379,6 @@ func (productPlanService *ProductPlanService) SetOnline(cmd *command.SetOnlineCo
return productPlan, nil
}
// 提交成品记录 (成品 二级品)
func (productPlanService *ProductPlanService) SubmitProductRecord(submitProductRecordCommand *command.SubmitProductRecordCommand) (interface{}, error) {
if err := submitProductRecordCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 换单
func (productPlanService *ProductPlanService) Exchange(switchCommand *command.SwitchCommand) (interface{}, error) {
if err := switchCommand.ValidateCommand(); err != nil {
... ... @@ -407,9 +434,9 @@ func (productPlanService *ProductPlanService) Exchange(switchCommand *command.Sw
return struct{}{}, nil
}
// 更新生产计划服务
func (productPlanService *ProductPlanService) UpdateProductPlan(cmd *command.UpdateProductPlanCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
// 领料
func (productPlanService *ProductPlanService) ReceiveMaterial(receiveMaterialCommand *command.ReceiveMaterialCommand) (interface{}, error) {
if err := receiveMaterialCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -422,79 +449,52 @@ func (productPlanService *ProductPlanService) UpdateProductPlan(cmd *command.Upd
defer func() {
transactionContext.RollbackTransaction()
}()
var productPlanRepository domain.ProductPlanRepository
var productPlan *domain.ProductPlan
productPlanRepository, productPlan, err = factory.FastPgProductPlan(transactionContext, cmd.ProductPlanId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
//if productPlan.Workshop.WorkshopId != cmd.WorkshopId{
// // 检查批次号是否有重复的
// if item, err := productPlanRepository.FindOne(map[string]interface{}{"companyId": cmd.CompanyId, "orgId": cmd.OrgId, "batchNumber": cmd.BatchNumber}); err == nil && item != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "批次号重复")
// }
//}
_, workshop, err := factory.FastPgWorkshop(transactionContext, cmd.WorkshopId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// 退料
func (productPlanService *ProductPlanService) ReturnMaterial(returnMaterialCommand *command.ReturnMaterialCommand) (interface{}, error) {
if err := returnMaterialCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
productPlan.Workshop = workshop.CloneSample()
if err := productPlan.Update(tool_funs.SimpleStructToMap(cmd)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if productPlan, err = productPlanRepository.Save(productPlan); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
result := &dto.ProductPlanDto{}
return result.LoadDto(productPlan, cmd.OrgId), nil
return nil, nil
}
// 搜索生产计划服务列表
func (productPlanService *ProductPlanService) SearchProductPlan(operateInfo *domain.OperateInfo, cmd *query.SearchProductPlanQuery) (int64, interface{}, error) {
if err := cmd.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
// 提交成品记录 (成品 二级品)
func (productPlanService *ProductPlanService) SubmitProductRecord(submitProductRecordCommand *command.SubmitProductRecordCommand) (interface{}, error) {
if err := submitProductRecordCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var productPlanRepository domain.ProductPlanRepository
if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productPlanRepository = value
}
count, productPlans, err := productPlanRepository.Find(utils.ObjectToMap(cmd))
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var result = make([]*dto.ProductPlanDto, 0)
for i := range productPlans {
item := productPlans[i]
newItem := &dto.ProductPlanDto{}
newItem.LoadDto(item, operateInfo.OrgId)
result = append(result, newItem)
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return count, result, nil
return nil, nil
}
func NewProductPlanService(options map[string]interface{}) *ProductPlanService {
... ...
... ... @@ -4,7 +4,6 @@ import (
"fmt"
"os"
"strconv"
"strings"
)
var SERVICE_NAME = "allied-creation-manufacture"
... ... @@ -37,21 +36,21 @@ func init() {
if os.Getenv("LOG_LEVEL") != "" {
LOG_LEVEL = os.Getenv("LOG_LEVEL")
}
if os.Getenv("CUSTOMER_ACCOUNT") != "" {
account := os.Getenv("CUSTOMER_ACCOUNT")
accounts := strings.Split(account, CUSTOMER_ACCOUNT_DELIMITER)
var tmpAccounts []int64
for i := range accounts {
v, err := strconv.ParseInt(accounts[i], 10, 64)
if err != nil {
panic(err)
}
tmpAccounts = append(tmpAccounts, v)
}
if len(tmpAccounts) > 0 {
CUSTOMER_ACCOUNT = tmpAccounts
}
}
//if os.Getenv("CUSTOMER_ACCOUNT") != "" {
// account := os.Getenv("CUSTOMER_ACCOUNT")
// accounts := strings.Split(account, CUSTOMER_ACCOUNT_DELIMITER)
// var tmpAccounts []int64
// for i := range accounts {
// v, err := strconv.ParseInt(accounts[i], 10, 64)
// if err != nil {
// panic(err)
// }
// tmpAccounts = append(tmpAccounts, v)
// }
// if len(tmpAccounts) > 0 {
// CUSTOMER_ACCOUNT = tmpAccounts
// }
//}
if os.Getenv("ALLIED_CREATION_BASIC_HOST") != "" {
ALLIED_CREATION_BASIC_HOST = os.Getenv("ALLIED_CREATION_BASIC_HOST")
... ...
... ... @@ -6,7 +6,10 @@ type Ext struct {
OrgName string `json:"orgName,omitempty"`
// 设备扩展数据
DeviceExt *DeviceExt `json:"deviceExt"`
DeviceExt *DeviceExt `json:"deviceExt,omitempty"`
// 考勤记录扩展
AttendanceExt *ProductAttendanceRecordExt `json:"attendanceExt,omitempty"`
}
func NewExt(orgName string) *Ext {
... ... @@ -19,3 +22,8 @@ func (e *Ext) WithDeviceExt(deviceExt *DeviceExt) *Ext {
e.DeviceExt = deviceExt
return e
}
func (e *Ext) WithAttendanceExt(ext *ProductAttendanceRecordExt) *Ext {
e.AttendanceExt = ext
return e
}
... ...
package domain
import "time"
import (
"errors"
"time"
)
const (
AttendanceNotApprove = 1 // 未审核
AttendanceApproved = 2 // 已审核
)
// 生产考勤记录
type ProductAttendanceRecord struct {
// 考勤记录ID
ProductAttendanceId int `json:"productAttendanceId,omitempty"`
// 企业id
CompanyId int `json:"companyId,omitempty"`
// 组织ID
OrgId int `json:"orgId,omitempty"`
// 产品ID
ProductId int `json:"productId,omitempty"`
// 考勤类型 1.正常 2.支援
AttendanceType int `json:"attendanceType,omitempty"`
// 生产工人
... ... @@ -57,9 +65,6 @@ func (productAttendanceRecord *ProductAttendanceRecord) Update(data map[string]i
if orgId, ok := data["orgId"]; ok {
productAttendanceRecord.OrgId = orgId.(int)
}
if productId, ok := data["productId"]; ok {
productAttendanceRecord.ProductId = productId.(int)
}
if attendanceType, ok := data["attendanceType"]; ok {
productAttendanceRecord.AttendanceType = attendanceType.(int)
}
... ... @@ -128,3 +133,17 @@ func (productAttendanceRecord *ProductAttendanceRecord) Update(data map[string]i
}
return nil
}
func (productAttendanceRecord *ProductAttendanceRecord) Approve(approveUser *User, workTimeAfter float64) error {
if productAttendanceRecord.AttendanceStatus == AttendanceApproved {
return errors.New("已审核")
}
productAttendanceRecord.AttendanceStatus = AttendanceApproved
productAttendanceRecord.WorkTimeAfter = workTimeAfter
if productAttendanceRecord.Ext != nil && productAttendanceRecord.Ext.AttendanceExt != nil {
productAttendanceRecord.Ext.AttendanceExt.ApproveUserId = approveUser.UserId
productAttendanceRecord.Ext.AttendanceExt.ApproveUserName = approveUser.UserName
productAttendanceRecord.Ext.AttendanceExt.ApproveAt = time.Now().Unix()
}
return nil
}
... ...
package domain
// ProductAttendanceRecordExt 生产考勤扩展
type ProductAttendanceRecordExt struct {
// 生产小组ID
ProductGroupId int `json:"productGroupId,omitempty"`
// 班组名称
GroupName string `json:"groupName,omitempty"`
// 审核人Id
ApproveUserId int `json:"approveUserId,omitempty"`
// 审核人名称
ApproveUserName string `json:"approveUserName,omitempty"`
// 审核时间
ApproveAt int64 `json:"approveAt,omitempty"`
}
... ...
... ... @@ -8,13 +8,11 @@ import (
type ProductAttendanceRecord struct {
tableName string `comment:"生产考勤记录" pg:"manufacture.product_attendance_record,alias:product_attendance_record"`
// 考勤记录ID
ProductAttendanceId int `comment:"考勤记录ID"`
ProductAttendanceId int `comment:"考勤记录ID" pg:"pk:product_attendance_id"`
// 企业id
CompanyId int `comment:"企业id"`
// 组织ID
OrgId int `comment:"组织ID"`
// 产品ID
ProductId int `comment:"产品ID"`
// 考勤类型 1.正常 2.支援
AttendanceType int `comment:"考勤类型 1.正常 2.支援"`
// 生产工人
... ...
... ... @@ -9,7 +9,7 @@ func TransformToProductAttendanceRecordDomainModelFromPgModels(productAttendance
return &domain.ProductAttendanceRecord{
ProductAttendanceId: productAttendanceRecordModel.ProductAttendanceId,
OrgId: productAttendanceRecordModel.OrgId,
ProductId: productAttendanceRecordModel.ProductId,
CompanyId: productAttendanceRecordModel.CompanyId,
AttendanceType: productAttendanceRecordModel.AttendanceType,
ProductWorker: productAttendanceRecordModel.ProductWorker,
WorkStation: productAttendanceRecordModel.WorkStation,
... ...
... ... @@ -171,6 +171,9 @@ func (repository *DeviceRepository) Find(queryOptions map[string]interface{}) (i
if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 {
query.Where(`org_id in (?)`, pg.In(v))
}
if v, ok := queryOptions["inDeviceId"]; ok && len(v.([]int)) > 0 {
query.Where(`device_id in (?)`, pg.In(v))
}
query.SetWhereByQueryOption("device_code = ?", "deviceCode")
query.SetWhereByQueryOption("device_status = ?", "deviceStatus")
if v, ok := queryOptions["deviceName"]; ok && len(v.(string)) > 0 {
... ...
... ... @@ -28,7 +28,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
sqlBuildFields := []string{
"product_attendance_id",
"org_id",
"product_id",
"company_id",
"attendance_type",
"product_worker",
"work_station",
... ... @@ -42,24 +42,18 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
"deleted_at",
"ext",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_attendance_id", "deleted_at"))
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_attendance_id", "deleted_at"))
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "productAttendanceRecord_id")
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_attendance_id", "deleted_at")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if productAttendanceRecord.Identify() == nil {
productAttendanceRecordId, err := repository.nextIdentify()
if err != nil {
return productAttendanceRecord, err
} else {
productAttendanceRecord.ProductAttendanceId = int(productAttendanceRecordId)
}
if _, err := tx.QueryOne(
pg.Scan(
&productAttendanceRecord.ProductAttendanceId,
&productAttendanceRecord.OrgId,
&productAttendanceRecord.ProductId,
&productAttendanceRecord.CompanyId,
&productAttendanceRecord.AttendanceType,
&productAttendanceRecord.ProductWorker,
&productAttendanceRecord.WorkStation,
... ... @@ -73,10 +67,10 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
&productAttendanceRecord.DeletedAt,
&productAttendanceRecord.Ext,
),
fmt.Sprintf("INSERT INTO product_attendance_records (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
productAttendanceRecord.ProductAttendanceId,
fmt.Sprintf("INSERT INTO manufacture.product_attendance_record (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
//productAttendanceRecord.ProductAttendanceId,
productAttendanceRecord.OrgId,
productAttendanceRecord.ProductId,
productAttendanceRecord.CompanyId,
productAttendanceRecord.AttendanceType,
productAttendanceRecord.ProductWorker,
productAttendanceRecord.WorkStation,
... ... @@ -87,7 +81,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
productAttendanceRecord.WorkTimeAfter,
productAttendanceRecord.CreatedAt,
productAttendanceRecord.UpdatedAt,
productAttendanceRecord.DeletedAt,
//productAttendanceRecord.DeletedAt,
productAttendanceRecord.Ext,
); err != nil {
return productAttendanceRecord, err
... ... @@ -97,7 +91,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
pg.Scan(
&productAttendanceRecord.ProductAttendanceId,
&productAttendanceRecord.OrgId,
&productAttendanceRecord.ProductId,
&productAttendanceRecord.CompanyId,
&productAttendanceRecord.AttendanceType,
&productAttendanceRecord.ProductWorker,
&productAttendanceRecord.WorkStation,
... ... @@ -111,10 +105,10 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
&productAttendanceRecord.DeletedAt,
&productAttendanceRecord.Ext,
),
fmt.Sprintf("UPDATE product_attendance_records SET %s WHERE product_attendance_record_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
productAttendanceRecord.ProductAttendanceId,
fmt.Sprintf("UPDATE manufacture.product_attendance_record SET %s WHERE product_attendance_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
//productAttendanceRecord.ProductAttendanceId,
productAttendanceRecord.OrgId,
productAttendanceRecord.ProductId,
productAttendanceRecord.CompanyId,
productAttendanceRecord.AttendanceType,
productAttendanceRecord.ProductWorker,
productAttendanceRecord.WorkStation,
... ... @@ -125,7 +119,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
productAttendanceRecord.WorkTimeAfter,
productAttendanceRecord.CreatedAt,
productAttendanceRecord.UpdatedAt,
productAttendanceRecord.DeletedAt,
//productAttendanceRecord.DeletedAt,
productAttendanceRecord.Ext,
productAttendanceRecord.Identify(),
); err != nil {
... ... @@ -147,7 +141,7 @@ func (repository *ProductAttendanceRecordRepository) FindOne(queryOptions map[st
tx := repository.transactionContext.PgTx
productAttendanceRecordModel := new(models.ProductAttendanceRecord)
query := sqlbuilder.BuildQuery(tx.Model(productAttendanceRecordModel), queryOptions)
query.SetWhereByQueryOption("product_attendance_record.product_attendance_record_id = ?", "productAttendanceRecordId")
query.SetWhereByQueryOption("product_attendance_record.product_attendance_id = ?", "productAttendanceRecordId")
if v, ok := queryOptions["includeDeleted"]; ok && v.(bool) {
query.AllWithDeleted()
}
... ... @@ -169,8 +163,20 @@ func (repository *ProductAttendanceRecordRepository) Find(queryOptions map[strin
var productAttendanceRecordModels []*models.ProductAttendanceRecord
productAttendanceRecords := make([]*domain.ProductAttendanceRecord, 0)
query := sqlbuilder.BuildQuery(tx.Model(&productAttendanceRecordModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("product_attendance_record_id", "DESC")
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
query.SetWhereByQueryOption("attendance_status = ?", "attendanceStatus")
if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 {
query.Where(`org_id in (?)`, pg.In(v))
}
if v, ok := queryOptions["userName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`product_worker->>'userName' like '%%%v%%'`, v))
}
if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`work_station->>'workshopName' like '%%%v%%'`, v))
}
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("product_attendance_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, productAttendanceRecords, err
} else {
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/service"
)
type AttendanceController struct {
beego.BaseController
}
func (controller *AttendanceController) CreateAttendance() {
attendanceService := service.NewAttendanceService(nil)
createAttendanceCommand := &command.CreateAttendanceCommand{}
controller.Unmarshal(createAttendanceCommand)
data, err := attendanceService.CreateAttendance(ParseOperateInfo(controller.BaseController), createAttendanceCommand)
controller.Response(data, err)
}
func (controller *AttendanceController) UpdateAttendance() {
attendanceService := service.NewAttendanceService(nil)
updateAttendanceCommand := &command.UpdateAttendanceCommand{}
controller.Unmarshal(updateAttendanceCommand)
productAttendanceId, _ := controller.GetInt(":productAttendanceId")
updateAttendanceCommand.ProductAttendanceId = productAttendanceId
data, err := attendanceService.UpdateAttendance(updateAttendanceCommand)
controller.Response(data, err)
}
func (controller *AttendanceController) GetAttendance() {
attendanceService := service.NewAttendanceService(nil)
getAttendanceQuery := &query.GetAttendanceQuery{}
productAttendanceId, _ := controller.GetInt(":productAttendanceId")
getAttendanceQuery.ProductAttendanceId = productAttendanceId
data, err := attendanceService.GetAttendance(getAttendanceQuery)
controller.Response(data, err)
}
func (controller *AttendanceController) RemoveAttendance() {
attendanceService := service.NewAttendanceService(nil)
removeAttendanceCommand := &command.RemoveAttendanceCommand{}
controller.Unmarshal(removeAttendanceCommand)
productAttendanceId, _ := controller.GetInt(":productAttendanceId")
removeAttendanceCommand.ProductAttendanceId = productAttendanceId
data, err := attendanceService.RemoveAttendance(removeAttendanceCommand)
controller.Response(data, err)
}
func (controller *AttendanceController) ListAttendance() {
attendanceService := service.NewAttendanceService(nil)
listAttendanceQuery := &query.ListAttendanceQuery{}
offset, _ := controller.GetInt("offset")
listAttendanceQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listAttendanceQuery.Limit = limit
data, err := attendanceService.ListAttendance(listAttendanceQuery)
controller.Response(data, err)
}
func (controller *AttendanceController) ApproveAttendance() {
attendanceService := service.NewAttendanceService(nil)
approveAttendanceCommand := &command.ApproveAttendanceCommand{}
controller.Unmarshal(approveAttendanceCommand)
data, err := attendanceService.ApproveAttendance(approveAttendanceCommand)
controller.Response(data, err)
}
func (controller *AttendanceController) SearchAttendance() {
attendanceService := service.NewAttendanceService(nil)
cmd := &query.SearchAttendanceQuery{}
controller.Unmarshal(cmd)
operateInfo := ParseOperateInfo(controller.BaseController)
//cmd.OrgId = operateInfo.OrgId
cmd.CompanyId = operateInfo.CompanyId
cmd.InOrgIds = operateInfo.OrgIds
total, data, err := attendanceService.SearchAttendance(operateInfo, cmd)
ResponseGrid(controller.BaseController, total, data, err)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego/controllers"
)
func init() {
web.Router("/attendances/", &controllers.AttendanceController{}, "Post:CreateAttendance")
web.Router("/attendances/:productAttendanceId", &controllers.AttendanceController{}, "Put:UpdateAttendance")
web.Router("/attendances/:productAttendanceId", &controllers.AttendanceController{}, "Get:GetAttendance")
web.Router("/attendances/:productAttendanceId", &controllers.AttendanceController{}, "Delete:RemoveAttendance")
web.Router("/attendances/", &controllers.AttendanceController{}, "Get:ListAttendance")
web.Router("/attendances/approve", &controllers.AttendanceController{}, "Post:ApproveAttendance")
web.Router("/attendances/search", &controllers.AttendanceController{}, "Post:SearchAttendance")
}
... ...
package attendance
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
)
var _ = Describe("审核工时", func() {
var productAttendanceRecordId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&productAttendanceRecordId),
"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",
"testProductAttendanceId", "testOrgId", "testProductId", "testAttendanceType", "testProductWorker", "testWorkStation", "testSignIn", "testSignOut", "testAttendanceStatus", "testWorkTimeBefore", "testWorkTimeAfter", "testCreatedAt", "testUpdatedAt", "testDeletedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("审核工时", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"productAttendanceId": "int",
"workTimeAfter": "float64",
}
httpExpect.POST("/attendances/approve").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM product_attendance_records WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package attendance
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/beego/beego/v2/server/web"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego"
)
func TestAttendance(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port Attendance Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = BeforeSuite(func() {
handler = web.BeeApp.Handlers
server = httptest.NewServer(handler)
})
var _ = AfterSuite(func() {
server.Close()
})
... ...
package attendance
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
)
var _ = Describe("创建", func() {
Describe("提交数据创建", func() {
Context("提交正确的新生产考勤记录数据", func() {
It("返回生产考勤记录数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"productAttendanceId": "int",
}
httpExpect.POST("/attendances/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("productAttendanceRecordId").ValueNotEqual("productAttendanceRecordId", BeZero())
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM product_attendance_records WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package attendance
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
)
var _ = Describe("返回", func() {
var productAttendanceRecordId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&productAttendanceRecordId),
"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",
"testProductAttendanceId", "testOrgId", "testProductId", "testAttendanceType", "testProductWorker", "testWorkStation", "testSignIn", "testSignOut", "testAttendanceStatus", "testWorkTimeBefore", "testWorkTimeAfter", "testCreatedAt", "testUpdatedAt", "testDeletedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据productAttendanceRecordId参数返回生产考勤记录", func() {
Context("传入有效的productAttendanceRecordId", func() {
It("返回生产考勤记录数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/attendances/{productAttendanceId}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM product_attendance_records WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package attendance
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
)
var _ = Describe("返回列表", func() {
var productAttendanceRecordId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&productAttendanceRecordId),
"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",
"testProductAttendanceId", "testOrgId", "testProductId", "testAttendanceType", "testProductWorker", "testWorkStation", "testSignIn", "testSignOut", "testAttendanceStatus", "testWorkTimeBefore", "testWorkTimeAfter", "testCreatedAt", "testUpdatedAt", "testDeletedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回生产考勤记录列表", func() {
Context("传入有效的参数", func() {
It("返回生产考勤记录数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/attendances/").
WithQuery("offset", "int").
WithQuery("limit", "int").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
ContainsKey("productAttendanceRecords").Value("productAttendanceRecords").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM product_attendance_records WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package attendance
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
)
var _ = Describe("移除", func() {
var productAttendanceRecordId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&productAttendanceRecordId),
"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",
"testProductAttendanceId", "testOrgId", "testProductId", "testAttendanceType", "testProductWorker", "testWorkStation", "testSignIn", "testSignOut", "testAttendanceStatus", "testWorkTimeBefore", "testWorkTimeAfter", "testCreatedAt", "testUpdatedAt", "testDeletedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除", func() {
Context("传入有效的productAttendanceRecordId", func() {
It("返回被移除生产考勤记录的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/attendances/{productAttendanceId}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM product_attendance_records WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package attendance
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
)
var _ = Describe("更新", func() {
var productAttendanceRecordId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&productAttendanceRecordId),
"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",
"testProductAttendanceId", "testOrgId", "testProductId", "testAttendanceType", "testProductWorker", "testWorkStation", "testSignIn", "testSignOut", "testAttendanceStatus", "testWorkTimeBefore", "testWorkTimeAfter", "testCreatedAt", "testUpdatedAt", "testDeletedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新", func() {
Context("提交正确的生产考勤记录数据", func() {
It("返回更新后的生产考勤记录数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{}
httpExpect.PUT("/attendances/{productAttendanceId}").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("productAttendanceRecordId").ValueEqual("productAttendanceRecordId", productAttendanceRecordId)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM product_attendance_records WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...