作者 yangfu

refactor: 代码优化

- 历史生产记录查询修改
- 定时初始化车间生产记录
... ... @@ -37,6 +37,9 @@ func (crontabService *CrontabService) initTask() {
})
task.AddTask("PullPrdMoK3cloud", PullPrdMoK3cloud)
autoInitWorkshopProductRecord := task.NewTask("AutoInitWorkshopProductRecord", "0 0 */4 * * *", AutoInitWorkshopProductRecord)
task.AddTask("AutoInitWorkshopProductRecord", autoInitWorkshopProductRecord)
autoApproveAttendanceRecord := task.NewTask("autoApproveAttendanceRecord", "0 */2 * * * *", AutoApproveProductAttendanceRecord)
task.AddTask("autoApproveAttendanceRecord", autoApproveAttendanceRecord)
... ...
package crontab
import (
"context"
"fmt"
"github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"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/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"time"
)
// AutoInitWorkshopProductRecord 自动初始化车间生产记录
func AutoInitWorkshopProductRecord(ctx context.Context) error {
defer func() {
if r := recover(); r != nil {
log.Logger.Error(fmt.Sprintf("%v", r), map[string]interface{}{"task": "自动初始化车间生产记录"})
}
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return err
}
if err := transactionContext.StartTransaction(); err != nil {
return err
}
defer func() {
if err != nil {
log.Logger.Error("【自动初始化车间生产记录】 失败:" + err.Error())
}
transactionContext.RollbackTransaction()
}()
log.Logger.Debug("【自动初始化车间生产记录】 启动")
_, workshop, err := factory.FastPgWorkshop(transactionContext, constant.MANUFACTURE_DEFAULT_WORKSHOPID)
if err != nil {
return err
}
productPlanDispatchRecordDao, _ := dao.NewProductPlanDispatchRecord(transactionContext.(*pg.TransactionContext))
productPlans, err := productPlanDispatchRecordDao.ProductPlans(constant.MANUFACTURE_DEFAULT_COMPANYID,
constant.MANUFACTURE_DEFAULT_ORGID,
constant.MANUFACTURE_DEFAULT_WORKSHOPID,
utils.GetZeroTimeWithLocal(time.Now(), time.UTC), "")
if err != nil {
return err
}
if len(productPlans) == 0 {
log.Logger.Debug("【自动初始化车间生产记录】 当天执行计划为空")
return nil
}
workshopProductRecordDao, _ := dao.NewWorkshopProductRecordDao(transactionContext.(*pg.TransactionContext))
workshopProductRecordRepository, _ := repository.NewWorkshopProductRecordRepository(transactionContext.(*pg.TransactionContext))
lines := workshop.GetProductLines(domain.NotDeleted)
for _, line := range lines {
for _, section := range line.ProductSections {
if !(section.SectionName == domain.ProductSection1 || section.SectionName == domain.ProductSection2) {
continue
}
if section.Removed == domain.Deleted {
continue
}
workstation := domain.NewWorkStation(workshop, line, section)
cid := constant.MANUFACTURE_DEFAULT_COMPANYID
oid := constant.MANUFACTURE_DEFAULT_ORGID
for _, plan := range productPlans {
var workshopProductRecord *domain.WorkshopProductRecord
workshopProductRecord, err = workshopProductRecordDao.WorkshopProductRecord(cid, oid, workstation.WorkStationId, plan.ProductPlanId, time.Now())
if err == domain.ErrorNotFound {
workshopProductRecord = domainService.NewWorkshopProductRecord(&domain.ProductRecord{
CompanyId: constant.MANUFACTURE_DEFAULT_COMPANYID,
OrgId: constant.MANUFACTURE_DEFAULT_ORGID,
WorkStation: workstation,
CreatedAt: time.Now(),
ProductRecordInfo: &domain.ProductRecordInfo{
ProductPlanId: plan.ProductPlanId,
PlanProductName: plan.PlanProductName,
BatchNumber: plan.BatchNumber,
},
}, plan)
if workshopProductRecord, err = workshopProductRecordRepository.Save(workshopProductRecord); err != nil {
return err
}
log.Logger.Debug(fmt.Sprintf("【自动初始化车间生产记录】 工位:%v(%v) 初始产能:%v kg 日期:%v ID:%v",
workshopProductRecord.WorkStation.WorkStationId, workshopProductRecord.WorkStation.SectionName,
workshopProductRecord.ProductWeigh, workshopProductRecord.ProductRecordInfo.ProductDate, workshopProductRecord.WorkshopProductRecordId))
continue
}
if err != nil {
log.Logger.Error(err.Error())
return nil
}
}
}
}
if err = transactionContext.CommitTransaction(); err != nil {
return err
}
return nil
}
... ...
... ... @@ -5,11 +5,13 @@ import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/tool_funs"
"github.com/linmadan/egglib-go/utils/xtime"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/query"
"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/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
... ... @@ -514,6 +516,26 @@ func (productPlanService *ProductPlanService) ReturnMaterial(returnMaterialComma
productRecordService, _ := domainService.NewPGProductRecordService(transactionContext.(*pg.TransactionContext))
productRecordDao, _ := dao.NewProductRecordDao(transactionContext.(*pg.TransactionContext))
begin := xtime.BeginningOfDay()
end := time.Now()
workstationId := domain.WorkstationKey(returnMaterialCommand.WorkshopId, returnMaterialCommand.LineId, returnMaterialCommand.SectionId)
totalReceive, err := productRecordDao.ProductWeightStatics(returnMaterialCommand.CompanyId, returnMaterialCommand.OrgId, domain.RecordTypeReceiveMaterial, returnMaterialCommand.ProductPlanId, workstationId, begin, end)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
totalReturn, err := productRecordDao.ProductWeightStatics(returnMaterialCommand.CompanyId, returnMaterialCommand.OrgId, domain.RecordTypeReturnMaterial, returnMaterialCommand.ProductPlanId, workstationId, begin, end)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
allowReturn := totalReceive - totalReturn
if totalReturn+returnMaterialCommand.Weigh > totalReceive {
if allowReturn > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("当天累计退料大于累计领料,当前只允许退料 %v kg", totalReceive-totalReturn))
}
return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("当天累计退料大于累计领料"))
}
_, err = productRecordService.SubmitProductRecord(domain.RecordTypeReturnMaterial, tool_funs.SimpleStructToMap(returnMaterialCommand))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
... ... @@ -4,6 +4,7 @@ import (
"github.com/linmadan/egglib-go/utils/xtime"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
)
// HistoryProductRecord 历史生成记录
... ... @@ -29,13 +30,16 @@ type HistoryProductRecord struct {
func (d *HistoryProductRecord) LoadDto(m *domain.ProductRecord) *HistoryProductRecord {
d.ProductRecordId = m.ProductRecordId
d.ProductWorker = m.ProductWorker
d.Weight = utils.Round(m.ProductRecordInfo.WeighBefore, 1)
d.Weight = utils.Round(m.ProductRecordInfo.Original, 1)
d.Status = m.ProductRecordInfo.ApproveStatus
d.PlanProductName = m.ProductRecordInfo.PlanProductName
d.BatchNumber = m.ProductRecordInfo.BatchNumber
d.CreatedAt = m.CreatedAt.Local().Format("2006-01-02 15:04:05")
d.ProductRecordType = m.ProductRecordType
if m.ProductRecordType != domain.RecordTypeSecondLevelWeigh && m.ProductRecordInfo.ApproveStatus == domain.ProductRecordNotApprove && !xtime.BeginningOfDay().Equal(xtime.New(m.CreatedAt).BeginningOfDay()) {
if m.ProductRecordType != domain.RecordTypeSecondLevelWeigh &&
m.ProductRecordInfo.ApproveStatus == domain.ProductRecordNotApprove &&
!(xtime.BeginningOfDay().Equal(xtime.New(m.CreatedAt.Local()).BeginningOfDay())) {
log.Logger.Debug("not equal", map[string]interface{}{"t1": xtime.BeginningOfDay(), "t2": xtime.New(m.CreatedAt.Local()).BeginningOfDay()})
d.Status = domain.ProductRecordLogged
}
return d
... ...
... ... @@ -27,12 +27,12 @@ type HistoryProductRecordQuery struct {
PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
// 页数
PageSize int `cname:"页数" json:"pageSize,omitempty"`
// 车间名称
//WorkshopName string `cname:"车间名称" json:"workshopName"`
// 批号
//BatchNumber string `cname:"批号" json:"batchNumber"`
// 姓名
//UserName string `cname:"姓名" json:"userName"`
// 车间ID
WorkshopId int `cname:"车间ID" json: workshopId,omitempty"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId,omitempty"`
// 工段ID
SectionId int `json:"sectionId,omitempty"`
// 生产记录类型:1:领料 2:退料 4:称重 8:二级品称重
ProductRecordType int `cname:"生产记录类型:1:领料 2:退料 4:称重 8:二级品称重" json:"productRecordType"`
// 生产线名称
... ... @@ -92,11 +92,19 @@ func (cmd *HistoryProductRecordQuery) Valid(validation *validation.Validation) {
cmd.ProductBeginTime = t
cmd.ProductEndTime = t.AddDate(0, 0, 1)
}
if cmd.Status == domain.ProductRecordLogged {
if cmd.Status == domain.ProductRecordNotApprove {
cmd.Status = domain.ProductRecordNotApprove
if xtime.IsZero(cmd.ProductBeginTime) || xtime.BeforeEqual(cmd.ProductBeginTime, xtime.BeginningOfDay()) {
cmd.ProductBeginTime = xtime.BeginningOfDay()
}
} else if cmd.Status == domain.ProductRecordLogged {
cmd.Status = domain.ProductRecordNotApprove
if len(cmd.Date) == 0 && xtime.IsZero(cmd.ProductEndTime) {
cmd.ProductEndTime = xtime.BeginningOfDay()
}
if len(cmd.Date) > 0 && !xtime.BeforeEqual(cmd.ProductEndTime, xtime.BeginningOfDay()) {
cmd.Status = domain.ProductRecordLogged
}
}
}
... ...
... ... @@ -14,6 +14,7 @@ var HTTP_PORT int = 8081
var CACHE_PREFIX = "allied-creation-manufacture-dev"
var LOG_LEVEL = "debug"
var LOG_FILE = "app.log"
var PPROF_ON = true
//天联共创基础模块
var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080" //"http://allied-creation-basic-dev.fjmaimaimai.com"
... ... @@ -45,5 +46,6 @@ func init() {
SERVICE_ENV = Configurator.DefaultString("SERVICE_ENV", SERVICE_ENV)
HTTP_PORT = Configurator.DefaultInt("HTTP_PORT", HTTP_PORT)
SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV)
PPROF_ON = Configurator.DefaultBool("PPROF_ON", PPROF_ON)
CACHE_PREFIX = SERVICE_NAME
}
... ...
... ... @@ -80,7 +80,9 @@ func (productAttendanceRecord *ProductAttendanceRecord) ComputeWorkTimeBefore(pr
if !productAttendanceRecord.SignOut.After(productAttendanceRecord.SignIn) {
return 0
}
wt := utils.Round(productAttendanceRecord.SignOut.Sub(productAttendanceRecord.SignIn).Hours(), 2)
signIn := roundTime(productAttendanceRecord.SignIn)
signOut := roundTime(productAttendanceRecord.SignOut)
wt := utils.Round(signOut.Sub(signIn).Hours(), 2)
if productCalendar == nil {
return roundWorkTime(wt)
}
... ... @@ -108,6 +110,20 @@ func roundWorkTime(wt float64) float64 {
return i
}
func roundTime(t time.Time) time.Time {
hour, min, _ := t.Local().Clock()
y, m, d := t.Local().Date()
newTime := time.Date(y, m, d, hour, 0, 0, 0, time.Local)
if min < 11 {
min = 0
} else if min >= 11 && min < 41 {
min = 30
} else {
min = 60
}
return newTime.Add(time.Minute * time.Duration(min))
}
func (productAttendanceRecord *ProductAttendanceRecord) SetProductTimeByProductCalendar(productCalendar *ProductCalendar) error {
now := xtime.New(productAttendanceRecord.SignIn)
productAttendanceRecord.ProductDate = now.BeginningOfDay()
... ...
... ... @@ -11,7 +11,7 @@ const (
)
const (
ProductSection1 = "打料"
ProductSection1 = "制模"
ProductSection2 = "成型"
ProductSection3 = "穿串"
ProductSection4 = "包装"
... ...
... ... @@ -29,7 +29,7 @@ func NewProductPlanDispatchRecord(transactionContext *pgTransaction.TransactionC
// 日期
// 产品编号
// 调度状态 status
func (dao *ProductPlanDispatchRecordDao) DeviceProductPlan(companyId, orgId int, workStationId string, date time.Time, productCode string, status int) (*domain.ProductPlanDispatchRecord, error) {
func (dao *ProductPlanDispatchRecordDao) ProductPlanDispatchRecord(companyId, orgId int, workStationId string, date time.Time, productCode string, status int) (*domain.ProductPlanDispatchRecord, error) {
tx := dao.transactionContext.PgTx
productPlanDispatchRecordModel := new(models.ProductPlanDispatchRecord)
query := sqlbuilder.BuildQuery(tx.Model(productPlanDispatchRecordModel), map[string]interface{}{})
... ... @@ -37,7 +37,9 @@ func (dao *ProductPlanDispatchRecordDao) DeviceProductPlan(companyId, orgId int,
query.Where("org_id = ?", orgId)
query.Where("work_station->>'workStationId'=?", workStationId)
query.Where("product_date = ?", date)
query.Where("plan_dispatch_status = ?", status)
if status > 0 {
query.Where("plan_dispatch_status = ?", status)
}
query.Where("plan_dispatch_record_ext->>'productCode'=?", productCode)
query.Order("updated_at desc")
if err := query.First(); err != nil {
... ... @@ -53,3 +55,57 @@ func (dao *ProductPlanDispatchRecordDao) DeviceProductPlan(companyId, orgId int,
return transform.TransformToProductPlanDispatchRecordDomainModelFromPgModels(productPlanDispatchRecordModel)
}
}
func (dao *ProductPlanDispatchRecordDao) ProductPlan(companyId, orgId int, workshopId int, date time.Time, productCode string) (*domain.ProductPlan, error) {
tx := dao.transactionContext.PgTx
productPlan := new(models.ProductPlan)
query := sqlbuilder.BuildQuery(tx.Model(productPlan), map[string]interface{}{})
query.Where("company_id = ?", companyId)
query.Where("org_id = ?", orgId)
query.Where("workshop->>'workshopId'='?'", workshopId)
query.Where("product_date = ?", date)
if len(productCode) > 0 {
query.Where("ext #>>'{productPlanExt,productCode}'=?", productCode)
}
query.Order("updated_at desc")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, domain.ErrorNotFound
} else {
return nil, err
}
}
if productPlan.ProductPlanId == 0 {
return nil, nil
} else {
return transform.TransformToProductPlanDomainModelFromPgModels(productPlan)
}
}
func (dao *ProductPlanDispatchRecordDao) ProductPlans(companyId, orgId int, workshopId int, date time.Time, productCode string) ([]*domain.ProductPlan, error) {
tx := dao.transactionContext.PgTx
productPlan := new(models.ProductPlan)
query := sqlbuilder.BuildQuery(tx.Model(productPlan), map[string]interface{}{})
query.Where("company_id = ?", companyId)
query.Where("org_id = ?", orgId)
query.Where("workshop->>'workshopId'='?'", workshopId)
query.Where("product_date = ?", date)
if len(productCode) > 0 {
query.Where("ext #>>'{productPlanExt,productCode}'=?", productCode)
}
query.Order("updated_at desc")
var productPlanModels = make([]*models.ProductPlan, 0)
var productPlans = make([]*domain.ProductPlan, 0)
if err := query.Select(&productPlanModels); err != nil {
return productPlans, err
} else {
for _, productPlanModel := range productPlanModels {
if productPlan, err := transform.TransformToProductPlanDomainModelFromPgModels(productPlanModel); err != nil {
return productPlans, err
} else {
productPlans = append(productPlans, productPlan)
}
}
return productPlans, nil
}
}
... ...
... ... @@ -117,7 +117,7 @@ select sum(a.weight) item_total,max(sname) sname from (
and product_record_info->>'approveStatus'='2'
and created_at >=?
and created_at <?
and work_station->>'sectionName' in ('打料','成型','穿串','包装')
and work_station->>'sectionName' in ('制模','成型','穿串','包装')
) a
group by a.workStationId
)
... ... @@ -127,10 +127,31 @@ select sname,round(item_total/(select sum(item_total) from item_product)*100, 0)
)
--select * from item_product_rate
select a.sname, coalesce(b.rate,0) rate from (
select unnest(ARRAY ['打料','成型','穿串','包装']) sname
select unnest(ARRAY ['制模','成型','穿串','包装']) sname
) a left join item_product_rate b on a.sname=b.sname`)
if _, err := tx.Query(result, sql, companyId, orgId, workshopId, beginTime, endTime); err != nil {
return err
}
return nil
}
// ProductWeightStatics 产能统计
func (dao *ProductRecordDao) ProductWeightStatics(companyId, orgId, productRecordType, productPlanId int, workstationId string, beginTime time.Time, endTime time.Time) (float64, error) {
tx := dao.transactionContext.PgTx
var result = struct {
Total float64
}{}
sql := fmt.Sprintf(`
select coalesce(sum(cast(product_record_info->>'original' as DECIMAL)),0) total
from manufacture.product_records
where company_id = ? and org_id = ? and product_record_type = ?
and work_station->>'workStationId' = ?
and product_record_info->>'productPlanId' = '?'
and created_at >= ? and created_at < ?
`)
if _, err := tx.QueryOne(&result, sql, companyId, orgId, productRecordType, workstationId, productPlanId, beginTime, endTime); err != nil {
return 0, err
}
return result.Total, nil
}
... ...
... ... @@ -11,7 +11,7 @@ import (
)
const (
ProductSection1 = "打料"
ProductSection1 = "制模" //打料更新为制模
ProductSection2 = "成型"
ProductSection3 = "穿串"
ProductSection4 = "包装"
... ... @@ -298,7 +298,7 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain.
workshopProductRecordDao, _ := dao.NewWorkshopProductRecordDao(ptr.transactionContext)
workshopProductRecord, err = workshopProductRecordDao.WorkshopProductRecord(cid, oid, productRecord.WorkStation.WorkStationId, planId, productRecord.CreatedAt)
if err == domain.ErrorNotFound {
workshopProductRecord = newWorkshopProductRecord(productRecord, productPlan)
workshopProductRecord = NewWorkshopProductRecord(productRecord, productPlan)
} else {
if err != nil {
log.Logger.Error(err.Error())
... ... @@ -310,9 +310,9 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain.
workshopProductRecord.ProductWeigh, productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordInfo.Original))
workshopProductRecord.UpdateProductWeigh(productRecord)
// 打料 跟 成型工段的初始产能是批次的产能
if productRecord.WorkStation.SectionName == ProductSection1 && productRecord.WorkStation.SectionName == ProductSection2 {
workshopProductRecord.AddPlanProductWeight(productPlan.PlanDevoted.Weight, productPlan.ProductPlanId)
}
//if productRecord.WorkStation.SectionName == ProductSection1 || productRecord.WorkStation.SectionName == ProductSection2 {
// workshopProductRecord.AddPlanProductWeight(productPlan.PlanDevoted.Weight, productPlan.ProductPlanId)
//}
if workshopProductRecord, err = workshopProductRecordRepository.Save(workshopProductRecord); err != nil {
// TODO:异常处理
... ... @@ -321,8 +321,8 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain.
return nil, nil
}
// newEmployeeProductRecord 员工生产记录
func newWorkshopProductRecord(productRecord *domain.ProductRecord, productPlan *domain.ProductPlan) *domain.WorkshopProductRecord {
// NewWorkshopProductRecord 车间生产记录
func NewWorkshopProductRecord(productRecord *domain.ProductRecord, productPlan *domain.ProductPlan) *domain.WorkshopProductRecord {
record := &domain.WorkshopProductRecord{
CompanyId: productRecord.CompanyId,
OrgId: productRecord.OrgId,
... ... @@ -347,7 +347,7 @@ func newWorkshopProductRecord(productRecord *domain.ProductRecord, productPlan *
}
// 打料、成型有初始值
if productRecord.WorkStation.SectionName == ProductSection1 || productRecord.WorkStation.SectionName == ProductSection2 {
record.ProductWeigh = productPlan.PlanDevoted.Weight
record.AddPlanProductWeight(productPlan.PlanDevoted.Weight, productPlan.ProductPlanId)
}
return record
}
... ...
... ... @@ -78,7 +78,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
// 封箱机、串串机需要定位到批次
if record.DeviceType == domain.DeviceTypeChuanChuanJi { //record.DeviceType == domain.DeviceTypeFengXiangJi ||
datetime, _ := time.ParseInLocation("2006-01-02", deviceRunningData.Date, time.Local)
if plan, err = ptr.findDeviceProductPlan(companyId, orgId, workStation.WorkStationId, utils.GetZeroTimeWithLocal(datetime, time.UTC), deviceRunningData.ProductType); err != nil {
if plan, err = ptr.findProductPlanAndActive(companyId, orgId, workStation, utils.GetZeroTimeWithLocal(datetime, time.UTC), deviceRunningData.ProductType); err != nil {
log.Logger.Error(err.Error(), map[string]interface{}{"workstation": workStation, "product_code": deviceRunningData.ProductType})
} else {
planId = plan.PlanDispatchRecordExt.ProductPlanId
... ... @@ -326,20 +326,29 @@ func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId,
}
// 查找设备的生产计划,如果计划没有上线的话将他上线
func (ptr *PGWorkshopDataConsumeService) findDeviceProductPlan(companyId, orgId int, workStationId string, date time.Time, productCode string) (*domain.ProductPlanDispatchRecord, error) {
func (ptr *PGWorkshopDataConsumeService) findProductPlanAndActive(companyId, orgId int, workStation *domain.WorkStation, date time.Time, productCode string) (*domain.ProductPlanDispatchRecord, error) {
planDispatchRecordDao, _ := dao.NewProductPlanDispatchRecord(ptr.transactionContext)
planDispatchRecordRepository, _ := repository.NewProductPlanDispatchRecordRepository(ptr.transactionContext)
var setPlanOnline = false
record, err := planDispatchRecordDao.DeviceProductPlan(companyId, orgId, workStationId, date, productCode, domain.PlanOnline)
record, err := planDispatchRecordDao.ProductPlanDispatchRecord(companyId, orgId, workStation.WorkStationId, date, productCode, 0)
// 未找到当前工段的调度计划,从计划管理查询是否有匹配记录,如果有在调度计划中上线
var productPlan *domain.ProductPlan
if err == domain.ErrorNotFound {
if record, err = planDispatchRecordDao.DeviceProductPlan(companyId, orgId, workStationId, date, productCode, domain.PlanOffline); err != nil {
return nil, err
} else {
setPlanOnline = true
if productPlan, err = planDispatchRecordDao.ProductPlan(companyId, orgId, workStation.WorkshopId, date, productCode); err == nil && productPlan != nil {
var productPlanDispatch = domain.NewProductPlanDispatchRecord(productPlan, workStation)
if productPlanDispatch, err = planDispatchRecordRepository.Save(productPlanDispatch); err != nil {
return nil, err
}
return productPlanDispatch, nil
}
return nil, err
}
if setPlanOnline {
record.ChangeStatus(domain.PlanOnline)
if err != nil {
return nil, err
}
if record != nil && record.PlanDispatchStatus == domain.PlanOffline {
if err = record.ChangeStatus(domain.PlanOnline); err != nil {
return nil, err
}
if record, err = planDispatchRecordRepository.Save(record); err != nil {
return nil, err
}
... ...
... ... @@ -147,12 +147,18 @@ func (repository *ProductRecordRepository) Find(queryOptions map[string]interfac
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
query.SetWhereByQueryOption("product_record_type & ? >0", "productRecordType")
query.SetWhereByQueryOption("work_station->>'workshopId'='?'", "workshopId")
query.SetWhereByQueryOption("work_station->>'lineId'='?'", "lineId")
query.SetWhereByQueryOption("work_station->>'sectionId'='?'", "sectionId")
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["productWorkerId"]; ok && v.(int) > 0 {
query.Where(`product_worker->>'userId' = '?'`, v)
}
if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`work_station->>'workshopName' like '%%%v%%'`, v))
}
... ...
... ... @@ -3,6 +3,9 @@ package beego
import (
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"net/http"
"net/http/pprof"
"os"
"strconv"
... ... @@ -39,6 +42,22 @@ func init() {
web.BConfig.Listen.HTTPSPort = port
}
}
if constant.PPROF_ON {
web.Handler("/debug/pprof/", http.HandlerFunc(pprof.Index))
web.Handler("/debug/cmdline", http.HandlerFunc(pprof.Cmdline))
web.Handler("/debug/profile", http.HandlerFunc(pprof.Profile))
web.Handler("/debug/symbol", http.HandlerFunc(pprof.Symbol))
web.Handler("/debug/trace", http.HandlerFunc(pprof.Trace))
web.Handler("/debug/allocs", pprof.Handler("allocs"))
web.Handler("/debug/block", pprof.Handler("block"))
web.Handler("/debug/goroutine", pprof.Handler("goroutine"))
web.Handler("/debug/heap", pprof.Handler("heap"))
web.Handler("/debug/mutex", pprof.Handler("mutex"))
web.Handler("/debug/threadcreate", pprof.Handler("threadcreate"))
}
web.BConfig.Listen.HTTPSCertFile = "./config/fjmaimaimai.com_bundle.crt"
web.BConfig.Listen.HTTPSKeyFile = "./config/fjmaimaimai.com.key"
web.InsertFilter("/*", web.BeforeExec, filters.AllowCors())
... ...
... ... @@ -154,6 +154,8 @@ func (controller *StatisticsController) TaskHandler() func(ctx *context.Context)
Response(ctx, nil, err)
return
}
case "13":
crontab.AutoInitWorkshopProductRecord(nil)
}
Response(ctx, nil, nil)
}
... ...