作者 yangfu

refactor: 日志修改、员工按拼音排序

... ... @@ -20,9 +20,6 @@ import (
)
func main() {
log.Logger.Info("server start ....")
log.Logger.Info(fmt.Sprintf("ENABLE_KAFKA_LOG:%v", constant.ENABLE_KAFKA_LOG))
if constant.ENABLE_KAFKA_LOG {
w, _ := logrus.NewKafkaWriter(constant.KAFKA_HOST, constant.TOPIC_LOG_STASH, false)
log.Logger.AddHook(w)
... ... @@ -34,6 +31,9 @@ func main() {
})
log.Logger.AddHook(bw)
redis.InitRedis()
log.Logger.Debug("server start ....")
log.Logger.Debug(fmt.Sprintf("ENABLE_KAFKA_LOG:%v", constant.ENABLE_KAFKA_LOG))
go mqtt.Start()
go task.Run()
cron := crontab.NewCrontabService(nil)
... ...
... ... @@ -2,6 +2,7 @@ package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils/converter"
"strings"
)
... ... @@ -19,6 +20,7 @@ type ProductGroupEmployeesDto struct {
WorkOnDescription string `json:"workOn,omitempty"`
// 工作位置键值 (车间ID+'.'+生产线ID+'.'+工段ID)
//WorkStationId string `json:"workStationId,omitempty"`
UserNamePinyin string `json:"pinyin"`
}
func NewProductGroupEmployeesDto(group *domain.ProductGroup) []*ProductGroupEmployeesDto {
... ... @@ -41,6 +43,9 @@ func NewGroupEmployee(group *domain.ProductGroup, u *domain.User) *ProductGroupE
workOns := domain.WorkOnDescription(group.WorkOn)
item.WorkOnDescription = strings.Join(workOns, ",")
//item.WorkStationId = group.WorkStation.WorkStationId
if len(item.UserName) > 0 {
item.UserNamePinyin = converter.ToPinYin(item.UserName, "")
}
return item
}
... ... @@ -72,3 +77,11 @@ func NewProductGroupEmployeesDtos() *ProductGroupEmployeesDtos {
MapResult: make(map[int]*ProductGroupEmployeesDto),
}
}
func (ms *ProductGroupEmployeesDtos) Len() int { return len(ms.Result) }
func (ms *ProductGroupEmployeesDtos) Less(i, j int) bool {
return ms.Result[i].UserNamePinyin < ms.Result[j].UserNamePinyin
}
func (ms *ProductGroupEmployeesDtos) Swap(i, j int) {
ms.Result[i], ms.Result[j] = ms.Result[j], ms.Result[i]
}
... ...
... ... @@ -11,6 +11,7 @@ import (
"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"
"sort"
"time"
)
... ... @@ -401,6 +402,7 @@ func (productGroupService *ProductGroupService) SearchProductGroupEmployees(oper
items := dto.NewProductGroupEmployeesDto(item)
results.Append(items...)
}
sort.Stable(results)
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -3,8 +3,8 @@ package domain
import "time"
const (
ParticipateNormal = 1
ParticipateSupport = 2
ParticipateNormal = 1 // 正常
ParticipateSupport = 2 // 支援
)
const (
... ... @@ -28,7 +28,7 @@ type EmployeeProductRecord struct {
WorkOn int `json:"workOn"`
// 参与类型 1:正常 2:支援
ParticipateType int `json:"participateType"`
// 产能
// 初始产能
ProductWeigh float64 `json:"productWeigh"`
// 二级品产能
SecondLevelWeigh float64 `json:"secondLevelWeigh"`
... ... @@ -72,9 +72,11 @@ func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh flo
employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh = make(map[string]float64)
}
if productRecordType == RecordTypeSecondLevelWeigh {
// 当前工段
if employeeProductRecord.WorkStation.SectionName == sectionName {
employeeProductRecord.SecondLevelWeigh += weigh
} else {
// 其他工段的二级品
if _, ok := employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName]; ok {
employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName] += weigh //存关联级的二级品
} else {
... ...
... ... @@ -12,10 +12,10 @@ type ProductRecordStaticInfo struct {
// 生产小组ID
ProductGroupId int `json:"productGroupId,omitempty"`
TotalOtherSecondLevelWeigh float64 `json:"otherSecondLevelWeigh"`
// 其他工段二级品的重量合计
TotalOtherSecondLevelWeigh float64 `json:"totalOtherSecondLevelWeigh"`
// 保存其他工段二级品的重量
OtherSectionSecondLevelWeigh map[string]float64 `json:"sectionSecondLevelWeigh"`
OtherSectionSecondLevelWeigh map[string]float64 `json:"otherSectionSecondLevelWeigh"`
}
func (info *ProductRecordStaticInfo) OtherSecondLevelWeigh() float64 {
... ...
... ... @@ -12,6 +12,7 @@ type PGApproveAttendanceRecordsService struct {
transactionContext *pgTransaction.TransactionContext
}
// 批量审核考勤记录
func (ptr *PGApproveAttendanceRecordsService) BatchApproveAttendanceRecords(opt *domain.OperateInfo, list []*domain.ProductAttendanceRecord, approveUserId int, workTime float64, status int) (interface{}, error) {
var productAttendanceRecordRepository, _ = repository.NewProductAttendanceRecordRepository(ptr.transactionContext)
var attendance *domain.ProductAttendanceRecord
... ...
package pg
import (
"context"
"fmt"
"github.com/beego/beego/v2/core/logs"
"log"
"reflect"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
"github.com/linmadan/egglib-go/persistent/pg/hooks"
)
var DB *pg.DB
... ... @@ -22,7 +23,7 @@ func init() {
Addr: fmt.Sprintf("%s:%s", constant.POSTGRESQL_HOST, constant.POSTGRESQL_PORT),
})
if !constant.DISABLE_SQL_GENERATE_PRINT {
DB.AddQueryHook(hooks.SqlGeneratePrintHook{})
DB.AddQueryHook(SqlGeneratePrintHook{})
}
if !constant.DISABLE_CREATE_TABLE {
for _, model := range []interface{}{
... ... @@ -59,6 +60,23 @@ func init() {
}
}
type SqlGeneratePrintHook struct{}
func (hook SqlGeneratePrintHook) BeforeQuery(c context.Context, q *pg.QueryEvent) (context.Context, error) {
return c, nil
}
func (hook SqlGeneratePrintHook) AfterQuery(c context.Context, q *pg.QueryEvent) error {
sqlStr, err := q.FormattedQuery()
if err != nil {
return err
}
//log.Logger.Debug(string(sqlStr))
log.Println(string(sqlStr))
logs.Debug(string(sqlStr))
return nil
}
func AddComments(db *pg.DB, model interface{}) {
tableName := db.Model(model).TableModel().Table().SQLName
columnsMap := make(map[string]*orm.Field)
... ...
... ... @@ -12,5 +12,9 @@ func ToPinYin(hans string, sep string) string {
for i := range tmp {
result = append(result, tmp[i]...)
}
return strings.Join(result, sep)
py := strings.Join(result, sep)
if len(py) == 0 {
return strings.ToLower(hans)
}
return py
}
... ...