作者 yangfu

refactor:rebase git log

FROM golang:alpine
ENV APP_DIR $GOPATH/src/project-20211220
ENV POSTGRESQL_DB_NAME="" \
POSTGRESQL_USER="" \
POSTGRESQL_PASSWORD="" \
POSTGRESQL_HOST="" \
POSTGRESQL_PORT="" \
REDIS_HOST="" \
REDIS_PORT="" \
REDIS_AUTH="" \
LOG_LEVEL="debug" \
ERROR_BASE_CODE="1" \
ERROR_BASE_CODE_MULTIPLE="2000" \
ENABLE_KAFKA_LOG="false" \
HTTP_PORT="8082" \
SERVICE_ENV="prd" \
ALLIED_CREATION_USER_HOST="https://allied-creation-user-prd.fjmaimaimai.com" \
MANUFACTURE_DEFAULT_COMPANYID="1" \
MANUFACTURE_DEFAULT_ORGID="1" \
MANUFACTURE_DEFAULT_WORKSHOPID="2" \
MANUFACTURE_PRODUCT_TYPE="0502010004ST,0502010004ST" \
MQTT_HOST="47.97.5.102" \
MQTT_PORT="6000"
RUN mkdir -p $APP_DIR
WORKDIR $APP_DIR/
COPY ./pkg pkg
COPY ./config config
COPY ./go.mod go.mod
COPY ./go.sum go.sum
COPY ./main.go main.go
RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"]
ENV GO111MODULE on
ENV GOPROXY https://goproxy.cn
RUN ["go","mod","tidy"]
RUN ["go","build"]
RUN ["ls"]
ENTRYPOINT ["./allied-creation-manufacture"]
\ No newline at end of file
... ...
... ... @@ -118,6 +118,8 @@ spec:
value: "23"
- name: MANUFACTURE_DEFAULT_ORGID
value: "487"
- name: MANUFACTURE_DEFAULT_WORKSHOPID
value: "2"
- name: MANUFACTURE_PRODUCT_TYPE
value: "0502010004ST,0502010004ST"
- name: MQTT_HOST
... ...
... ... @@ -17,6 +17,7 @@ require (
github.com/hibiken/asynq v0.21.0
github.com/imkira/go-interpol v1.1.0 // indirect
github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/moul/http2curl v1.0.0 // indirect
github.com/mozillazg/go-pinyin v0.19.0
github.com/onsi/ginkgo v1.15.2
... ...
... ... @@ -15,6 +15,8 @@ type AttendanceRecordDto struct {
//OrgId int `json:"orgId,omitempty"`
// 考勤类型 1.正常 2.支援
AttendanceType int `json:"attendanceType,omitempty"`
// 班组名称
GroupName string `json:"groupName"`
// 生产工人
ProductWorker *domain.User `json:"productWorker,omitempty"`
// 审核人
... ... @@ -72,6 +74,7 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i
t := time.Unix(m.Ext.AttendanceExt.ApproveAt, 0)
d.ApproveAt = t.Local().Format("2006-01-02 15:04:05")
}
d.GroupName = m.Ext.AttendanceExt.GroupName
}
}
return d
... ...
... ... @@ -12,6 +12,8 @@ type EmployeeAttendanceRecordDto struct {
SignDate string `json:"signDate"`
// 工作位置
*domain.WorkStation
// 班组名称
GroupName string `json:"groupName"`
// 生产工人
ProductWorker *domain.User `json:"productWorker,omitempty"`
// 考勤类型 1.正常 2.支援
... ... @@ -52,6 +54,9 @@ func (d *EmployeeAttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord,
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
//d.ProductAttendanceRecordExt = m.Ext.AttendanceExt
if m.Ext.AttendanceExt != nil {
d.GroupName = m.Ext.AttendanceExt.GroupName
}
}
return d
}
... ...
... ... @@ -13,7 +13,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"math/rand"
"strconv"
"sync"
"time"
... ... @@ -140,9 +139,9 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD
}
}
// TODO:测试假数据,后期注释掉
if createDeviceCollectionCommand.DeviceType == domain.DeviceTypeChuanChuanJi {
newDeviceCollection.Values["Count"] = rand.Intn(300)
}
//if createDeviceCollectionCommand.DeviceType == domain.DeviceTypeChuanChuanJi {
// newDeviceCollection.Values["Count"] = rand.Intn(300)
//}
deviceCollection, err := deviceCollectionRepository.Save(newDeviceCollection)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
... ... @@ -11,6 +11,8 @@ var (
MANUFACTURE_DEFAULT_COMPANYID = 1
// 生产制造 - 称重系统 - 默认组织
MANUFACTURE_DEFAULT_ORGID = 1
// 生产制造 - 称重系统 - 默认车间ID
MANUFACTURE_DEFAULT_WORKSHOPID = 2
// 产品类型列表
MANUFACTURE_PRODUCT_TYPE = "0502010004ST,0504010004ST"
... ... @@ -24,6 +26,9 @@ func init() {
if os.Getenv("MANUFACTURE_DEFAULT_ORGID") != "" {
MANUFACTURE_DEFAULT_ORGID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_DEFAULT_ORGID"))
}
if os.Getenv("MANUFACTURE_DEFAULT_WORKSHOPID") != "" {
MANUFACTURE_DEFAULT_WORKSHOPID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_DEFAULT_WORKSHOPID"))
}
if os.Getenv("MANUFACTURE_PRODUCT_TYPE") != "" {
MANUFACTURE_PRODUCT_TYPE = os.Getenv("MANUFACTURE_PRODUCT_TYPE")
}
... ...
... ... @@ -43,6 +43,9 @@ type ProductRecord struct {
ProductRecordInfo *ProductRecordInfo `json:"productRecordInfo,omitempty"`
// 扩展数据
Ext *Ext `json:"ext,omitempty"`
// 上一条记录
PreRecord *ProductRecord `json:"-"`
}
type ProductRecordRepository interface {
... ...
... ... @@ -70,17 +70,20 @@ func (employeeProductRecord *EmployeeProductRecord) Update(data map[string]inter
}
// 更新生产量
func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh float64, productRecordType int, sectionName string, yesterdayWeight float64, bestWeight float64) {
func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(productRecord *ProductRecord, yesterdayWeight float64, bestWeight float64) {
var weigh float64 = productRecord.ProductRecordInfo.Weigh
var productRecordType int = productRecord.ProductRecordType
var sectionName string = productRecord.WorkStation.SectionName
if employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh == nil {
employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh = make(map[string]float64)
}
if productRecordType == RecordTypeSecondLevelWeigh {
// 当前工段
if employeeProductRecord.WorkStation.SectionName == sectionName {
if employeeProductRecord.WorkStation.SectionName == sectionName && productRecord.PreRecord == nil {
employeeProductRecord.SecondLevelWeigh += weigh
} else {
} else if productRecord.PreRecord != nil {
// 其他工段的二级品
employeeProductRecord.ProductRecordInfo.AddSectionWeight(sectionName, weigh)
employeeProductRecord.ProductRecordInfo.AddSectionWeight(productRecord.PreRecord.WorkStation.SectionName, weigh)
}
}
if productRecordType == RecordTypeReceiveMaterial {
... ...
... ... @@ -31,6 +31,8 @@ type ProductRecordStaticInfo struct {
TotalOtherSecondLevelWeigh float64 `json:"totalOtherSecondLevelWeigh"`
// 保存其他工段二级品的重量
OtherSectionSecondLevelWeigh map[string]float64 `json:"otherSectionSecondLevelWeigh"`
// 生产计划列表
ProductPlans []int `json:"plans"`
}
func (info *ProductRecordStaticInfo) OtherSecondLevelWeigh() float64 {
... ... @@ -76,3 +78,24 @@ func (info *ProductRecordStaticInfo) PreStatistics(productWeight float64, second
info.QualificationRate = utils.Round(info.OutputWeight*100.0/info.InputWeight, 0)
}
}
func (info *ProductRecordStaticInfo) GetBestOutputWeight() float64 {
return max(info.OutputWeight, max(info.YesterdayOutputWeight, info.BestOutputWeight))
}
func (info *ProductRecordStaticInfo) AddProductPlan(productPlanId int) bool {
for _, v := range info.ProductPlans {
if v == productPlanId {
return false
}
}
info.ProductPlans = append(info.ProductPlans, productPlanId)
return true
}
func max(a, b float64) float64 {
if a > b {
return a
}
return b
}
... ...
... ... @@ -53,16 +53,23 @@ func (workshopProductRecord *WorkshopProductRecord) Update(data map[string]inter
return nil
}
func (employeeProductRecord *WorkshopProductRecord) UpdateProductWeigh(weigh float64, productRecordType int, sectionName string) {
func (employeeProductRecord *WorkshopProductRecord) UpdateProductWeigh(productRecord *ProductRecord) {
var (
weigh float64 = productRecord.ProductRecordInfo.Weigh
productRecordType int = productRecord.ProductRecordType
sectionName string = productRecord.WorkStation.SectionName
)
if employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh == nil {
employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh = make(map[string]float64)
}
if productRecordType == RecordTypeSecondLevelWeigh {
if employeeProductRecord.WorkStation.SectionName == sectionName {
if employeeProductRecord.WorkStation.SectionName == sectionName && productRecord.PreRecord == nil {
employeeProductRecord.SecondLevelWeigh += weigh
} else {
// 其他工段的二级品
employeeProductRecord.ProductRecordInfo.AddSectionWeight(sectionName, weigh)
if productRecord.PreRecord != nil {
employeeProductRecord.ProductRecordInfo.AddSectionWeight(productRecord.PreRecord.WorkStation.SectionName, weigh)
}
}
}
if productRecordType == RecordTypeReceiveMaterial {
... ... @@ -81,6 +88,13 @@ func (employeeProductRecord *WorkshopProductRecord) UpdateProductWeigh(weigh flo
}
// 产能
func (employeeProductRecord *WorkshopProductRecord) AddPlanProductWeight(weight float64, productPlanId int) {
if employeeProductRecord.ProductRecordInfo.AddProductPlan(productPlanId) {
employeeProductRecord.ProductWeigh += weight
}
}
// 产能
func (employeeProductRecord *WorkshopProductRecord) RealProductWeigh() float64 {
// 产能 = 总投入量 - 本阶段二级品重量 - 其他上级二级品重量
result := employeeProductRecord.ProductWeigh - employeeProductRecord.SecondLevelWeigh - employeeProductRecord.ProductRecordInfo.OtherSecondLevelWeigh()
... ...
... ... @@ -8,6 +8,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"time"
)
... ... @@ -34,6 +35,9 @@ func (dao *AttendanceRecordDao) ProductWorkStationAttendanceRecord(companyId, or
query.Where("company_id = ?", companyId)
query.Where("org_id = ?", orgId)
query.Where("work_station->>'workStationId' = ?", workStationId)
// 当天
query.Where("sign_in >= ?", utils.GetZeroTime(productTime))
query.Where("sign_in <?", utils.GetNextDayZeroTime(productTime))
query.Where("sign_in <= ?", productTime)
query.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
query.WhereOr("sign_out >= ?", productTime)
... ...
... ... @@ -25,6 +25,31 @@ func NewEmployeeProductRecordDao(transactionContext *pgTransaction.TransactionCo
}
}
// 员工对应工段批次的生产记录 (生产日期)
func (dao *EmployeeProductRecordDao) WorkerWorkStationProductRecord(companyId, orgId int, workStationId string, planId, workerId int, productTime time.Time) (*domain.EmployeeProductRecord, error) {
tx := dao.transactionContext.PgTx
employeeProductRecordModel := new(models.EmployeeProductRecord)
query := sqlbuilder.BuildQuery(tx.Model(employeeProductRecordModel), map[string]interface{}{})
query.Where("company_id = ?", companyId)
query.Where("org_id = ?", orgId)
query.Where("product_worker ->>'userId' = '?'", workerId)
query.Where("work_station ->>'workStationId' = ?", workStationId)
query.Where("product_record_info ->>'productPlanId' = '?'", planId)
query.Where("product_record_info ->>'productDate' = ?", productTime.Local().Format("2006-01-02"))
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, domain.ErrorNotFound
} else {
return nil, err
}
}
if employeeProductRecordModel.EmployeeProductRecordId == 0 {
return nil, domain.ErrorNotFound
} else {
return transform.TransformToEmployeeProductRecordDomainModelFromPgModels(employeeProductRecordModel)
}
}
// 员工对应批次的生产记录 (生产日期)
func (dao *EmployeeProductRecordDao) WorkerProductRecord(companyId, orgId, planId, workerId int, productTime time.Time) (*domain.EmployeeProductRecord, error) {
tx := dao.transactionContext.PgTx
... ...
... ... @@ -25,15 +25,16 @@ func NewWorkshopProductRecordDao(transactionContext *pgTransaction.TransactionCo
}
}
// 员工对应批次的生产记录 (生产日期)
func (dao *WorkshopProductRecordDao) WorkshopProductRecord(companyId, orgId, planId int, productTime time.Time) (*domain.WorkshopProductRecord, error) {
// 车间对应工段的生产记录 (生产日期)
func (dao *WorkshopProductRecordDao) WorkshopProductRecord(companyId, orgId int, workStationId string, planId int, productTime time.Time) (*domain.WorkshopProductRecord, error) {
tx := dao.transactionContext.PgTx
employeeProductRecordModel := new(models.WorkshopProductRecord)
query := sqlbuilder.BuildQuery(tx.Model(employeeProductRecordModel), map[string]interface{}{})
query.Where("company_id = ?", companyId)
query.Where("org_id = ?", orgId)
query.Where("work_station ->>'workStationId' = ?", workStationId)
query.Where("product_date = ?", productTime.Local().Format("2006-01-02"))
query.Where("product_record_info ->>'productPlanId' = '?'", planId)
//query.Where("product_record_info ->>'productPlanId' = '?'", planId)
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, domain.ErrorNotFound
... ...
... ... @@ -3,6 +3,7 @@ package domainService
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
... ... @@ -222,7 +223,9 @@ func (ptr *PGCommonStatisticsService) WorkshopProductionEfficiencyStatistics(que
if err := utils.LoadQueryObject(queryOptions, request); err != nil {
return nil, err
}
if request.WorkshopId == 0 {
request.WorkshopId = constant.MANUFACTURE_DEFAULT_WORKSHOPID
}
workshopRepository, _ := repository.NewWorkshopRepository(ptr.transactionContext)
type record struct {
Oee float64 `json:"oee"`
... ... @@ -342,9 +345,12 @@ func (ptr *PGCommonStatisticsService) DeviceRunningInfo(queryOptions map[string]
if err := utils.LoadQueryObject(queryOptions, request); err != nil {
return nil, err
}
if request.WorkshopId == 0 {
request.WorkshopId = constant.MANUFACTURE_DEFAULT_WORKSHOPID
}
deviceDailyRunningRecordDao, _ := dao.NewDeviceDailyRunningRecordDao(ptr.transactionContext)
var response = make([]*DeviceInfo, 0)
deviceDailyRunningRecordDao.DeviceRunningInfo(request.CompanyId, request.OrgId, "CCJ1", &response)
deviceDailyRunningRecordDao.DeviceRunningInfo(request.CompanyId, request.OrgId, "", &response)
return map[string]interface{}{
"devices": response,
... ... @@ -388,7 +394,7 @@ func (ptr *PGCommonStatisticsService) DeviceSummary(deviceInfos []*DeviceInfo) i
"total": total,
"off": deviceSummary(total, deviceOff),
"on": deviceSummary(total, deviceRunning),
"err": deviceSummary(total, deviceRunning),
"err": deviceSummary(total, deviceErr),
}
return result
}
... ...
... ... @@ -95,7 +95,7 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu
// 领料、退料需要换算产能
if productRecordType == domain.RecordTypeReceiveMaterial || productRecordType == domain.RecordTypeReturnMaterial {
weight = (weight / uc.FromUnitQuantity.Quantity) * uc.ToUnitQuantity.Quantity
weight = utils.Round((weight/uc.FromUnitQuantity.Quantity)*uc.ToUnitQuantity.Quantity, 1)
}
// 退料、需要判断用户是否有领过料
if productRecordType == domain.RecordTypeReturnMaterial {
... ... @@ -132,7 +132,7 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu
}
// 发送Job
if productRecordType == domain.RecordTypeReceiveMaterial || productRecordType == domain.RecordTypeReturnMaterial {
if (productRecordType == domain.RecordTypeReceiveMaterial || productRecordType == domain.RecordTypeReturnMaterial) && workstation.SectionName == ProductSection4 {
// 发送Job
if err = SendProductRecordStaticsJob(record); err != nil {
return nil, err
... ...
... ... @@ -2,6 +2,7 @@ package domainService
import (
"fmt"
"github.com/mohae/deepcopy"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
... ... @@ -24,10 +25,10 @@ const (
func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain.ProductRecord) (interface{}, error) {
var (
workshopRepository, _ = repository.NewWorkshopRepository(ptr.transactionContext)
productPlanRepository, _ = repository.NewProductPlanRepository(ptr.transactionContext)
productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext)
employeeProductRecordRepository, _ = repository.NewEmployeeProductRecordRepository(ptr.transactionContext)
workshopRepository, _ = repository.NewWorkshopRepository(ptr.transactionContext)
productPlanRepository, _ = repository.NewProductPlanRepository(ptr.transactionContext)
productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext)
//employeeProductRecordRepository, _ = repository.NewEmployeeProductRecordRepository(ptr.transactionContext)
)
var (
... ... @@ -44,10 +45,13 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain.
//查询生产记录 批次、生产日期、下(成型)所有二级品
// 更新打料的二级品需要再一次更新成型的二级品
if section, err := FindSectionByName(workshopRepository, productRecord.WorkStation.WorkshopId, productRecord.WorkStation.LineId, ProductSection2); err == nil && section != nil {
nextProductRecord := *productRecord
nextProductRecord.WorkStation.SectionName = ProductSection2
nextProductRecord.WorkStation.SectionId = section.SectionId
ptr.EmployeeProductStatics(&nextProductRecord)
if nextProductRecord, ok := deepcopy.Copy(productRecord).(*domain.ProductRecord); ok {
nextProductRecord.WorkStation.SectionName = ProductSection2
nextProductRecord.WorkStation.SectionId = section.SectionId
nextProductRecord.WorkStation.WorkStationId = domain.WorkstationKey(productRecord.WorkStation.WorkshopId, productRecord.WorkStation.LineId, section.SectionId)
nextProductRecord.PreRecord = productRecord
ptr.EmployeeProductStatics(nextProductRecord)
}
}
}
break
... ... @@ -56,7 +60,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain.
case ProductSection3:
break
case ProductSection4: //个人特殊处理
return ptr.personalProductStatics(productRecord)
return ptr.personalProductStatics(nil, nil, nil, productRecord)
default:
return nil, nil //ptr.personalProductStatics(productRecord)
}
... ... @@ -64,72 +68,34 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain.
log.Logger.Debug(fmt.Sprintf("工段:%v product_record 编号:%v 批次为0", productRecord.WorkStation.WorkStationId, productRecord.ProductRecordId))
return nil, nil
}
// 2.0 查找批次
productPlan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": planId})
if err != nil {
return nil, err
}
// 2.1 判断是否是支援类型 有打卡记录,员工是否是属于该工段的员工
groupMembers, groupMembersKeyFunc := FindGroupMembers(productGroupRepository, cid, oid, productRecord.WorkStation.WorkStationId)
// 集体
// 1.查询员工 -》 员工打卡记录 工位+打卡日期
// 2.打卡记录的时间区间 在生产记录上报的时间范围内
attendanceRecordDao, _ := dao.NewAttendanceRecordDao(ptr.transactionContext)
_, attendanceRecords, err := attendanceRecordDao.ProductWorkStationAttendanceRecord(cid, oid, productRecord.WorkStation.WorkStationId, time.Now()) //, productRecord.CreatedAt
_, attendanceRecords, err := attendanceRecordDao.ProductWorkStationAttendanceRecord(cid, oid, productRecord.WorkStation.WorkStationId, productRecord.CreatedAt) //, productRecord.CreatedAt
if err != nil || len(attendanceRecords) == 0 {
return nil, err
}
// 2.1 判断是否是支援类型 有打卡记录,员工是否是属于该工段的员工
groupMembers, groupMembersKeyFunc := FindGroupMembers(productGroupRepository, cid, oid, productRecord.WorkStation.WorkStationId)
employeeProductRecordDao, _ := dao.NewEmployeeProductRecordDao(ptr.transactionContext)
for i := 0; i < len(attendanceRecords); i++ {
r := attendanceRecords[i]
participateType := domain.ParticipateNormal
if _, ok := groupMembers[groupMembersKeyFunc(r.ProductWorker.UserId)]; !ok {
participateType = domain.ParticipateSupport
}
var employeeProductRecord *domain.EmployeeProductRecord
employeeProductRecord, err = employeeProductRecordDao.WorkerProductRecord(cid, oid, productRecord.ProductRecordInfo.ProductPlanId, r.ProductWorker.UserId, productRecord.CreatedAt)
if err == domain.ErrorNotFound {
employeeProductRecord = newEmployeeProductRecord(productRecord, participateType, productPlan, r.ProductWorker)
} else {
if err != nil {
log.Logger.Error(err.Error())
continue
}
}
// 查询当前员工 昨日产能 、历史最好产能
var (
yesterdayOutputWeight float64 = 0
bestOutputWeight float64 = 0
)
if employeeProductRecord.ProductRecordInfo.BestOutputWeight > 0 {
if record, e := employeeProductRecordDao.WorkerProductRecord(cid, oid, planId, r.ProductWorker.UserId, productRecord.CreatedAt.AddDate(0, 0, -1)); e == nil && record != nil {
yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight
bestOutputWeight = record.ProductRecordInfo.BestOutputWeight
} else {
if record, e := employeeProductRecordDao.WorkerBestOutputRecord(cid, oid, planId, r.ProductWorker.UserId); e == nil && record != nil {
yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight
}
}
}
employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName, yesterdayOutputWeight, bestOutputWeight)
if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil {
// TODO:异常处理
log.Logger.Error(fmt.Sprintf("生产记录:[%v] 员工:[%v] 处理异常:%v", productRecord.ProductRecordId, r.ProductWorker.UserId, err.Error()))
continue
productRecord.ProductWorker = r.ProductWorker
// 3.查询员工产能记录 -》员工 批次+工位+批次生产日期 (有 更新产能数据、没有插入一条产能数据)
// 4.更新产能 (产能、二级品) (特殊工段处理 打料、成型)
// 个人
if _, err := ptr.personalProductStatics(productPlan, groupMembers, groupMembersKeyFunc, productRecord); err != nil {
return nil, err
}
}
// 3.查询员工产能记录 -》员工 批次+工位+批次生产日期 (有 更新产能数据、没有插入一条产能数据)
// 4.更新产能 (产能、二级品) (特殊工段处理 打料、成型)
// 个人
return nil, nil
}
... ... @@ -208,7 +174,7 @@ func FindGroupMembers(productGroupRepository domain.ProductGroupRepository, comp
}
// 个人生产记录统计
func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain.ProductRecord) (interface{}, error) {
func (ptr *PGProductRecordService) personalProductStatics(productPlan *domain.ProductPlan, groupMembers map[string]*domain.User, groupMembersKeyFunc func(int) string, productRecord *domain.ProductRecord) (interface{}, error) {
var (
//workshopRepository,_=repository.NewWorkshopRepository(ptr.transactionContext)
productPlanRepository, _ = repository.NewProductPlanRepository(ptr.transactionContext)
... ... @@ -216,29 +182,37 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain.
employeeProductRecordRepository, _ = repository.NewEmployeeProductRecordRepository(ptr.transactionContext)
)
var (
cid = productRecord.CompanyId
oid = productRecord.OrgId
planId = productRecord.ProductRecordInfo.ProductPlanId
productPlan *domain.ProductPlan
err error
cid = productRecord.CompanyId
oid = productRecord.OrgId
planId = productRecord.ProductRecordInfo.ProductPlanId
//productPlan *domain.ProductPlan
err error
)
// 2.1 判断是否是支援类型 有打卡记录,员工是否是属于该工段的员工
groupMembers, groupMembersKeyFunc := FindGroupMembers(productGroupRepository, cid, oid, productRecord.WorkStation.WorkStationId)
employeeProductRecordDao, _ := dao.NewEmployeeProductRecordDao(ptr.transactionContext)
productPlan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": planId})
if err != nil {
return nil, err
if groupMembers == nil {
groupMembers, groupMembersKeyFunc = FindGroupMembers(productGroupRepository, cid, oid, productRecord.WorkStation.WorkStationId)
}
if productPlan == nil {
productPlan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": planId})
if err != nil {
return nil, err
}
}
workStationId := productRecord.WorkStation.WorkStationId
employeeProductRecordDao, _ := dao.NewEmployeeProductRecordDao(ptr.transactionContext)
participateType := domain.ParticipateNormal
if _, ok := groupMembers[groupMembersKeyFunc(productRecord.ProductWorker.UserId)]; !ok {
participateType = domain.ParticipateSupport
}
var employeeProductRecord *domain.EmployeeProductRecord
employeeProductRecord, err = employeeProductRecordDao.WorkerProductRecord(cid, oid, productRecord.ProductRecordInfo.ProductPlanId, productRecord.ProductWorker.UserId, productRecord.CreatedAt)
employeeProductRecord, err = employeeProductRecordDao.WorkerWorkStationProductRecord(cid, oid, workStationId, productRecord.ProductRecordInfo.ProductPlanId, productRecord.ProductWorker.UserId, productRecord.CreatedAt)
if err == domain.ErrorNotFound {
employeeProductRecord = newEmployeeProductRecord(productRecord, participateType, productPlan, productRecord.ProductWorker)
err = nil
} else if err != nil {
return nil, err
}
// 查询当前员工 昨日产能 、历史最好产能
... ... @@ -247,9 +221,9 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain.
bestOutputWeight float64 = 0
)
if employeeProductRecord.ProductRecordInfo.BestOutputWeight == 0 {
if record, e := employeeProductRecordDao.WorkerProductRecord(cid, oid, planId, productRecord.ProductWorker.UserId, productRecord.CreatedAt.AddDate(0, 0, -1)); e == nil && record != nil {
if record, e := employeeProductRecordDao.WorkerWorkStationProductRecord(cid, oid, workStationId, planId, productRecord.ProductWorker.UserId, productRecord.CreatedAt.AddDate(0, 0, -1)); e == nil && record != nil {
yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight
bestOutputWeight = record.ProductRecordInfo.BestOutputWeight
bestOutputWeight = record.ProductRecordInfo.GetBestOutputWeight()
} else {
if record, e := employeeProductRecordDao.WorkerBestOutputRecord(cid, oid, planId, productRecord.ProductWorker.UserId); e == nil && record != nil {
... ... @@ -258,7 +232,7 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain.
}
}
employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName, yesterdayOutputWeight, bestOutputWeight)
employeeProductRecord.UpdateProductWeigh(productRecord, yesterdayOutputWeight, bestOutputWeight)
if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil {
// TODO:异常处理
... ... @@ -273,7 +247,7 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain.
workshopRepository, _ = repository.NewWorkshopRepository(ptr.transactionContext)
productPlanRepository, _ = repository.NewProductPlanRepository(ptr.transactionContext)
//productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext)
employeeProductRecordRepository, _ = repository.NewWorkshopProductRecordRepository(ptr.transactionContext)
workshopProductRecordRepository, _ = repository.NewWorkshopProductRecordRepository(ptr.transactionContext)
)
var (
... ... @@ -298,29 +272,36 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain.
//查询生产记录 批次、生产日期、下(成型)所有二级品
// 更新打料的二级品需要再一次更新成型的二级品
if section, err := FindSectionByName(workshopRepository, productRecord.WorkStation.WorkshopId, productRecord.WorkStation.LineId, ProductSection2); err == nil && section != nil {
nextProductRecord := *productRecord
nextProductRecord.WorkStation.SectionName = ProductSection2
nextProductRecord.WorkStation.SectionId = section.SectionId
ptr.WorkshopProductStatics(&nextProductRecord)
if nextProductRecord, ok := deepcopy.Copy(productRecord).(*domain.ProductRecord); ok {
nextProductRecord.WorkStation.SectionName = ProductSection2
nextProductRecord.WorkStation.SectionId = section.SectionId
nextProductRecord.WorkStation.WorkStationId = domain.WorkstationKey(productRecord.WorkStation.WorkshopId, productRecord.WorkStation.LineId, section.SectionId)
nextProductRecord.PreRecord = productRecord
ptr.WorkshopProductStatics(nextProductRecord)
}
}
}
break
}
var employeeProductRecord *domain.WorkshopProductRecord
employeeProductRecordDao, _ := dao.NewWorkshopProductRecordDao(ptr.transactionContext)
employeeProductRecord, err = employeeProductRecordDao.WorkshopProductRecord(cid, oid, planId, productRecord.CreatedAt)
var workshopProductRecord *domain.WorkshopProductRecord
workshopProductRecordDao, _ := dao.NewWorkshopProductRecordDao(ptr.transactionContext)
workshopProductRecord, err = workshopProductRecordDao.WorkshopProductRecord(cid, oid, productRecord.WorkStation.WorkStationId, planId, productRecord.CreatedAt)
if err == domain.ErrorNotFound {
employeeProductRecord = newWorkshopProductRecord(productRecord, productPlan)
workshopProductRecord = newWorkshopProductRecord(productRecord, productPlan)
} else {
if err != nil {
log.Logger.Error(err.Error())
return nil, nil
}
}
employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName)
workshopProductRecord.UpdateProductWeigh(productRecord)
// 打料 跟 成型工段的初始产能是批次的产能
if productRecord.WorkStation.SectionName == ProductSection1 && productRecord.WorkStation.SectionName == ProductSection2 {
workshopProductRecord.AddPlanProductWeight(productPlan.PlanDevoted.Weight, productPlan.ProductPlanId)
}
if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil {
if workshopProductRecord, err = workshopProductRecordRepository.Save(workshopProductRecord); err != nil {
// TODO:异常处理
log.Logger.Error(fmt.Sprintf("生产记录:[%v] 处理异常:%v", productRecord.ProductRecordId, err.Error()))
}
... ...
... ... @@ -58,12 +58,15 @@ func (ptr *PGWorkshopPlanCompletionRecordService) WorkshopPlanCompletion(begin t
totalReal += v.RealWeight
}
var completionRate float64
if !(totalPlan == 0 || totalReal == 0) {
completionRate = utils.Round(totalReal*100.0/totalPlan, 0)
}
// 超出计划生产的,最多完成效率 100%
if totalPlan <= totalReal {
completionRate = 100
if totalPlan > 0 && totalReal > 0 {
// 超出计划生产的,最多完成效率 100%
if totalPlan <= totalReal {
completionRate = 100
} else {
completionRate = utils.Round(totalReal*100.0/totalPlan, 0)
}
} else {
completionRate = 0
}
var record *models.WorkshopPlanCompletionRecord
... ...
... ... @@ -27,8 +27,8 @@ func (repository *EmployeeProductRecordRepository) nextIdentify() (int64, error)
func (repository *EmployeeProductRecordRepository) Save(employeeProductRecord *domain.EmployeeProductRecord) (*domain.EmployeeProductRecord, error) {
sqlBuildFields := []string{
"employee_product_record_id",
"org_id",
"company_id",
"org_id",
"work_station",
"work_on",
"participate_type",
... ...
#! /bin/bash
echo "批量打卡"
# 待打卡的用户IC卡号列表
icList=("18860189991" "18860189992" "18860189993" "18860187878" "18860183016")
# 设备编号
device_coe='STX-D-0001'
# 测试环境服务地址
#host="http://allied-creation-manufacture-test.fjmaimaimai.com/zkteco/iclock/cdata?SN=$device_coe"
# 本地环境服务地址
host="http://106.75.231.90:9999/zkteco/iclock/cdata?SN=$device_coe"
sign_time=`date "+%Y-%m-%d 08:00:00"`
if [ $1 = 'off' ];then
sign_time=`date "+%Y-%m-%d 18:00:00"`
echo "下班打卡"
else
echo "上班打卡"
fi
for str in ${icList[*]};do
echo "IC: $str $sign_time \r\n"
curl --location --request POST $host \
--data-raw "$str $sign_time $ YY"
done
\ No newline at end of file
... ...
#! /bin/bash
echo "批量打卡"
# 待打卡的用户IC卡号列表
icList=("18860189991" "18860189992")
# 设备编号
device_coe='STX-D-0001'
# 测试环境服务地址
host="http://allied-creation-manufacture-test.fjmaimaimai.com/zkteco/iclock/cdata?SN=$device_coe"
# 本地环境服务地址
#host="http://106.75.231.90:9999/zkteco/iclock/cdata?SN=$device_coe"
sign_time=`date "+%Y-%m-%d %H:%M:%S"`
for str in ${icList[*]};do
echo "IC: $str 打卡时间: $sign_time \r\n"
curl --location --request POST $host \
--data-raw "$str $sign_time $ YY"
done
\ No newline at end of file
... ...