作者 yangfu

feat: 车间、员工产能导出

package query
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
type ManufactureEmployeeProductiveQuery struct {
// 页码
PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
// 页数
PageSize int `cname:"页数" json:"pageSize,omitempty"`
// 车间名称
WorkshopName string `cname:"车间名称" json:"workshopName,omitempty"`
// 生产线名称
LineName string `cname:"生产线名称" json:"lineName,omitempty"`
// 工段名称
SectionName string `cname:"工段名称" json:"sectionName,omitempty"`
// 姓名
UserName string `cname:"姓名" json:"userName"`
// 员工类型 1:固定 2:派遣 3.临时
EmployeeType string `cname:"员工类型 1:固定 2:派遣 3.临时" json:"employeeType"`
// 开始时间
BeginTime string `cname:"开始时间" json:"beginTime"`
// 结束时间
EndTime string `cname:"结束时间" json:"endTime"`
//操作人
Operator domain.Operator `json:"-"`
SelectedField []string `json:"selectedField"`
}
... ...
package query
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
type ManufactureWorkshopProductiveQuery struct {
// 工段名称
SectionName string `cname:"工段名称" json:"sectionName,omitempty"`
// 品名
PlanProductName string `cname:"品名" json:"planProductName,omitempty"`
// 开始时间
BeginTime string `cname:"开始时间" json:"beginTime"`
// 结束时间
EndTime string `cname:"结束时间" json:"endTime"`
//操作人
Operator domain.Operator `json:"-"`
SelectedField []string `json:"selectedField"`
}
... ...
... ... @@ -65,3 +65,34 @@ func (srv ExcelDataService) ExportProducts(cmd *query.SearchProductQuery) (Expor
}
return ExportProductsData{SourceData: result.Grid.List, SelectedField: cmd.SelectedField}, nil
}
func (srv ExcelDataService) ExportEmployeeProductive(cmd *query.ManufactureEmployeeProductiveQuery) (ExportEmployeeProductiveData, error) {
creationUserGateway := allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(cmd.Operator)
result, err := creationUserGateway.SearchEmployeeProductive(allied_creation_manufacture.SearchEmployeeProductiveRequest{
WorkshopName: cmd.WorkshopName,
LineName: cmd.LineName,
SectionName: cmd.SectionName,
UserName: cmd.UserName,
EmployeeType: cmd.EmployeeType,
BeginTime: cmd.BeginTime,
EndTime: cmd.EndTime,
})
if err != nil {
return ExportEmployeeProductiveData{}, fmt.Errorf("获取员工产能数据失败:%w", err)
}
return ExportEmployeeProductiveData{SourceData: result.Grid.List, SelectedField: cmd.SelectedField}, nil
}
func (srv ExcelDataService) ExportWorkshopProductive(cmd *query.ManufactureWorkshopProductiveQuery) (ExportWorkshopProductiveData, error) {
creationUserGateway := allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(cmd.Operator)
result, err := creationUserGateway.SearchWorkshopProductive(allied_creation_manufacture.SearchWorkshopProductiveRequest{
SectionName: cmd.SectionName,
PlanProductName: cmd.PlanProductName,
BeginTime: cmd.BeginTime,
EndTime: cmd.EndTime,
})
if err != nil {
return ExportWorkshopProductiveData{}, fmt.Errorf("获取员工产能数据失败:%w", err)
}
return ExportWorkshopProductiveData{SourceData: result.Grid.List, SelectedField: cmd.SelectedField}, nil
}
... ...
... ... @@ -284,7 +284,7 @@ func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.Import
domain.ImportCooperationUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210926/object/1632635345_SbfzmkXjQHhCwPw4MB7zb5EBBtdp2MSE.xlsx",
domain.ImportDividendsReturnOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210927/object/1632743214_rNHm6ZBXZaC5xKTrsE7M4h45MY6n6Ff3.xlsx",
domain.ImportProducts: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20220120/object/1642670543_cbraNKjNPHcbN6RNBYQBrwhC7BXGbDWp.xlsx",
domain.ImportDevices: "",
domain.ImportDevices: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20220126/object/1643184320_hT6sY5BKHmBa4TynfSGSCGyZ2KTTtzkj.xlsx",
}
var url string
var ok bool
... ...
... ... @@ -3,6 +3,7 @@ package service
import (
"fmt"
"github.com/linmadan/egglib-go/utils/excel"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_manufacture"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)
... ... @@ -239,3 +240,171 @@ func (data ExportProductsData) DataListLen() int {
func (data ExportProductsData) TableTitle() []string {
return nil
}
//ExportEmployeeProductiveData 导出员工产能数据
type ExportEmployeeProductiveData struct {
SourceData []allied_creation_manufacture.EmployeeProductiveItem
SelectedField []string
}
var _ excel.ExcelMaker = (*ExportEmployeeProductiveData)(nil)
func (data ExportEmployeeProductiveData) AllFields() []DataFieldOptions {
return []DataFieldOptions{
{EnName: "createdAt", CnName: "日期"},
{EnName: "workshopName", CnName: "车间名称"},
{EnName: "lineName", CnName: "线别"},
{EnName: "sectionName", CnName: "工段"},
{EnName: "workOn", CnName: "班别"},
{EnName: "userName", CnName: "姓名"},
{EnName: "employeeType", CnName: "员工类型"},
{EnName: "participateType", CnName: "类别"},
{EnName: "planProductName", CnName: "品名"},
{EnName: "productWeigh", CnName: "产能"},
{EnName: "secondLevelWeigh", CnName: "二级品"},
{EnName: "qualificationRate", CnName: "合格率"},
{EnName: "orgName", CnName: "组织机构"},
}
}
func (data ExportEmployeeProductiveData) DataFieldList() []excel.DataField {
fields := []excel.DataField{}
allFields := data.AllFields()
for _, value2 := range allFields {
if len(data.SelectedField) == 0 || value2.IsDefault {
fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
continue
}
for _, value3 := range data.SelectedField {
if value2.EnName == value3 {
fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
}
}
}
return fields
}
func (data ExportEmployeeProductiveData) CellValue(index int, enName string) (value interface{}) {
if index > data.DataListLen() {
return ""
}
switch enName {
case "createdAt":
return data.SourceData[index].CreatedAt
case "workshopName":
return data.SourceData[index].WorkshopName
case "lineName":
return data.SourceData[index].LineName
case "sectionName":
return data.SourceData[index].SectionName
case "workOn":
return data.SourceData[index].WorkOn
case "userName":
return data.SourceData[index].ProductWorker.UserName
case "employeeType":
return domain.EmployeeTypeDescription(data.SourceData[index].ProductWorker.EmployeeType)
case "participateType":
return domain.ParticipateTypeDescription(data.SourceData[index].ParticipateType)
case "planProductName":
return data.SourceData[index].PlanProductName
case "productWeigh":
return fmt.Sprintf("%vKg", data.SourceData[index].ProductWeigh)
case "secondLevelWeigh":
return fmt.Sprintf("%vKg", data.SourceData[index].SecondLevelWeigh)
case "qualificationRate":
return fmt.Sprintf("%v%%", data.SourceData[index].QualificationRate)
case "orgName":
return data.SourceData[index].OrgName
}
return nil
}
func (data ExportEmployeeProductiveData) DataListLen() int {
return len(data.SourceData)
}
func (data ExportEmployeeProductiveData) TableTitle() []string {
return nil
}
//ExportWorkshopProductiveData 导出员工产能数据
type ExportWorkshopProductiveData struct {
SourceData []allied_creation_manufacture.WorkshopProductiveItem
SelectedField []string
}
var _ excel.ExcelMaker = (*ExportWorkshopProductiveData)(nil)
func (data ExportWorkshopProductiveData) AllFields() []DataFieldOptions {
return []DataFieldOptions{
{EnName: "createdAt", CnName: "日期"},
{EnName: "batchNumber", CnName: "批次号"},
{EnName: "workshopName", CnName: "车间名称"},
{EnName: "lineName", CnName: "线别"},
{EnName: "sectionName", CnName: "工段"},
{EnName: "planProductName", CnName: "品名"},
{EnName: "devotedProductWeigh", CnName: "投入量"},
{EnName: "productWeigh", CnName: "产出量"},
{EnName: "secondLevelWeigh", CnName: "二级品"},
{EnName: "qualificationRate", CnName: "出品率"},
{EnName: "orgName", CnName: "组织机构"},
}
}
func (data ExportWorkshopProductiveData) DataFieldList() []excel.DataField {
fields := []excel.DataField{}
allFields := data.AllFields()
for _, value2 := range allFields {
if len(data.SelectedField) == 0 || value2.IsDefault {
fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
continue
}
for _, value3 := range data.SelectedField {
if value2.EnName == value3 {
fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
}
}
}
return fields
}
func (data ExportWorkshopProductiveData) CellValue(index int, enName string) (value interface{}) {
if index > data.DataListLen() {
return ""
}
switch enName {
case "createdAt":
return data.SourceData[index].CreatedAt
case "batchNumber":
return data.SourceData[index].BatchNumber
case "workshopName":
return data.SourceData[index].WorkshopName
case "lineName":
return data.SourceData[index].LineName
case "sectionName":
return data.SourceData[index].SectionName
case "userName":
return data.SourceData[index].ProductWorker.UserName
case "planProductName":
return data.SourceData[index].PlanProductName
case "devotedProductWeigh":
return fmt.Sprintf("%vKg", data.SourceData[index].DevotedProductWeigh)
case "productWeigh":
return fmt.Sprintf("%vKg", data.SourceData[index].ProductWeigh)
case "secondLevelWeigh":
return fmt.Sprintf("%vKg", data.SourceData[index].SecondLevelWeigh)
case "qualificationRate":
return fmt.Sprintf("%v%%", data.SourceData[index].QualificationRate)
case "orgName":
return data.SourceData[index].OrgName
}
return nil
}
func (data ExportWorkshopProductiveData) DataListLen() int {
return len(data.SourceData)
}
func (data ExportWorkshopProductiveData) TableTitle() []string {
return nil
}
... ...
package constant
import (
"os"
"strconv"
)
var (
// 生产制造 - 称重系统 - 默认公司
MANUFACTURE_WEIGH_DEFAULT_COMPANYID = 1
// 生产制造 - 称重系统 - 默认组织
MANUFACTURE_WEIGH_DEFAULT_ORGID = 1
)
func init() {
if os.Getenv("MANUFACTURE_WEIGH_DEFAULT_COMPANY_ID") != "" {
MANUFACTURE_WEIGH_DEFAULT_COMPANYID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_WEIGH_DEFAULT_COMPANYID"))
}
if os.Getenv("MANUFACTURE_WEIGH_DEFAULT_ORGID") != "" {
MANUFACTURE_WEIGH_DEFAULT_ORGID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_WEIGH_DEFAULT_ORGID"))
}
}
... ...
... ... @@ -65,9 +65,9 @@ const (
ImportDividendsReturnOrders = "BUSINESS_ALLIED-CREATION_BONUS_RETURN"
// 导入产品
ImportProducts = "ImportProducts"
ImportProducts = "BUSINESS_ALLIED-MANUFACTURING_BASIC_PRODUCT"
// 导入设备
ImportDevices = "ImportDevices"
ImportDevices = "BUSINESS_ALLIED-MANUFACTURING_BASIC_DEVICE"
)
const (
... ... @@ -78,6 +78,10 @@ const (
// 导入产品
ExportProducts = "ExportProducts"
// 导出员工产能统计
ExportManufactureEmployeeProductive = "ExportManufactureEmployeeProductive"
// 导出车间产能统计
ExportManufactureWorkshopProductive = "ExportManufactureWorkshopProductive"
)
const (
... ... @@ -93,3 +97,26 @@ const (
const (
DefaultPassword = "4a693460c4cf078ea5b6b5a9e2cf382064a6f810" // TL123456!
)
func EmployeeTypeDescription(employeeType int) string {
if employeeType == 1 {
return "固定"
}
if employeeType == 2 {
return "派遣"
}
if employeeType == 3 {
return "临时"
}
return "固定"
}
func ParticipateTypeDescription(participateType int) string {
if participateType == 1 {
return "正常"
}
if participateType == 2 {
return "支援"
}
return "正常"
}
... ...
... ... @@ -48,7 +48,7 @@ type BatchAddProductRequest struct {
}
type BatchAddProductResponse []interface{}
//BatchAddProduct 批量添加产品
//SearchProduct 搜索产品
func (gateway HttpLibAlliedCreationManufacture) SearchProduct(param SearchProductRequest) (*SearchProductResponse, error) {
url := fmt.Sprintf("%s%s", gateway.BaseUrl(), "/products/search")
method := "post"
... ... @@ -99,3 +99,128 @@ type BatchAddDeviceRequest struct {
List []*domain.ImportDeviceItem `json:"list"`
}
type BatchAddDeviceResponse []interface{}
/**生产记录**/
//SearchProduct 搜索员工产能统计
func (gateway HttpLibAlliedCreationManufacture) SearchEmployeeProductive(param SearchEmployeeProductiveRequest) (*SearchEmployeeProductiveResponse, error) {
url := fmt.Sprintf("%s%s", gateway.BaseUrl(), "/product-records/employee-productive/search")
method := "post"
var data SearchEmployeeProductiveResponse
err := gateway.FastDoRequest(url, method, param, &data)
return &data, err
}
type (
SearchEmployeeProductiveRequest struct {
// 页码
//PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
// 页数
//PageSize int `cname:"页数" json:"pageSize,omitempty"`
// 车间名称
WorkshopName string `cname:"车间名称" json:"workshopName,omitempty"`
// 生产线名称
LineName string `cname:"生产线名称" json:"lineName,omitempty"`
// 工段名称
SectionName string `cname:"工段名称" json:"sectionName,omitempty"`
// 姓名
UserName string `cname:"姓名" json:"userName"`
// 员工类型 1:固定 2:派遣 3.临时
EmployeeType string `cname:"员工类型 1:固定 2:派遣 3.临时" json:"employeeType"`
// 开始时间
BeginTime string `cname:"开始时间" json:"beginTime"`
// 结束时间
EndTime string `cname:"结束时间" json:"endTime"`
}
SearchEmployeeProductiveResponse struct {
Grid struct {
List []EmployeeProductiveItem `json:"list"`
Total int `json:"total"`
} `json:"grid"`
}
EmployeeProductiveItem struct {
EmployeeProductRecordID int `json:"employeeProductRecordId"`
ProductWorker struct {
UserID int `json:"userId"`
UserName string `json:"userName"`
Avatar string `json:"avatar"`
Phone string `json:"phone"`
EmployeeType int `json:"employeeType"`
} `json:"productWorker"`
WorkStationID string `json:"workStationId"`
WorkshopID int `json:"workshopId"`
WorkshopName string `json:"workshopName"`
LineID int `json:"lineId"`
LineName string `json:"lineName"`
SectionID int `json:"sectionId"`
SectionName string `json:"sectionName"`
WorkOn string `json:"workOn"`
PlanProductName string `json:"planProductName"`
BatchNumber string `json:"batchNumber"`
ParticipateType int `json:"participateType"`
ProductWeigh float64 `json:"productWeigh"`
SecondLevelWeigh float64 `json:"secondLevelWeigh"`
CreatedAt string `json:"createdAt"`
OrgName string `json:"orgName"`
AuthFlag bool `json:"authFlag"`
QualificationRate int `json:"qualificationRate"`
}
)
//SearchProduct 搜索员工产能统计
func (gateway HttpLibAlliedCreationManufacture) SearchWorkshopProductive(param SearchWorkshopProductiveRequest) (*SearchWorkshopProductiveResponse, error) {
url := fmt.Sprintf("%s%s", gateway.BaseUrl(), "/product-records/workshop-productive/search")
method := "post"
var data SearchWorkshopProductiveResponse
err := gateway.FastDoRequest(url, method, param, &data)
return &data, err
}
type (
SearchWorkshopProductiveRequest struct {
// 品名
PlanProductName string `cname:"品名" json:"planProductName,omitempty"`
// 工段名称
SectionName string `cname:"工段名称" json:"sectionName,omitempty"`
// 开始时间
BeginTime string `cname:"开始时间" json:"beginTime"`
// 结束时间
EndTime string `cname:"结束时间" json:"endTime"`
}
SearchWorkshopProductiveResponse struct {
Grid struct {
List []WorkshopProductiveItem `json:"list"`
Total int `json:"total"`
} `json:"grid"`
}
WorkshopProductiveItem struct {
EmployeeProductRecordID int `json:"employeeProductRecordId"`
ProductWorker struct {
UserID int `json:"userId"`
UserName string `json:"userName"`
Avatar string `json:"avatar"`
Phone string `json:"phone"`
EmployeeType int `json:"employeeType"`
} `json:"productWorker"`
WorkStationID string `json:"workStationId"`
WorkshopID int `json:"workshopId"`
WorkshopName string `json:"workshopName"`
LineID int `json:"lineId"`
LineName string `json:"lineName"`
SectionID int `json:"sectionId"`
SectionName string `json:"sectionName"`
WorkOn string `json:"workOn"`
PlanProductName string `json:"planProductName"`
BatchNumber string `json:"batchNumber"`
//ParticipateType int `json:"participateType"`
// 投入量
DevotedProductWeigh float64 `json:"devotedProductWeigh"`
// 产能
ProductWeigh float64 `json:"productWeigh"`
// 二级品产能
SecondLevelWeigh float64 `json:"secondLevelWeigh"`
CreatedAt string `json:"createdAt"`
OrgName string `json:"orgName"`
AuthFlag bool `json:"authFlag"`
QualificationRate int `json:"qualificationRate"`
}
)
... ...
... ... @@ -271,6 +271,18 @@ func fileExport(controller *ExcelDataController, code string) {
companyUserListQuery.Operator = exportDataCommand.Operator
data, err = excelService.ExportProducts(companyUserListQuery)
filename = "导出商品"
case domain.ExportManufactureEmployeeProductive:
companyUserListQuery := &query.ManufactureEmployeeProductiveQuery{}
exportDataCommand.UnmarshalQuery(companyUserListQuery)
companyUserListQuery.Operator = exportDataCommand.Operator
data, err = excelService.ExportEmployeeProductive(companyUserListQuery)
filename = "导出员工产能统计"
case domain.ExportManufactureWorkshopProductive:
companyUserListQuery := &query.ManufactureWorkshopProductiveQuery{}
exportDataCommand.UnmarshalQuery(companyUserListQuery)
companyUserListQuery.Operator = exportDataCommand.Operator
data, err = excelService.ExportWorkshopProductive(companyUserListQuery)
filename = "导出车间产能汇总"
default:
err = fmt.Errorf("export type :%v not exists", exportDataCommand.Code)
}
... ... @@ -301,6 +313,21 @@ func (controller *ExcelDataController) ExportCooperationUser() {
fileExport(controller, domain.ExportCooperationUser)
}
// ExportProducts 导出生产制造产品
func (controller *ExcelDataController) ExportProducts() {
fileExport(controller, domain.ExportProducts)
}
// ExportManufactureEmployeeProductive 导出生产制造-员工产能统计
func (controller *ExcelDataController) ExportManufactureEmployeeProductive() {
fileExport(controller, domain.ExportManufactureEmployeeProductive)
}
// ExportManufactureEmployeeProductive 导出生产制造-车间产能统计
func (controller *ExcelDataController) ExportManufactureWorkshopProductive() {
fileExport(controller, domain.ExportManufactureWorkshopProductive)
}
//GetExcelDataFields 获取导出excel数据的可选字段
func (controller *ExcelDataController) GetExcelDataFields() {
... ...
package middleware
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_manufacture"
)
func RedirectManufactureWeigh() web.FilterFunc {
return RedirectInternalService("/v1/manufacture-weigh", allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(domain.Operator{
CompanyId: int64(constant.MANUFACTURE_WEIGH_DEFAULT_COMPANYID),
OrgId: int64(constant.MANUFACTURE_WEIGH_DEFAULT_ORGID),
}))
}
... ...
... ... @@ -8,6 +8,9 @@ import (
func init() {
web.Router("/v1/web/excel/export/company-user", &web_client.ExcelDataController{}, "Post:ExportCompanyUser")
web.Router("/v1/web/excel/export/cooperation-user", &web_client.ExcelDataController{}, "Post:ExportCooperationUser")
web.Router("/v1/web/excel/export/manufacture-products", &web_client.ExcelDataController{}, "Post:ExportProducts")
web.Router("/v1/web/excel/export/manufacture-employee-productive", &web_client.ExcelDataController{}, "Post:ExportManufactureEmployeeProductive")
web.Router("/v1/web/excel/export/manufacture-workshop-productive", &web_client.ExcelDataController{}, "Post:ExportManufactureWorkshopProductive")
web.Router("/v1/web/excel/import/dividends-orders", &web_client.ExcelDataController{}, "Post:ImportDividendsOrder")
web.Router("/v1/web/excel/import/dividends-returned-orders", &web_client.ExcelDataController{}, "Post:ImportDividendsReturnedOrder")
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/middleware"
)
func init() {
// 车间列表
web.Post("/v1/manufacture-weigh/workshops/selector", middleware.RedirectManufactureWeigh())
// 车间员工
web.Post("/v1/manufacture-weigh/product-groups/employees", middleware.RedirectManufactureWeigh())
// 生产批次列表
web.Post("/v1/manufacture-weigh/product-plans/search", middleware.RedirectManufactureWeigh())
// 物料列表
web.Post("/v1/manufacture-weigh/unit-conversions/materials", middleware.RedirectManufactureWeigh())
// 领料
web.Post("/v1/manufacture-weigh/product-plans/receive-material", middleware.RedirectManufactureWeigh())
// 退料
web.Post("/v1/manufacture-weigh/product-plans/return-material", middleware.RedirectManufactureWeigh())
// 提交二级品
web.Post("/v1/manufacture-weigh/product-plans/submit-product-record", middleware.RedirectManufactureWeigh())
}
... ...