作者 Your Name

Merge branch 'dev' into test

... ... @@ -260,7 +260,7 @@ func (srv ProductTroubleService) ListProductTrouble(param *query.ListProductTrou
offset := param.PageSize * (param.PageNumber - 1)
condition := map[string]interface{}{
"limit": limit,
"offsett": offset,
"offset": offset,
"companyId": param.CompanyId,
"orgId": param.OrgId,
}
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
pgTransaction "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/infrastructure/dao"
)
//车间看板(生产)
// 车间描述
func (svr *CommonStatisticsService) WorkshopDesc() (interface{}, 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()
}()
boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
workshopDesc, err := boardShowData.WorkshopDesc(
constant.MANUFACTURE_DEFAULT_COMPANYID,
constant.MANUFACTURE_DEFAULT_ORGID,
constant.MANUFACTURE_DEFAULT_WORKSHOPID,
)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
//在岗人数
onDuty, err := boardShowData.OnDutyCount(
constant.MANUFACTURE_DEFAULT_COMPANYID,
constant.MANUFACTURE_DEFAULT_ORGID,
constant.MANUFACTURE_DEFAULT_WORKSHOPID,
)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
result := map[string]interface{}{
"lines": workshopDesc.Lines,
"uname": workshopDesc.Uname,
"workon": workshopDesc.Workon,
"workshopName": workshopDesc.WorkshopName,
"onDuty": onDuty,
}
return result, nil
}
// 员工效率排名
func (svr *CommonStatisticsService) EmployeeWorkpieceRatio() (interface{}, 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()
}()
boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
result, err := boardShowData.EmployeeWorkpieceRatio(
constant.MANUFACTURE_DEFAULT_COMPANYID,
constant.MANUFACTURE_DEFAULT_ORGID,
constant.MANUFACTURE_DEFAULT_WORKSHOPID,
)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
listData := map[string]interface{}{
"list": result,
}
return listData, nil
}
// TimeSectionProductRecord 时段产能
func (svr *CommonStatisticsService) TimeSectionProductRecord() (interface{}, 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()
}()
boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
// todo
result, err := boardShowData.TimeSectionProductRecord(
constant.MANUFACTURE_DEFAULT_COMPANYID,
constant.MANUFACTURE_DEFAULT_ORGID,
constant.MANUFACTURE_DEFAULT_WORKSHOPID,
0, 0,
)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
listData := map[string]interface{}{
"list": result,
}
return listData, nil
}
// TopShow 今日昨日历史最佳
func (svr *CommonStatisticsService) TopShow() (interface{}, 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()
}()
boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
result, err := boardShowData.TopShow(
constant.MANUFACTURE_DEFAULT_COMPANYID,
constant.MANUFACTURE_DEFAULT_ORGID,
constant.MANUFACTURE_DEFAULT_WORKSHOPID,
)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return result, nil
}
// ProportionOfSecondLevel 二级品占比
func (svr *CommonStatisticsService) ProportionOfSecondLevel() (interface{}, 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()
}()
boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
result, err := boardShowData.ProportionOfSecondLevel(
constant.MANUFACTURE_DEFAULT_COMPANYID,
constant.MANUFACTURE_DEFAULT_ORGID,
constant.MANUFACTURE_DEFAULT_WORKSHOPID,
)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
listData := map[string]interface{}{
"list": result,
}
return listData, nil
}
// SectionProductInfo 工段生产信息
func (svr *CommonStatisticsService) SectionProductInfo() (interface{}, 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()
}()
boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
result, err := boardShowData.ProportionOfSecondLevel(
constant.MANUFACTURE_DEFAULT_COMPANYID,
constant.MANUFACTURE_DEFAULT_ORGID,
constant.MANUFACTURE_DEFAULT_WORKSHOPID,
)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
listData := map[string]interface{}{
"list": result,
}
return listData, nil
}
// WorkshopPlanCompletionCurrent 当前计划达成率
func (svr *CommonStatisticsService) WorkshopPlanCompletionCurrent() (interface{}, 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()
}()
boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
result, err := boardShowData.WorkshopPlanCompletionCurrent(
constant.MANUFACTURE_DEFAULT_COMPANYID,
constant.MANUFACTURE_DEFAULT_ORGID,
constant.MANUFACTURE_DEFAULT_WORKSHOPID,
)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
listData := map[string]interface{}{
"rate": result,
}
return listData, nil
}
// WorkshopPlanCompletion5Day 近5天计划达成率
func (svr *CommonStatisticsService) WorkshopPlanCompletion5Day() (interface{}, 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()
}()
boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
result, err := boardShowData.WorkshopPlanCompletion5Day(
constant.MANUFACTURE_DEFAULT_COMPANYID,
constant.MANUFACTURE_DEFAULT_ORGID,
constant.MANUFACTURE_DEFAULT_WORKSHOPID,
)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
listData := map[string]interface{}{
"list": result,
}
return listData, nil
}
// 批次产能
func (svr *CommonStatisticsService) ProductPlan() (interface{}, 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()
}()
boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
result, err := boardShowData.ProductPlan(
constant.MANUFACTURE_DEFAULT_COMPANYID,
constant.MANUFACTURE_DEFAULT_ORGID,
constant.MANUFACTURE_DEFAULT_WORKSHOPID,
)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
listData := map[string]interface{}{
"list": result,
}
return listData, nil
}
... ...
package dao
import pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)
//车间看板(生产)的展示数据
... ... @@ -8,6 +12,16 @@ type BoardShowDao struct {
transactionContext *pgTransaction.TransactionContext
}
func NewBoardShowDao(transactionContext *pgTransaction.TransactionContext) (*BoardShowDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &BoardShowDao{
transactionContext: transactionContext,
}, nil
}
}
type BoardWorkshopDesc struct {
WorkshopName string `json:"workshopName"`
Uname string `json:"uname"`
... ... @@ -15,7 +29,7 @@ type BoardWorkshopDesc struct {
Workon string `json:"workon"`
}
//WorkshopDesc 车间描述
// WorkshopDesc 车间描述
func (d *BoardShowDao) WorkshopDesc(companyId int, orgId int, workshopId int) (*BoardWorkshopDesc, error) {
sqlStr := `with workshop as (
select a.workshop_name,a.uname,a.line->>'lineName' linename from (
... ... @@ -41,7 +55,7 @@ func (d *BoardShowDao) WorkshopDesc(companyId int, orgId int, workshopId int) (*
return &result, nil
}
//在岗人数
// 在岗人数
func (d *BoardShowDao) OnDutyCount(companyId int, orgId int, workshopId int) (int, error) {
sqlStr := `select count(distinct product_worker->>'userId') from manufacture.product_attendance_record
where company_id = ?
... ... @@ -54,7 +68,7 @@ func (d *BoardShowDao) OnDutyCount(companyId int, orgId int, workshopId int) (in
return cnt, err
}
//员工效率排名
// 员工效率排名
type BoardEmployeeWorkpieceRatio struct {
Uname string `json:"uname"`
Today string `json:"today"`
... ... @@ -62,7 +76,7 @@ type BoardEmployeeWorkpieceRatio struct {
History string `json:"history"`
}
//员工效率排名
// 员工效率排名
func (d *BoardShowDao) EmployeeWorkpieceRatio(companyId int, orgId int, workshopId int) (
[]BoardEmployeeWorkpieceRatio, error) {
sqlStr := `with employee_plan_product as(
... ... @@ -92,14 +106,14 @@ func (d *BoardShowDao) EmployeeWorkpieceRatio(companyId int, orgId int, workshop
return result, nil
}
//时段产能
// 时段产能
type BoardTimeSectionProductRecord struct {
Ts string `json:"ts"`
Total string `json:"total"`
Line string `json:"line"`
}
//TimeSectionProductRecord 时段产能
// TimeSectionProductRecord 时段产能
func (d *BoardShowDao) TimeSectionProductRecord(companyId int, orgId int, workshopId int, lineIdA int, lineIdB int) (
[]BoardTimeSectionProductRecord, error,
) {
... ... @@ -178,14 +192,14 @@ func (d *BoardShowDao) TimeSectionProductRecord(companyId int, orgId int, worksh
return result, err
}
//今日昨日历史最佳
// 今日昨日历史最佳
type BoardTopShow struct {
Today string `json:"today"`
Yesterday string `json:"yesterday"`
History string `json:"history"`
}
//TopShop 今日昨日历史最佳
// TopShop 今日昨日历史最佳
func (d *BoardShowDao) TopShow(companyId int, orgId int, workshopId int) (*BoardTopShow, error) {
sqlStr := `with today_product as (
select
... ... @@ -225,13 +239,13 @@ func (d *BoardShowDao) TopShow(companyId int, orgId int, workshopId int) (*Board
return &result, err
}
//二级品占比
// 二级品占比
type BoardProportionOfSecondLevel struct {
Sname string `json:"sname"` //品名
Rate string `json:"rate"` //占比
}
//二级品占比
// 二级品占比
func (d *BoardShowDao) ProportionOfSecondLevel(companyId int, orgId int, workshopId int) (
[]BoardProportionOfSecondLevel, error) {
sqlStr := `with item_product as (
... ... @@ -263,7 +277,7 @@ func (d *BoardShowDao) ProportionOfSecondLevel(companyId int, orgId int, worksho
return result, err
}
//工段生产信息
// 工段生产信息
type BoardSectionProductInfo struct {
Sname string `json:"sname"`
ProductWeight string `json:"productWeight"`
... ... @@ -273,7 +287,7 @@ type BoardSectionProductInfo struct {
Sort string `json:"sort"` //排名
}
//工段生产信息
// 工段生产信息
func (d *BoardShowDao) SectionProductInfo(companyId int, orgId int, workshopId int) (
[]BoardSectionProductInfo, error) {
sqlStr := `with section_product as(
... ... @@ -322,7 +336,7 @@ func (d *BoardShowDao) SectionProductInfo(companyId int, orgId int, workshopId i
return result, err
}
//当前计划达成率
// 当前计划达成率
func (d *BoardShowDao) WorkshopPlanCompletionCurrent(companyId int, orgId int, workshopId int) (string, error) {
sqlStr := `select rate rate from manufacture.workshop_plan_completion_record where
company_id = ?
... ... @@ -339,23 +353,82 @@ func (d *BoardShowDao) WorkshopPlanCompletionCurrent(companyId int, orgId int, w
return result, err
}
//近5天 计划达成率
func (d *BoardShowDao) WorkshopPlanCompletion5Day(companyId int, orgId int, workshopId int) {
// sqlStr := `with ts_product as (
// select rate,
// to_char(created_at,'mm-dd') ts
// from manufacture.workshop_plan_completion_record
// where company_id = 23
// and org_id = 487
// and workshop_id= 38
// and created_at > (now()-interval '6d')
// )
// ,ts_product_list as (
// select d.ts,ts_product.rate from (
// select to_char(c.ts::timestamp,'mm-dd') ts from (
// select generate_series(now() - interval '4 day',now(),'1 day') ts
// ) c ) d left join ts_product on d.ts = ts_product.ts
// )
// SELECT ts, coalesce(rate,0) total
// from ts_product_list`
type PlanCompletion5Day struct {
Ts string `jsonL:"ts"`
Total string `json:"total"`
}
// 近5天 计划达成率
func (d *BoardShowDao) WorkshopPlanCompletion5Day(companyId int, orgId int, workshopId int) ([]PlanCompletion5Day, error) {
sqlStr := `with ts_product as (
select rate,
to_char(created_at,'mm-dd') ts
from manufacture.workshop_plan_completion_record
where company_id = ?
and org_id = ?
and workshop_id= ?
and created_at > (now()-interval '6d')
)
,ts_product_list as (
select d.ts,ts_product.rate from (
select to_char(c.ts::timestamp,'mm-dd') ts from (
select generate_series(now() - interval '4 day',now(),'1 day') ts
) c ) d left join ts_product on d.ts = ts_product.ts
)
SELECT ts, coalesce(rate,0) total
from ts_product_list`
var result []PlanCompletion5Day
condition := []interface{}{
companyId, orgId, workshopId,
}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
// product_plan 批次产能
func (d *BoardShowDao) ProductPlan(companyId int, orgId int, workshopId int) ([]PlanCompletion5Day, error) {
sqlStr := `with product_record as (
select
(case when product_record_type=1 then cast(product_record_info->>'weigh' as DECIMAL)
ELSE -(cast(product_record_info->>'weigh' as DECIMAL))
END) as weight,
cast(product_record_info->>'productPlanId' as INTEGER) plan_id
from manufacture.product_records
where company_id =?
and org_id = ?
and work_station->>'workshopId'='?'
and work_station->>'sectionName'='包装'
and product_record_type in (1,2)
and created_at>to_date(to_char((now() -interval '3 day'), 'YYYY-MM-DD'),'YYYY-MM-DD') --'2022-01-01' --
), product_record_sum as(
select sum(weight) weight,plan_id
from product_record
GROUP BY plan_id
)
select
a.product_plan_id
,batch_number --批次号
,plan_product_name --品名
,machine --机台
,coalesce(plan_devoted->>'unit','') unit --规格
,cast(coalesce(plan_devoted->>'quantity','0') as DECIMAL) quantity -- 数量
,cast(coalesce(plan_devoted->>'weight','0')as DECIMAL) plan_weight -- 计划重量
, coalesce(b.weight,0) real_weight --批次实际产能
from manufacture.product_plan a left join product_record_sum b on a.product_plan_id = b.plan_id
where company_id = ?
and org_id = ?
and workshop->>'workshopId'='?'
and product_date >to_date(to_char(now() -interval '3 day', 'YYYY-MM-DD'),'YYYY-MM-DD')
and cast(coalesce(plan_devoted->>'weight','0')as DECIMAL) >0
order by created_at desc`
var result []PlanCompletion5Day
condition := []interface{}{
companyId, orgId, workshopId,
companyId, orgId, workshopId,
}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
... ...
... ... @@ -125,6 +125,7 @@ func (repo *ProductTroubleRepository) Find(queryOptions map[string]interface{})
query.Where(fmt.Sprintf(`product_worker->>'userName' like '%%%v%%'`, v))
}
//TODO
cnt, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/statistics/service"
)
type BoardDataController struct {
beego.BaseController
}
func (c *BoardDataController) WorkshopDesc() {
srv := service.NewCommonStatisticsService(nil)
data, err := srv.WorkshopDesc()
c.Response(data, err)
}
func (c *BoardDataController) EmployeeWorkpieceRatio() {
srv := service.NewCommonStatisticsService(nil)
data, err := srv.EmployeeWorkpieceRatio()
c.Response(data, err)
}
func (c *BoardDataController) TimeSectionProductRecord() {
srv := service.NewCommonStatisticsService(nil)
data, err := srv.TimeSectionProductRecord()
c.Response(data, err)
}
func (c *BoardDataController) TopShow() {
srv := service.NewCommonStatisticsService(nil)
data, err := srv.TopShow()
c.Response(data, err)
}
func (c *BoardDataController) ProportionOfSecondLevel() {
srv := service.NewCommonStatisticsService(nil)
data, err := srv.ProportionOfSecondLevel()
c.Response(data, err)
}
func (c *BoardDataController) SectionProductInfo() {
srv := service.NewCommonStatisticsService(nil)
data, err := srv.SectionProductInfo()
c.Response(data, err)
}
func (c *BoardDataController) WorkshopPlanCompletionCurrent() {
srv := service.NewCommonStatisticsService(nil)
data, err := srv.WorkshopPlanCompletionCurrent()
c.Response(data, err)
}
func (c *BoardDataController) WorkshopPlanCompletion5Day() {
srv := service.NewCommonStatisticsService(nil)
data, err := srv.WorkshopPlanCompletion5Day()
c.Response(data, err)
}
func (c *BoardDataController) ProductPlan() {
srv := service.NewCommonStatisticsService(nil)
data, err := srv.ProductPlan()
c.Response(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("/workshop-public-notice/workshop", &controllers.BoardDataController{}, "Get:WorkshopDesc")
web.Router("/workshop-public-notice/employee/workpiece-ratio", &controllers.BoardDataController{}, "Get:EmployeeWorkpieceRatio")
web.Router("/workshop-public-notice/section-product-info", &controllers.BoardDataController{}, "Get:TimeSectionProductRecord")
web.Router("/workshop-public-notice/proportion-of-second-level", &controllers.BoardDataController{}, "Get:ProportionOfSecondLevel")
web.Router("/workshop-public-notice/top-show", &controllers.BoardDataController{}, "Get:TopShow")
web.Router("/workshop-public-notice/product_plan", &controllers.BoardDataController{}, "Get:ProductPlan")
web.Router("/workshop-public-notice/workshop-plan-completion/current", &controllers.BoardDataController{}, "Get:WorkshopPlanCompletionCurrent")
web.Router("/workshop-public-notice/workshop-plan-completion/5day", &controllers.BoardDataController{}, "Get:WorkshopPlanCompletion5Day")
}
... ...