作者 yangfu

feat:

1.员工IC卡号查询
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"reflect"
"strings"
)
type GetSignInEmployeeQuery struct {
// 查询偏离量
//Offset int `cname:"查询偏离量" json:"offset"`
// 查询限制
//Limit int `cname:"查询限制" json:"limit"`
// 页码
//PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
// 页数
//PageSize int `cname:"页数" json:"pageSize,omitempty"`
// 当前公司
CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
// 当前登录的组织
OrgId int `cname:"当前登录的组织" json:"orgId,omitempty"`
// IC卡号
IcCardNumber string `cname:"IC卡号" json:"icCardNumber,omitempty"`
}
func (listProductGroupQuery *GetSignInEmployeeQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProductGroupQuery *GetSignInEmployeeQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listProductGroupQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listProductGroupQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
... ... @@ -422,6 +422,37 @@ func (productGroupService *ProductGroupService) SearchProductGroupEmployees(oper
}, nil
}
// 返回生产班组服务列表
func (productGroupService *ProductGroupService) GetSignEmployee(cmd *query.GetSignInEmployeeQuery) (interface{}, error) {
if err := cmd.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.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()
}()
var userService = domainService.NewUserService()
worker, err := userService.UserByICCode(cmd.CompanyId, cmd.OrgId, cmd.IcCardNumber)
if err != nil || worker == nil || worker.UserId == 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户不存在")
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"employee": worker,
}, nil
}
func NewProductGroupService(options map[string]interface{}) *ProductGroupService {
newProductGroupService := &ProductGroupService{}
return newProductGroupService
... ...
... ... @@ -338,8 +338,8 @@ func (productJobService *ProductJobService) SearchProductJob(operateInfo *domain
newJobDto := &dto.ProductJobDto{}
newJobDto.LoadDto(item, operateInfo.OrgId)
newJobDto.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId)
newJobDto.WorkStation.Principal = item.WorkStation.Principal
newJobDto.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId, 1)
//newJobDto.WorkStation.Principal = item.WorkStation.Principal
result = append(result, newJobDto)
}
return count, result, nil
... ...
... ... @@ -22,7 +22,7 @@ type ReceiveMaterialCommand struct {
// 工段ID
SectionId int `cname:"工段" json:"sectionId" valid:"Required"`
// 生产小组ID
ProductGroupId int `cname:"生产小组" json:"productGroupId" valid:"Required"`
ProductGroupId int `cname:"生产小组" json:"productGroupId"`
// 员工Id 用户唯一标识
EmployeeId int `cname:"员工" json:"employeeId" valid:"Required"`
// 物料ID
... ...
... ... @@ -22,7 +22,7 @@ type ReturnMaterialCommand struct {
// 工段ID
SectionId int `cname:"工段" json:"sectionId" valid:"Required"`
// 生产小组ID
ProductGroupId int `cname:"生产小组" json:"productGroupId" valid:"Required"`
ProductGroupId int `cname:"生产小组" json:"productGroupId"`
// 员工Id 用户唯一标识
EmployeeId int `cname:"员工" json:"employeeId" valid:"Required"`
// 物料ID
... ...
... ... @@ -22,7 +22,7 @@ type SubmitProductRecordCommand struct {
// 工段ID
SectionId int `cname:"工段" json:"sectionId" valid:"Required"`
// 生产小组ID
ProductGroupId int `cname:"生产小组" json:"productGroupId" valid:"Required"`
ProductGroupId int `cname:"生产小组" json:"productGroupId"`
// 员工Id 用户唯一标识
EmployeeId int `cname:"员工" json:"employeeId" valid:"Required"`
// 物料ID
... ...
... ... @@ -577,7 +577,7 @@ func (productPlanService *ProductPlanService) SearchProductPlanOnlineDispatchRec
productPlanRepository = value
}
queryOptions := utils.ObjectToMap(cmd)
//queryOptions["planDispatchStatus"] = 1
queryOptions["planDispatchStatus"] = 1
count, productPlans, err := productPlanRepository.Find(queryOptions)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
... ... @@ -16,7 +16,7 @@ type ApproveProductRecordCommand struct {
// 审核后重量
WeighAfter float64 `cname:"审核后重量" json:"weighAfter" valid:"Required"`
// 审核时间
ApproveAt string `cname:"审核时间" json:"approveAt" valid:"Required"`
//ApproveAt string `cname:"审核时间" json:"approveAt" valid:"Required"`
}
func (approveProductRecordCommand *ApproveProductRecordCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -98,6 +98,13 @@ func (workshopService *WorkshopService) GetWorkshop(getWorkshopQuery *query.GetW
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
userService := domainService.NewUserService()
if workshop.Principal.UserId > 0 {
u, _ := userService.User(workshop.Principal.UserId)
if u != nil {
workshop.Principal = u
}
}
if workshop == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getWorkshopQuery.WorkshopId)))
} else {
... ...
... ... @@ -5,15 +5,16 @@ import "os"
var MQTT_TOPIC = "/MQTT"
//设备商提供的测试地址
//var MQTT_HOST = "175.24.122.87"
//var MQTT_PORT = "1883"
//var MQTT_USER = "user111"
//var MQTT_PASSWORD = "user111"
//内网测试地址
var MQTT_HOST = "192.168.100.222"
var MQTT_HOST = "175.24.122.87"
var MQTT_PORT = "1883"
var MQTT_USER = "admin"
var MQTT_PASSWORD = "123456"
var MQTT_USER = "user111"
var MQTT_PASSWORD = "user111"
//内网测试地址
//var MQTT_HOST = "192.168.100.222"
//var MQTT_PORT = "1883"
//var MQTT_USER = "admin"
//var MQTT_PASSWORD = "123456"
func init() {
if os.Getenv("MQTT_HOST") != "" {
... ...
... ... @@ -88,6 +88,10 @@ func (workshop *Workshop) RemoveLine(lineId int) (*ProductLine, error) {
if err != nil {
return nil, err
}
sections := line.GetProductSections(NotDeleted)
if len(sections) > 0 {
return nil, fmt.Errorf("生产线:%v下存在工段,不可删除", line.LineName)
}
if line.Removed == Deleted {
return nil, fmt.Errorf("生产线:%v已删除", line.LineName)
}
... ...
... ... @@ -5,10 +5,13 @@ import "strings"
/*车间列表*/
type Workshops []*Workshop
func (m Workshops) FindWorkStation(workshopId, lineId, sectionId int) *WorkStation {
func (m Workshops) FindWorkStation(workshopId, lineId, sectionId int, flag ...int) *WorkStation {
for i := range m {
item := m[i]
workstation, err := item.FindWorkStation(workshopId, lineId, sectionId)
if len(flag) > 0 && flag[0] == 1 && workstation != nil {
workstation.Principal = item.Principal
}
if err == nil && workstation != nil {
return workstation
}
... ...
... ... @@ -39,6 +39,16 @@ func (gateway HttpLibAlliedCreationUser) UserByCode(companyId, orgId int, userCo
}
return users[0], nil
}
func (gateway HttpLibAlliedCreationUser) UserByICCode(companyId, orgId int, icCode string) (*models.User, error) {
_, users, err := gateway.UserSearch(ReqUserSearch{CompanyId: int64(companyId), OrganizationId: int64(orgId), IcCardNumber: icCode, Limit: 1, PullRealTime: true})
if err != nil {
return nil, err
}
if len(users) == 0 {
return nil, fmt.Errorf("用户不存在")
}
return users[0], nil
}
func (gateway HttpLibAlliedCreationUser) Users(userIds []int) ([]*models.User, error) {
var list = make([]*models.User, 0)
for i := range userIds {
... ...
... ... @@ -42,6 +42,8 @@ type (
InCompanyIds []interface{} `json:"inCompanyIds,omitempty"`
// 用户编号 企业内标识
UserCode string `cname:"用户编号" json:"userCode,omitempty"`
// IC卡号
IcCardNumber string `cname:"IC卡号" json:"icCardNumber,omitempty"`
// 自定义高级查询
AdvancedQuery string `json:"advancedQuery"`
... ...
... ... @@ -30,7 +30,7 @@ WITH ts_product as(
select sum(a.weight) total,a.ts from (
select
cast(device_running_record_info->>'count' as DECIMAL) weight,
to_char(product_date at time ZONE 'Asia/shanghai', 'mm:dd') ts
to_char(product_date at time ZONE 'Asia/shanghai', 'mm-dd') ts
from manufacture.device_daily_running_record
where
company_id = ?
... ... @@ -46,7 +46,7 @@ WITH ts_product as(
-- select * from ts_product
, ts_product_list as (
select d.ts,ts_product.total from (
select to_char(c.ts::timestamp,'mm:dd') ts from (
select to_char(c.ts::timestamp,'mm-dd') ts from (
select generate_series(now() - interval '6 day',now(),'1 day') ts
) c ) d left join ts_product on d.ts = ts_product.ts
)
... ...
... ... @@ -27,6 +27,14 @@ func (svr *UserService) UserByCode(companyId, orgId int, userCode string) (*doma
return svr.ToUser(rsp), nil
}
func (svr *UserService) UserByICCode(companyId, orgId int, userCode string) (*domain.User, error) {
rsp, err := svr.internalUserService.UserByICCode(companyId, orgId, userCode)
if err != nil {
return nil, err
}
return svr.ToUser(rsp), nil
}
func (svr *UserService) Users(id []int) ([]*domain.User, error) {
rsp, err := svr.internalUserService.Users(id)
if err != nil {
... ...
... ... @@ -11,6 +11,14 @@ func SendWorkshopWorkTimeStaticJob(productRecord *domain.ProductAttendanceRecord
return SendAsyncJob(domain.TaskKeyWorkshopWorkTimeRecordStatics(), productRecord)
}
func SendProductRecordStaticsJob(productRecord *domain.ProductRecord) error {
task := asynq.NewTask(domain.TaskKeyPatternProductRecordStatics(), []byte(json.MarshalToString(productRecord)))
client := asynq.NewClient(asynq.RedisClientOpt{Addr: constant.REDIS_ADDRESS})
_, err := client.Enqueue(task)
return err
}
func SendDeviceZkTecoReportJob(productRecord *domain.DeviceZkTeco) error {
return SendAsyncJob(domain.TaskDeviceZkTecoReport(), productRecord)
}
... ...
... ... @@ -75,6 +75,7 @@ func (ptr *PGCommonStatisticsService) HourProductiveStatistics(queryOptions map[
productRecordDao, _ := dao.NewProductRecordDao(ptr.transactionContext)
var response = make([]interface{}, 0)
var tmpXData = make([]string, 0)
for _, v := range workshop.GetProductLines(domain.NotDeleted) {
var result = make([]*record, 0)
if err := productRecordDao.TimeSectionProductRecord(request.CompanyId, request.OrgId, request.WorkshopId, v.LineId, SectionNameCCJ, time.Now().Add(-time.Hour*5), &result); err != nil {
... ... @@ -87,12 +88,18 @@ func (ptr *PGCommonStatisticsService) HourProductiveStatistics(queryOptions map[
xData = append(xData, r.Ts)
values = append(values, r.Total)
}
if len(tmpXData) == 0 {
tmpXData = xData
}
response = append(response, map[string]interface{}{
"lineName": v.LineName,
"data": NewXYData(xData, values),
})
}
return response, nil
return map[string]interface{}{
"xAxis": tmpXData,
"list": response,
}, nil
}
type HourProductiveStatisticsRequest struct {
... ... @@ -102,14 +109,15 @@ type HourProductiveStatisticsRequest struct {
}
func NewXYData(xData []string, values interface{}) interface{} {
return map[string]interface{}{
"xAxis": map[string]interface{}{
"data": xData,
},
"source": map[string]interface{}{
"value": values,
},
}
//return map[string]interface{}{
//"xAxis": map[string]interface{}{
// "data": xData,
//},
//"source": map[string]interface{}{
// "value": values,
//},
//}
return values
}
// 时段产能-统计 (传串设备)
... ... @@ -132,6 +140,8 @@ func (ptr *PGCommonStatisticsService) DailyProductiveStatistics(queryOptions map
productRecordDao, _ := dao.NewDeviceDailyRunningRecordDao(ptr.transactionContext)
var response = make([]interface{}, 0)
var tmpXData = make([]string, 0)
for _, v := range workshop.GetProductLines(domain.NotDeleted) {
var result = make([]*record, 0)
if err := productRecordDao.TimeSectionRunningRecord(request.CompanyId, request.OrgId, request.WorkshopId, v.LineId, SectionNameCCJ, time.Now().Add(-time.Hour*24*7), &result); err != nil {
... ... @@ -144,13 +154,19 @@ func (ptr *PGCommonStatisticsService) DailyProductiveStatistics(queryOptions map
xData = append(xData, r.Ts)
values = append(values, r.Total)
}
if len(tmpXData) == 0 {
tmpXData = xData
}
response = append(response, map[string]interface{}{
"lineName": v.LineName,
"data": NewXYData(xData, values),
})
}
return map[string]interface{}{
"recent_7_day": response,
"recent_7_day": map[string]interface{}{
"xAxis": tmpXData,
"list": response,
},
}, nil
}
... ...
... ... @@ -2,11 +2,8 @@ package domainService
import (
"fmt"
"github.com/hibiken/asynq"
"github.com/linmadan/egglib-go/core/application"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/json"
"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/repository"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
... ... @@ -32,7 +29,7 @@ type SubmitOptions struct {
// 工段ID
SectionId int `cname:"工段" json:"sectionId" valid:"Required"`
// 生产小组ID
ProductGroupId int `cname:"生产小组" json:"productGroupId" valid:"Required"`
ProductGroupId int `cname:"生产小组" json:"productGroupId"`
// 员工Id 用户唯一标识
EmployeeId int `cname:"员工" json:"employeeId" valid:"Required"`
// 物料ID
... ... @@ -209,14 +206,6 @@ func (ptr *PGProductRecordService) BatchApprove(list []*domain.ProductRecord, ap
return struct{}{}, nil
}
func SendProductRecordStaticsJob(productRecord *domain.ProductRecord) error {
task := asynq.NewTask(domain.TaskKeyPatternProductRecordStatics(), []byte(json.MarshalToString(productRecord)))
client := asynq.NewClient(asynq.RedisClientOpt{Addr: constant.REDIS_ADDRESS})
_, err := client.Enqueue(task)
return err
}
func NewPGProductRecordService(transactionContext *pgTransaction.TransactionContext) (*PGProductRecordService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...
... ... @@ -89,3 +89,14 @@ func (controller *ProductGroupController) SearchProductGroupEmployees() {
_, data, err := productGroupService.SearchProductGroupEmployees(operateInfo, cmd)
controller.Response(data, err)
}
func (controller *ProductGroupController) GetSignInEmployeeQuery() {
productGroupService := service.NewProductGroupService(nil)
cmd := &query.GetSignInEmployeeQuery{}
Must(controller.Unmarshal(cmd))
operateInfo := ParseOperateInfo(controller.BaseController)
cmd.OrgId = operateInfo.OrgId
cmd.CompanyId = operateInfo.CompanyId
data, err := productGroupService.GetSignEmployee(cmd)
controller.Response(data, err)
}
... ...
... ... @@ -14,4 +14,5 @@ func init() {
web.Router("/product-groups/", &controllers.ProductGroupController{}, "Get:ListProductGroup")
web.Router("/product-groups/search", &controllers.ProductGroupController{}, "Post:SearchProductGroup")
web.Router("/product-groups/employees", &controllers.ProductGroupController{}, "Post:SearchProductGroupEmployees")
web.Router("/product-groups/employee-signing", &controllers.ProductGroupController{}, "Post:GetSignInEmployeeQuery")
}
... ...