作者 tangxuhui

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…

…ion-manufacture into dev

# Conflicts:
#	pkg/infrastructure/dao/material_k3cloud_dao.go
#	pkg/port/beego/routers/test_router.go
正在显示 83 个修改的文件 包含 3676 行增加207 行删除

要显示太多修改。

为保证性能只显示 83 of 83+ 个文件。

#project
\ No newline at end of file
# 生产制造项目说明
## 1.数据导入导出模块
### 1.1.Excel导入流程
- 原型说明
选择模板下载、文件上传
![](https://doc-press.fjmaimaimai.com/team/frontend/plugins/data-transfer-upload.png)
导入数据检验有错,显示具体错误
![](https://timeless-world.oss-cn-shenzhen.aliyuncs.com/opportunity/dev_online/20220225/object/1645791913_Rz2JJkkx6xEXtAFdXDH5eH6NTjfhtjxf.jpg)
- [导入接口文档地址](https://doc-press.fjmaimaimai.com/team/frontend/plugins/business/import.html)
```
POST/v1/web/file-import
Content-Type multipart/form-data
params:
file 文件
code 对应导入模块的编码
```
- ``对接步骤``以导入公司用户模块为例
1.定义接口导入的``code``为``ADMIN_SYSTEM-MANAGE_BASE_USER``
2.根据接口解析导入文件的数据
3.调用基础库解析数据并传到后台
```go
// 1.解析列
excelImport := excel.NewExcelImport()
excelImport.RowBegin = 3 //第二行开始读取
excelImport.DataFields = []excel.DataField{
{EnName: "userCode", CnName: "*用户编码"},
{EnName: "userName", CnName: "*用户姓名"},
{EnName: "org", CnName: "*组织机构"},
{EnName: "department", CnName: "*所属部门"},
{EnName: "enableStatus", CnName: "*用户状态"},
{EnName: "phone", CnName: "*手机号"},
{EnName: "employeeType", CnName: "*员工类型"},
{EnName: "icCardNumber", CnName: "IC卡号"},
{EnName: "email", CnName: "邮箱"},
}
excelData, err := excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
users := make([]allied_creation_user.BatchAddUserItem, 0)
for _, v := range excelData {
if srv.fieldValueAllEmpty(v) {
continue
}
item := allied_creation_user.BatchAddUserItem{
CompanyId: importDataCommand.Operator.CompanyId,
UserType: domain.UserTypeEmployee,
UserCode: strings.TrimSpace(v["userCode"]),
Org: strings.TrimSpace(v["org"]),
Department: strings.TrimSpace(v["department"]),
UserName: strings.TrimSpace(v["userName"]),
Phone: strings.TrimSpace(v["phone"]),
Email: strings.TrimSpace(v["email"]),
EnableStatus: strings.TrimSpace(v["enableStatus"]),
EmployeeType: strings.TrimSpace(v["employeeType"]),
IcCardNumber: strings.TrimSpace(v["icCardNumber"]),
}
users = append(users, item)
}
// 2.向后台服务发起批量添加请求
userGateway := allied_creation_user.NewHttplibAlliedCreationUser(importDataCommand.Operator)
result, err := userGateway.UserBatchAdd(allied_creation_user.ReqBatchAddUser{
Users: users,
Password: initPassword,
})
```
```go
```
### 2.2 Excel导出流程
- 功能原型说明
实现可以自定义选择列进行导出,以及选择导出格式,导出格式有 ``xlsx``\\``csv``,功能如下图所示:
![](https://timeless-world.oss-cn-shenzhen.aliyuncs.com/opportunity/dev_online/20220225/object/1645789890_JbTa22EtANsD3fm2nJ4aH6FJkHzXaHJB.png)
- 前后端交互说明
``接口定义``
导出接口
```shell
POST /v1/web/file-export
// request 请求参数
{
// 业务编码
"code":"string"
// 选择的导出的列
"fields":[]
// 导出文件格式
"format":"xlsx"
// 业务查询条件
"where":{}
}
```
导出列查询接口
```shell
GET/v1/web/file-export/fields/:code
// response 应答数据
{
"fields":[
{
"enName":"字段键名",
"cnName":"字段展示名称",
"selected":true // 默认勾选
}
]
}
```
- 交互流程
1.前台根据 ``导出列查询接口`` 获取可以导出的列;
2.勾选需要导出的列、文件格式,调用 ``导出接口`` 向后台发起导出数据请求;
#### 2.2.1 后端导出实现
1. 导出数据实现接口
```
type ExcelMaker interface {
DataFieldList() []DataField //字段元数据列表
CellValue(index int, enName string) (value interface{}) //获取单元格字段值
DataListLen() int //数据列表大小
TableTitle() []string //列表顶部自定义内容
}
```
如下所示
```go
//ExportCooperationUserData 导出共创用户数据
type ExportCooperationUserData struct {
SourceData []allied_creation_user.UserDetail //具体数据
SelectedField []string
}
var _ excel.ExcelMaker = (*ExportCooperationUserData)(nil)
func (data ExportCooperationUserData) AllFields() []DataFieldOptions {
return []DataFieldOptions{
{EnName: "UserCode", CnName: "用户编码"},
{EnName: "UserName", CnName: "用户姓名"},
{EnName: "Phone", CnName: "手机号"},
{EnName: "CooperationCompany", CnName: "共创公司"},
{EnName: "CooperationDeadline", CnName: "共创到期"},
{EnName: "EnableStatus", CnName: "状态"},
}
}
func (data ExportCooperationUserData) 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 ExportCooperationUserData) CellValue(index int, enName string) (value interface{}) {
if index > data.DataListLen() {
return ""
}
switch enName {
case "UserCode":
return data.SourceData[index].UserCode
case "UserName":
return data.SourceData[index].UserInfo.UserName
case "CooperationCompany":
return data.SourceData[index].CooperationInfo.CooperationCompany
case "CooperationDeadline":
if data.SourceData[index].CooperationInfo.CooperationDeadline.IsZero() || data.SourceData[index].CooperationInfo.CooperationDeadline.Unix() == 0 {
return ""
}
return data.SourceData[index].CooperationInfo.CooperationDeadline.Format("2006-01-02")
case "Phone":
return data.SourceData[index].UserInfo.Phone
case "Email":
return data.SourceData[index].UserInfo.Email
case "EnableStatus":
status := data.SourceData[index].EnableStatus
statusName := ""
// 状态(1:启用 2:禁用 3:注销)
switch status {
case 1:
statusName = "启用"
case 2:
statusName = "禁用"
case 3:
statusName = "注销"
}
return statusName
}
return nil
}
func (data ExportCooperationUserData) DataListLen() int {
return len(data.SourceData)
}
func (data ExportCooperationUserData) TableTitle() []string {
return nil
}
```
2. 返回文件
```go
//返回文件
excelTool := excel.NewExcelExport()
err = excelTool.ExportData(data, "")
controller.responseExcelByFile(controller.Ctx, excelTool, filename)
func (controller *ExcelDataController) responseExcelByFile(ctx *context.Context, excelExport *excel.ExcelExport, fileName string) error {
ctx.Output.Header("Content-Disposition", "attachment; filename="+fileName)
ctx.Output.Header("Content-Description", "File Transfer")
ctx.Output.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
ctx.Output.Header("Content-Transfer-Encoding", "binary")
ctx.Output.Header("Expires", "0")
ctx.Output.Header("Cache-Control", "must-revalidate")
ctx.Output.Header("Pragma", "public")
//跳过保存文件,直接写入ctx.ResponseWriter
excelExport.ExcelFile.Write(ctx.ResponseWriter)
return nil
}
```
... ...
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAy0OxRf+NheQG9epxbrudwnrzqVgqK5zCuRAkLUgaSMATVXEA
iDzJN39om+Q49MmtEk4pXGzKUyzkFJG96PA8tJq0E+bSDtSK3n+2mjZb6pChmgHw
KEX7T8ZVLqJBSrfrI4Z2BJDNEC+3wvVW3zpog1RlfKgft6NYUzNLUqE5Mxzq7lpD
eRsq+FhzM1sOeEb2dAmUlDDs+7HcR3Kj0ttKeg+hKqIottQ/H6Tq4c8deEQGnO0+
RN3CygyETbYmLuWttI/sUltulWJALIuU81Yr6uCOq5MSt2WsU8CTuhRwGXSvcQCO
FLYppYktoMDOGIBQffmJc/DdT1d35fvdpKbm+QIDAQABAoIBAQC8X7+qX2uI6gqJ
XPxC4x0RX2DxUAPE50KOv6bHUEsLoPZJ+K/Fko/oHuuTja47Lax3inhKb4gSDUhS
x754YivgNH8u8ns5wz/vc+yGflowyFj7oVAwAqslA2luDnD0Df6crcAx+wAQQCjN
RRF9T2QMUeq73BOI3Ji+gosLyN55vms2KadrwpPQwYN7qhdrerE7vPqCZeswzs1/
A5M9PVGBG+simNea5kv+tVJUdLi6ckGAB5KabyhpG779ckwzV/aZy3wIj4SvUvCd
bewH0xPHx5TqnMOXtzHgktClmL7hIYxy9sL14Dn0KVHbyolQ7IqmJtjXYqG84Fmx
AfyDfeABAoGBAPP820tKElrfTuZ+Z19kJBTp6I5iax2Ph10glUHLlLqJ82clI/Gl
CbMtnGmD72HfnJei82xqoVLsUkN9Sp+TSNJALh4N8rHkAtwq5kWToiAWZydwxVsp
x5OWEN3+QFIdjVW6fhg6jZSK5HHIqMdZOVvbfKP+Cv9fWWzlS7/WVTlJAoGBANVF
kol+KojM4DEASrw0s1mfPr0XvUFvKJ2TgVGR3HxAk4r0e0WwJdSfwGiB/ePcc6g5
D5dxBe8W5g3+V0DaC0f1DDNXg2MjYWoByWrurbm14FRnpMnx/UfZLo7rq8T9YrUT
Bd/y0/JasndN27bIfd60n233IYMqhV2+wBwqD3AxAoGAE2/wdHYJMk4Z9gjZ6WKL
8VKVIUq759X4XbXrzhsO1TGKP4xY6bZRKIIYtNs65dwvmHD13Yw9H+MNxqyjlkTg
h0dvpRtNW1ij1bBhOefCAbZnL2AviMyyRpKs81J/A0uxZ8P8qad4gf3ypxHqSD9W
b3fz3QivDZsl/6Pgvf6wOWkCgYEA1Cv9x5lj2WrxEu62axyG3P9nHBm055cdsf5g
JfVVg6t+3TuyM7c1O52efpnsKrdTvKTf1QrVG3INdxh0V4lUtcac16sVhBhbvml+
p0pCPMIrJe1ibKG5F7SB9B+TaEuo2nnNW2mp367JY5VqoyI8zsWk4nJ8vZAc1BGD
78EMUNECgYEAtV0pta3GuHKOLX1HMRsUsYuWjLqAbahnciF6MnjNWSonEK3VjMhI
g+krP/9sWoC3cFOG+4s96ubjDTWImvQvCrPaENdvlNwgp035bn51eFRv00QchM2H
VCS9Nhoqj5BIHl1G7Q13+tYTzjUWtteG902nWDVhgSlNLJf1rbTn34g=
-----END RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA45R02HLq/QHraf7VBf6QO4ca1StnmvztF5BLVU7txhKe9FD4
CLUhwharlUlPPjYFdqm9pFxynUqt15djEPhGVUEFeBpf931pVuPugNmZ/AVj0p8y
06eTNLphkrzCdBzISUN5E3PKglz3efIzq6ZK8vbns/XSQA9NRzAPTboe0KC0Flj4
YPP1X69aJiBOGClsAjG1EXQ6gxepBiL1Fq3GtpKHrQPFHffUXEkPZJz09x6RxpuU
CrtxUKdO6eKg89COo3xLXVpOZu94+csBAgvXqmADp/XCQELZRMTTEA4OIyz7yXoK
nmqceoHaeSv4nzDDMwzITFvWmZHDPHLuZwNSZwIDAQABAoIBAQDGPKf3b0rQLt7g
irEGsrLyl4JBE7kA4bao4vEsEz+9XLUHfoxAEX+hcFvwA1a6ixYBQmRGCp1v9AAw
HteVjZ6+XpAkCV102NJsdMlphaLDS/KjIjeE9KCeuoeJ6VC9EeFJKDQMRL2vBsov
eFGYAJeiwn4cXVHSqUGYc/2wqCJ1eRHJkvprDqIeZU8ND3uQ5Gz/5azezf8hBu2P
MUDseX1PzdvvElidxpHR1KsZTvGVFMMFWRcSDfQYSIB8EevMKQS2YwU9kmiCI3s3
qDEAc/Usj64oRLh3Wwh9V0H26zpn/XyQ5pzYmWtCGUpifGuAAQeFKc1jPN6fJy6a
WwLprqV5AoGBAP0k7btOXE5+hmMGcuiu3vWg0X3EOQf7MtMlsrMbqrzS4HbaaMqP
BW4hrQOLl8zB9vOYt0TuK0/+ONLlCgYiodqA8FkC7TUHcTyHUEIE3+QTrI23CY6z
AbJgnHew4jKhRvbLFHkrrIMWgRIDlIwk7HFwHLpU9tw2SsHMz6hWQjY1AoGBAOYl
suq/hyYHlI6ggbzkFjchlRxBFEOm8GOa6LLjuP0sxbaFXXfFUtw4YhO0WL8X9JSm
Qtsb4HVQPZMGlrY5rale4FOXBnSovt0LuPR3gX9OaK9T9x4X+gabQrlGIlcS2QRM
AvwPGlWptLLmQOgWdcZ5xOGEWdXDhIFrAK6khEmrAoGBAJDRM39YEM6G63JzGgGr
KLn0SmRcgRPjzOumQVjdlwt2yBq2UASxVTXv5f6FOU5WGGS7FP1GE1kr4m4jwVxJ
K7bI1LbXScRwgYNTFcLu7vaXmrtn3vvXxDy7sEd41a6JPQOqoge/yG0lzqjzi2Ox
K+KpdIXUXXUVSicceB+hWTeRAoGAIVuXejT2hsmUe7PB+jnpCmagsS6xnDinIRjD
36HoHzINGi5sZL7CCs9VT9vU/SWguqb6i72XpAlUU2oiEBl+FU1+ID+EnQYUW/+l
+DEWIPihbcAy0jbRc4GvgyEqOwqtT9UgnZ4myAHIAiIjiEAxI+pkYfeH+dbT7tou
iCGqVu8CgYBOF/1Ek3ex23CryLuMHg8wp0VHSSuksnurMWkg/H8qBT7NjWhVNRCi
mrjy2oCSI6TKPwVZQo15LeOuhXkfYFig667sBvo59Nz+QBQhh6NGwrSiZuYlf3F/
8mgDIjspJm4R9kFRAZZcsuHH6hHAge5Lik/yRyztxI9Vlpok6e1bEw==
-----END RSA PRIVATE KEY-----
\ No newline at end of file
... ...
-----BEGIN CERTIFICATE-----
MIIGazCCBVOgAwIBAgIQZBwijHoFToh2kjGwQ1E6bjANBgkqhkiG9w0BAQsFADBc
MQswCQYDVQQGEwJDTjEaMBgGA1UEChMRV29UcnVzIENBIExpbWl0ZWQxMTAvBgNV
BAMMKFdvVHJ1cyBPViBTZXJ2ZXIgQ0EgIFtSdW4gYnkgdGhlIElzc3Vlcl0wHhcN
MjEwMjA0MDAwMDAwWhcNMjIwMzA2MjM1OTU5WjCB0TELMAkGA1UEBhMCQ04xDzAN
BgNVBBETBjM1MDAxNTESMBAGA1UEBwwJ56aP5bee5biCMU8wTQYDVQQJDEbpqazl
sL7ljLrmuZbph4zot68yN+WPtzEj5qW85LqU5qW8NTEw44CBNTEx5a6k77yI6Ieq
6LS46K+V6aqM5Yy65YaF77yJMTAwLgYDVQQKDCfnpo/lu7rkubDkubDkubDkv6Hm
ga/np5HmioDmnInpmZDlhazlj7gxGjAYBgNVBAMMESouZmptYWltYWltYWkuY29t
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy0OxRf+NheQG9epxbrud
wnrzqVgqK5zCuRAkLUgaSMATVXEAiDzJN39om+Q49MmtEk4pXGzKUyzkFJG96PA8
tJq0E+bSDtSK3n+2mjZb6pChmgHwKEX7T8ZVLqJBSrfrI4Z2BJDNEC+3wvVW3zpo
g1RlfKgft6NYUzNLUqE5Mxzq7lpDeRsq+FhzM1sOeEb2dAmUlDDs+7HcR3Kj0ttK
eg+hKqIottQ/H6Tq4c8deEQGnO0+RN3CygyETbYmLuWttI/sUltulWJALIuU81Yr
6uCOq5MSt2WsU8CTuhRwGXSvcQCOFLYppYktoMDOGIBQffmJc/DdT1d35fvdpKbm
+QIDAQABo4ICsTCCAq0wHwYDVR0jBBgwFoAUDUmPFTN7wE+2+zo4Cfw0Fdpg3RQw
HQYDVR0OBBYEFMGZEgzwtp+UhpTAS9nmSxlo9tIlMA4GA1UdDwEB/wQEAwIFoDAM
BgNVHRMBAf8EAjAAMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjBJBgNV
HSAEQjBAMDQGCysGAQQBsjEBAgIWMCUwIwYIKwYBBQUHAgEWF2h0dHBzOi8vc2Vj
dGlnby5jb20vQ1BTMAgGBmeBDAECAjA9BgNVHR8ENjA0MDKgMKAuhixodHRwOi8v
Y3JsLmNybG9jc3AuY24vV29UcnVzT1ZTZXJ2ZXJDQV8yLmNybDBsBggrBgEFBQcB
AQRgMF4wOAYIKwYBBQUHMAKGLGh0dHA6Ly9haWEuY3Jsb2NzcC5jbi9Xb1RydXNP
VlNlcnZlckNBXzIuY3J0MCIGCCsGAQUFBzABhhZodHRwOi8vb2NzcC5jcmxvY3Nw
LmNuMIIBBQYKKwYBBAHWeQIEAgSB9gSB8wDxAHcARqVV63X6kSAwtaKJafTzfREs
QXS+/Um4havy/HD+bUcAAAF3brV9qAAABAMASDBGAiEAjrXS+1JJW9jag/XfW+kY
oL4sGGDNvcZgV35E0EcGQVACIQCjQh8k5oSFtqo7Qrbx2k3OISjfPSYRXNNsG4Ba
MyDmRwB2AN+lXqtogk8fbK3uuF9OPlrqzaISpGpejjsSwCBEXCpzAAABd261fdAA
AAQDAEcwRQIgcPQQJ3rkCFaQPKwT3rtfQkr0taPzw0KW7yqu+MtmBH0CIQChKeMk
v7Xs0z7J47lM6HTPOU+xXL2riC69LC1KCOS6GTAtBgNVHREEJjAkghEqLmZqbWFp
bWFpbWFpLmNvbYIPZmptYWltYWltYWkuY29tMA0GCSqGSIb3DQEBCwUAA4IBAQBn
+jDy7sZS0gZzwMR4hnZHWqFYcJR3wnk77xr+5Yu2ifhlxaLHE3rEY3xTR9LsPwfW
pdg2McinPCI6vs009NYIpeTiHzVDPzKu2BaUfKj+EHLwZQGfXkNhp3cpqZMiTkr/
YNqf25GXsBa+spwzyHh9MBXXCfWRfdHX7JlH5zyoLNztTp8unxaRYldjghHDA3Q7
8Fyz6OncY3I4U4KKBSq2/TTxveDW6NxTTuJTPOg3/qSIkwdOBLuIzuhxmF4D9wpl
LMHmne2CilVeg73/GAzQt/w7FzmdvaHPAOVYWzdaTNALiXJxbi7EyO8q/uNK0GqY
hljMsnA1hApG+/2sOP/P
MIIGeTCCBWGgAwIBAgIRAI8zZs95ViIzW/6yB+17fngwDQYJKoZIhvcNAQELBQAw
XDELMAkGA1UEBhMCQ04xGjAYBgNVBAoTEVdvVHJ1cyBDQSBMaW1pdGVkMTEwLwYD
VQQDDChXb1RydXMgT1YgU2VydmVyIENBICBbUnVuIGJ5IHRoZSBJc3N1ZXJdMB4X
DTIyMDIxMDAwMDAwMFoXDTIzMDMxMjIzNTk1OVowZjELMAkGA1UEBhMCQ04xEjAQ
BgNVBAgMCeemj+W7uuecgTEnMCUGA1UECgwe5aSp6IGU5L+h5oGv56eR5oqA5pyJ
6ZmQ5YWs5Y+4MRowGAYDVQQDDBEqLmZqbWFpbWFpbWFpLmNvbTCCASIwDQYJKoZI
hvcNAQEBBQADggEPADCCAQoCggEBAOOUdNhy6v0B62n+1QX+kDuHGtUrZ5r87ReQ
S1VO7cYSnvRQ+Ai1IcIWq5VJTz42BXapvaRccp1KrdeXYxD4RlVBBXgaX/d9aVbj
7oDZmfwFY9KfMtOnkzS6YZK8wnQcyElDeRNzyoJc93nyM6umSvL257P10kAPTUcw
D026HtCgtBZY+GDz9V+vWiYgThgpbAIxtRF0OoMXqQYi9RatxraSh60DxR331FxJ
D2Sc9PcekcablAq7cVCnTunioPPQjqN8S11aTmbvePnLAQIL16pgA6f1wkBC2UTE
0xAODiMs+8l6Cp5qnHqB2nkr+J8wwzMMyExb1pmRwzxy7mcDUmcCAwEAAaOCAyow
ggMmMB8GA1UdIwQYMBaAFA1JjxUze8BPtvs6OAn8NBXaYN0UMB0GA1UdDgQWBBSd
7Jpt75ZS1gDF9uvt6jq/wsM6pTAOBgNVHQ8BAf8EBAMCBaAwDAYDVR0TAQH/BAIw
ADAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwSQYDVR0gBEIwQDA0Bgsr
BgEEAbIxAQICFjAlMCMGCCsGAQUFBwIBFhdodHRwczovL3NlY3RpZ28uY29tL0NQ
UzAIBgZngQwBAgIwPQYDVR0fBDYwNDAyoDCgLoYsaHR0cDovL2NybC5jcmxvY3Nw
LmNuL1dvVHJ1c09WU2VydmVyQ0FfMi5jcmwwbAYIKwYBBQUHAQEEYDBeMDgGCCsG
AQUFBzAChixodHRwOi8vYWlhLmNybG9jc3AuY24vV29UcnVzT1ZTZXJ2ZXJDQV8y
LmNydDAiBggrBgEFBQcwAYYWaHR0cDovL29jc3AuY3Jsb2NzcC5jbjCCAX4GCisG
AQQB1nkCBAIEggFuBIIBagFoAHYArfe++nz/EMiLnT2cHj4YarRnKV3PsQwkyoWG
NOvcgooAAAF+4S03XgAABAMARzBFAiEAqR1sq52hM4f5aS3cvFX0eMSDkBy0Ezbf
8O6DPg7404sCIC+acfUKRvt4A89tcgvdK8TiAvFb1zaaN5608wtyLUcRAHcAejKM
VNi3LbYg6jjgUh7phBZwMhOFTTvSK8E6V6NS61IAAAF+4S03HAAABAMASDBGAiEA
7OiNg/IGkzMm3/NDw+oZuqDAYgigaq9Bsh67gyRDw9oCIQCexK1Oo74f6IMRebPU
Z2/U6DyiOh6bUu/qJJyyhjBHrgB1AOg+0No+9QY1MudXKLyJa8kD08vREWvs62nh
d31tBr1uAAABfuEtNwMAAAQDAEYwRAIgWcr/D/Ygi5WOeoRdpg93smwz6snU9vxL
I0CLiufIfKECIAFvFv9PMrHTyC05TIGfWfkVHqGZoPjPKRUtZyoWlMGaMC0GA1Ud
EQQmMCSCESouZmptYWltYWltYWkuY29tgg9mam1haW1haW1haS5jb20wDQYJKoZI
hvcNAQELBQADggEBAHhfZLmBvIDl9kQvKZf2IrFUNbd9/yLWnrCoKOaQejVVOGkZ
BmFpn2ZXGCfuCZUqhZQLc9xL49fkmBACQJa358pLUcrMRweZPPRPW53uGWH6N3IA
cAShUscFU9LBZ7ynbK9OG58E1O9/taJVQGd7YmjhEyA7A3oTtxjedk1ZPz1Hue/w
au5wfAg9Tl4ds8/rPTCACSYTd1HXhR9OuqDcinTdtwJrzKp3NKWpQjPvgpNcaJPA
j8JHnggP3GDe4xGNyt6CmNuZpWVm23CT7pFYwqQYTLqKB5yFRK4PUZ3PPKz49gQv
hkln6/8l93Jt5oRolk4kq6A/D64jwlNwa7EPlz8=
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIF4TCCA8mgAwIBAgIQHQgpVDhMv3SvabmRFpvwLTANBgkqhkiG9w0BAQwFADCB
... ...
apiVersion: v1
kind: Service
metadata:
name: allied-creation-manufacture
namespace: mmm-suplus-test
labels:
k8s-app: allied-creation-manufacture
spec:
ports:
- name: "http"
port: 80
targetPort: 8082
selector:
k8s-app: allied-creation-manufacture
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: allied-creation-manufacture
namespace: mmm-suplus-test
labels:
k8s-app: allied-creation-manufacture
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: allied-creation-manufacture
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference: {}
weight: 100
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- cn-hangzhou.i-bp1djh1xn7taumbue1ze
- cn-hangzhou.i-bp1djh1xn7taumbue1zd
- cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
- cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
containers:
- name: allied-creation-manufacture
image: 192.168.0.243:5000/mmm/allied-creation-manufacture:dev
imagePullPolicy: Always
ports:
- containerPort: 8082
env:
- name: POSTGRESQL_DB_NAME
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresqlalliedcreation.dbname
- name: POSTGRESQL_USER
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresql.user
- name: POSTGRESQL_PASSWORD
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresql.password
- name: POSTGRESQL_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresql.host
- name: POSTGRESQL_PORT
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresql.port
- name: REDIS_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: redis.ip
- name: REDIS_PORT
valueFrom:
configMapKeyRef:
name: suplus-config
key: redis.port
- name: REDIS_AUTH
value: ""
- name: LOG_LEVEL
value: "debug"
- name: ERROR_BASE_CODE
value: "1"
- name: ERROR_BASE_CODE_MULTIPLE
value: "2000"
- name: ENABLE_KAFKA_LOG
value: "true"
- name: HTTP_PORT
value: "8082"
- name: SERVICE_ENV
value: "dev"
- name: SUPLUS_ADMIN_BASE_HOST
value: "http://suplus-admin-base-dev.fjmaimaimai.com"
- name: ALLIED_CREATION_GATEWAY_HOST
value: "https://allied-creation-gateway-test.fjmaimaimai.com"
- name: ALLIED_CREATION_USER_HOST
value: "https://allied-creation-user-test.fjmaimaimai.com"
- name: ALLIED_CREATION_COOPERATION_HOST
value: "https://allied-creation-cooperation-test.fjmaimaimai.com"
- name: ALLIED_CREATION_BASIC_HOST
value: "https://allied-creation-basic-test.fjmaimaimai.com"
- name: ALLIED_CREATION_MANUFACTURE_HOST
value: "http://allied-creation-manufacture-test.fjmaimaimai.com"
- name: SMS_SERVE_HOST
value: "https://sms.fjmaimaimai.com:9897"
- name: SUPLUS_SALE_APP
value: "http://suplus-sale-app-gateway-test.fjmaimaimai.com"
- name: MANUFACTURE_DEFAULT_COMPANYID
value: "23"
- name: MANUFACTURE_DEFAULT_ORGID
value: "487"
\ No newline at end of file
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-test get pods | grep -q allied-creation-manufacture
if [ "$?" == "1" ];then
kubectl create -f /tmp/test/allied-creation-manufacture/allied-creation-manufacture.yaml --record
kubectl -n mmm-suplus-test get svc | grep -q allied-creation-manufacture
if [ "$?" == "0" ];then
echo "allied-creation-manufacture service install success!"
else
echo "allied-creation-manufacture service install fail!"
fi
kubectl -n mmm-suplus-test get pods | grep -q allied-creation-manufacture
if [ "$?" == "0" ];then
echo "allied-creation-manufacture deployment install success!"
else
echo "allied-creation-manufacture deployment install fail!"
fi
else
kubectl delete -f /tmp/test/allied-creation-manufacture/allied-creation-manufacture.yaml
kubectl -n mmm-suplus-test get svc | grep -q allied-creation-manufacture
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-test get svc | grep -q allied-creation-manufacture
done
kubectl -n mmm-suplus-test get pods | grep -q allied-creation-manufacture
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-test get pods | grep -q allied-creation-manufacture
done
kubectl create -f /tmp/test/allied-creation-manufacture/allied-creation-manufacture.yaml --record
kubectl -n mmm-suplus-test get svc | grep -q allied-creation-manufacture
if [ "$?" == "0" ];then
echo "allied-creation-manufacture service update success!"
else
echo "allied-creation-manufacture service update fail!"
fi
kubectl -n mmm-suplus-test get pods | grep -q allied-creation-manufacture
if [ "$?" == "0" ];then
echo "allied-creation-manufacture deployment update success!"
else
echo "allied-creation-manufacture deployment update fail!"
fi
fi
\ No newline at end of file
... ...
... ... @@ -13,6 +13,7 @@ require (
github.com/go-redis/redis v6.15.7+incompatible
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.3.0
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/moul/http2curl v1.0.0 // indirect
... ... @@ -20,6 +21,7 @@ require (
github.com/onsi/ginkgo v1.15.2
github.com/onsi/gomega v1.11.0
github.com/sergi/go-diff v1.2.0 // indirect
github.com/shopspring/decimal v1.2.0
github.com/smartystreets/goconvey v1.7.2 // indirect
github.com/stretchr/testify v1.7.0
github.com/tidwall/gjson v1.13.0
... ...
... ... @@ -61,6 +61,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dchest/siphash v1.2.1/go.mod h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBlVnOnt4=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/eapache/go-resiliency v1.1.0 h1:1NtRmCAqadE2FN4ZcN6g90TP3uk8cg9rn9eNK2197aU=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
... ... @@ -112,6 +114,8 @@ github.com/go-redis/redis v6.14.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8w
github.com/go-redis/redis v6.15.7+incompatible h1:3skhDh95XQMpnqeqNftPkQD9jL9e5e36z/1SUm6dy1U=
github.com/go-redis/redis v6.15.7+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-redis/redis/v7 v7.4.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
github.com/go-redis/redis/v8 v8.11.2 h1:WqlSpAwz8mxDSMCvbyz1Mkiqe0LE5OY4j3lgkvu1Ts0=
github.com/go-redis/redis/v8 v8.11.2/go.mod h1:DLomh7y2e3ggQXQLd1YgmvIfecPJoFl7WU5SOQ/r06M=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
... ... @@ -154,8 +158,9 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
... ... @@ -163,6 +168,7 @@ github.com/google/gops v0.3.7/go.mod h1:bj0cwMmX1X4XIJFTjR99R5sCxNssNJ8HebFNvoQl
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
... ... @@ -180,6 +186,8 @@ github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hibiken/asynq v0.21.0 h1:uH9XogJhjq/S39E0/DEPWLZQ6hHJ73UiblZTe4RzHwA=
github.com/hibiken/asynq v0.21.0/go.mod h1:tyc63ojaW8SJ5SBm8mvI4DDONsguP5HE85EEl4Qr5Ig=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/iancoleman/strcase v0.1.2/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
github.com/imkira/go-interpol v1.1.0 h1:KIiKr0VSG2CUW1hl1jpiyuzuJeKUUpC8iM1AIE7N1Vk=
... ... @@ -266,6 +274,7 @@ github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+
github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.14.2/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg=
github.com/onsi/ginkgo v1.15.2 h1:l77YT15o814C2qVL47NOyjV/6RbaP7kKdrvZnxQ3Org=
github.com/onsi/ginkgo v1.15.2/go.mod h1:Dd6YFfwBW84ETqqtL0CPyPXillHgY6XhQH3uuCCTr/o=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
... ... @@ -273,6 +282,7 @@ github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc=
github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48=
github.com/onsi/gomega v1.11.0 h1:+CqWgvj0OZycCaqclBD1pxKHAU+tOkHmQIWvDHq2aug=
github.com/onsi/gomega v1.11.0/go.mod h1:azGKhqFUon9Vuj0YmTfLSmx0FUwqXYSTl5re8lQLTUg=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
... ... @@ -314,6 +324,8 @@ github.com/richardlehane/mscfb v1.0.3 h1:rD8TBkYWkObWO0oLDFCbwMeZ4KoalxQy+QgniCj
github.com/richardlehane/mscfb v1.0.3/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
github.com/richardlehane/msoleps v1.0.1 h1:RfrALnSNXzmXLbGct/P2b4xkFz4e8Gmj/0Vj9M9xC1o=
github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
... ... @@ -325,6 +337,8 @@ github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 h1:X+yvsM2yrEktyI
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
github.com/shirou/gopsutil v0.0.0-20180427012116-c95755e4bcd7/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/siddontang/go v0.0.0-20170517070808-cb568a3e5cc0/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw=
github.com/siddontang/goredis v0.0.0-20150324035039-760763f78400/go.mod h1:DDcKzU3qCuvj/tPnimWSsZZzvk9qvkvrIL5naVBPh5s=
... ... @@ -340,6 +354,8 @@ github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec/go.mod h1:QBvMkMya+gXctz3kmljlUCu/yB3GZ6oee+dUozsezQE=
... ... @@ -432,6 +448,8 @@ go.opentelemetry.io/otel/trace v0.19.0/go.mod h1:4IXiNextNOpPnRlI4ryK69mn5iC84bj
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/automaxprocs v1.3.0 h1:II28aZoGdaglS5vVNnspf28lnZpXScxtIozx1lAjdb0=
go.uber.org/automaxprocs v1.3.0/go.mod h1:9CWT6lKIep8U41DDaPiH6eFscnTyjfTANNQNx6LrIcA=
go.uber.org/goleak v0.10.0 h1:G3eWbSNIskeRqtsN/1uI5B+eP73y3JUuBsv9AZjehb4=
go.uber.org/goleak v0.10.0/go.mod h1:VCZuO8V8mFPlL0F5J5GK1rtHV3DrFcQ1R8ryq7FK0aI=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.14.1/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
... ... @@ -540,6 +558,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
... ...
... ... @@ -2,13 +2,14 @@ package main
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/mqtt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/task"
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/log/logrus"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/mqtt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/crontab"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
... ... @@ -19,9 +20,6 @@ import (
)
func main() {
log.Logger.Info("server start ....")
log.Logger.Info(fmt.Sprintf("ENABLE_KAFKA_LOG:%v", constant.ENABLE_KAFKA_LOG))
if constant.ENABLE_KAFKA_LOG {
w, _ := logrus.NewKafkaWriter(constant.KAFKA_HOST, constant.TOPIC_LOG_STASH, false)
log.Logger.AddHook(w)
... ... @@ -33,10 +31,15 @@ func main() {
})
log.Logger.AddHook(bw)
redis.InitRedis()
log.Logger.Debug("server start ....")
log.Logger.Debug(fmt.Sprintf("ENABLE_KAFKA_LOG:%v", constant.ENABLE_KAFKA_LOG))
go mqtt.Start()
go task.Run()
cron := crontab.NewCrontabService(nil)
cron.StartCrontabTask()
defer cron.StopCrontabTask()
log.Logger.Info("server start!")
web.Run()
log.Logger.Info("server stop!")
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"reflect"
"strings"
)
type WorkerAttendanceReportCommand struct {
*domain.DeviceZkTeco
}
func (removeProductRecordCommand *WorkerAttendanceReportCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProductRecordCommand *WorkerAttendanceReportCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeProductRecordCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeProductRecordCommand).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
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"reflect"
"strings"
)
type WorkshopWorkTimeRecordStaticsCommand struct {
*domain.ProductAttendanceRecord
}
// Type is a string value that indicates the type of the task.
//func (t *ProductRecordStaticsCommand) Type() string
// Payload is the data needed for task execution.
//func (t *ProductRecordStaticsCommand) Payload() []byte
func (removeProductRecordCommand *WorkshopWorkTimeRecordStaticsCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProductRecordCommand *WorkshopWorkTimeRecordStaticsCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeProductRecordCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeProductRecordCommand).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
}
... ...
... ... @@ -2,6 +2,7 @@ package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"time"
)
type AttendanceRecordDto struct {
... ... @@ -15,7 +16,10 @@ type AttendanceRecordDto struct {
AttendanceType int `json:"attendanceType,omitempty"`
// 生产工人
ProductWorker *domain.User `json:"productWorker,omitempty"`
*domain.ProductAttendanceRecordExt
// 审核人
ApproveUser *domain.User `json:"approveUser"`
//*domain.ProductAttendanceRecordExt
ApproveAt string `json:"approveAt"`
// 工作位置
*domain.WorkStation
// 签到
... ... @@ -54,7 +58,20 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
d.ProductAttendanceRecordExt = m.Ext.AttendanceExt
//d.ProductAttendanceRecordExt = m.Ext.AttendanceExt
//if
if m.Ext.AttendanceExt != nil {
if m.Ext.AttendanceExt.ApproveUserId > 0 {
d.ApproveUser = &domain.User{
UserId: m.Ext.AttendanceExt.ApproveUserId,
UserName: m.Ext.AttendanceExt.ApproveUserName,
}
}
if m.Ext.AttendanceExt.ApproveAt > 0 {
t := time.Unix(m.Ext.AttendanceExt.ApproveAt, 0)
d.ApproveAt = t.Format("2006-01-02 15:04:05")
}
}
}
return d
}
... ...
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
type EmployeeAttendanceRecordDto struct {
// 考勤记录ID
ProductAttendanceId int `json:"productAttendanceId"`
// 签到日期
SignDate string `json:"signDate"`
// 工作位置
*domain.WorkStation
// 生产工人
ProductWorker *domain.User `json:"productWorker,omitempty"`
// 考勤类型 1.正常 2.支援
AttendanceType int `json:"attendanceType,omitempty"`
//*domain.ProductAttendanceRecordExt
// 考勤状态 1.未审核 2:已审核 4.自动审核
AttendanceStatus int `json:"attendanceStatus"`
// 考勤类型 1.正常 2.支援
AttendanceTypeDescription string `json:"attendanceTypeDescription,omitempty"`
// 员工类型描述 1:固定 2:派遣 3.临时
EmployeeTypeDescription string `json:"employeeTypeDescription,omitempty"`
// 考勤状态 1.未审核 2:已审核 4.自动审核
AttendanceStatusDescription string `json:"attendanceStatusDescription"`
// 工时
WorkTime float64 `json:"workTime"`
// 组织名称
OrgName string `json:"orgName"`
// 权限标识 (当前登录组织匹配为true,否则false)
AuthFlag bool `json:"authFlag"`
}
func (d *EmployeeAttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId int) *EmployeeAttendanceRecordDto {
d.ProductAttendanceId = m.ProductAttendanceId
d.AttendanceType = m.AttendanceType
d.ProductWorker = m.ProductWorker
d.WorkStation = m.WorkStation
if !m.SignIn.IsZero() {
//d.SignIn = m.SignIn.Format("15:04:05")
d.SignDate = m.SignIn.Format("2006-01-02")
}
d.WorkTime = m.WorkTimeAfter
//d.WorkTimeAfter = m.WorkTimeAfter
d.AttendanceStatus = m.AttendanceStatus
d.AttendanceTypeDescription = domain.ParticipateTypeDescription(m.AttendanceType)
d.EmployeeTypeDescription = domain.EmployeeTypeDescription(m.ProductWorker.EmployeeType)
d.AttendanceStatusDescription = domain.AttendanceStatusDescription(m.AttendanceStatus)
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
//d.ProductAttendanceRecordExt = m.Ext.AttendanceExt
}
return d
}
... ...
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
type WorkshopWorkTimeRecordDto struct {
// 车间工时记录ID
WorkshopWorkTimeRecordId int `json:"workshopWorkTimeRecordId"`
// 工作位置
*domain.WorkStation
// 签到日期
//SignDate string `json:"signDate"`
// 记录信息
*domain.WorkshopWorkTimeRecordInfo
// 记录日期
RecordDate string `json:"recordDate"`
// 组织名称
OrgName string `json:"orgName"`
// 权限标识 (当前登录组织匹配为true,否则false)
AuthFlag bool `json:"authFlag"`
}
func (d *WorkshopWorkTimeRecordDto) LoadDto(m *domain.WorkshopWorkTimeRecord, orgId int) *WorkshopWorkTimeRecordDto {
d.WorkshopWorkTimeRecordId = m.WorkshopWorkTimeRecordId
d.WorkStation = m.WorkStation
d.WorkshopWorkTimeRecordInfo = m.WorkshopWorkTimeRecordInfo
d.WorkStation = m.WorkStation
d.RecordDate = m.RecordDate.Format("2006-01-02")
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
//d.ProductAttendanceRecordExt = m.Ext.AttendanceExt
}
return d
}
... ...
package query
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type SearchEmployeeAttendanceQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset"`
// 查询限制
Limit int `cname:"查询限制" json:"limit"`
// 当前公司
CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
// 当前登录的组织
OrgId int `cname:"当前登录的组织" json:"orgId,omitempty" `
// 匹配多个组织
InOrgIds []int `cname:"匹配多个组织" json:"inOrgIds,omitempty" `
// 页码
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,omitempty"`
// 考勤状态 1.未审核 2:已审核 3.自动审核
AttendanceStatus int `cname:"考勤状态 1.未审核 2:已审核 3.自动审核" json:"attendanceStatus,omitempty"`
// 员工类型 1:固定 2:派遣 3.临时
EmployeeType int `cname:"1:固定 2:派遣 3.临时" json:"employeeType,omitempty"`
// 开始时间
BeginTime string `cname:"开始时间" json:"beginTime"`
// 结束时间
EndTime string `cname:"结束时间" json:"endTime"`
// 开始时间
SignBeginTime time.Time `cname:"开始时间" json:"signBeginTime"`
// 结束时间
SignEndTime time.Time `cname:"结束时间" json:"signEndTime"`
}
func (cmd *SearchEmployeeAttendanceQuery) Valid(validation *validation.Validation) {
cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize)
var err error
if len(cmd.BeginTime) > 0 {
if cmd.SignBeginTime, err = time.Parse("2006-01-02 15:04:05", cmd.BeginTime); err != nil {
log.Logger.Error(err.Error())
validation.Error("开始时间有误")
return
}
}
if len(cmd.EndTime) > 0 {
if cmd.SignEndTime, err = time.Parse("2006-01-02 15:04:05", cmd.EndTime); err != nil {
log.Logger.Error(err.Error())
validation.Error("结束时间有误")
return
}
}
cmd.AttendanceStatus = 6 // 审核 + 自动审核
}
func (cmd *SearchEmployeeAttendanceQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(cmd)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(cmd).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
}
... ...
... ... @@ -44,14 +44,16 @@ func (attendanceService *AttendanceService) ApproveAttendance(cmd *command.Appro
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err = attendance.Approve(user, cmd.WorkTimeAfter); err != nil {
if err = attendance.Approve(user, cmd.WorkTimeAfter, domain.AttendanceApproved); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if _, err := productAttendanceRecordRepository.Save(attendance); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := domainService.SendWorkshopWorkTimeStaticJob(attendance); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -117,6 +119,7 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain
ProductGroupId: productGroup.ProductGroupId,
}),
}
newAttendance.WorkTimeBefore = newAttendance.ComputeWorkTimeBefore()
var attendanceRepository domain.ProductAttendanceRecordRepository
attendanceRepository, _, _ = factory.FastPgAttendance(transactionContext, 0)
... ... @@ -310,6 +313,74 @@ func (attendanceService *AttendanceService) SearchAttendance(operateInfo *domain
return count, result, nil
}
// 员工工时统计
func (attendanceService *AttendanceService) SearchEmployeeAttendanceStatics(operateInfo *domain.OperateInfo, cmd *query.SearchEmployeeAttendanceQuery) (int64, interface{}, error) {
if err := cmd.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var attendanceRepository domain.ProductAttendanceRecordRepository
attendanceRepository, _, _ = factory.FastPgAttendance(transactionContext, 0)
queryOptions := utils.ObjectToMap(cmd)
count, attendances, err := attendanceRepository.Find(queryOptions)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var result = make([]*dto.EmployeeAttendanceRecordDto, 0)
for i := range attendances {
newItem := &dto.EmployeeAttendanceRecordDto{}
result = append(result, newItem.LoadDto(attendances[i], operateInfo.OrgId))
}
return count, result, nil
}
// 车间工时统计
func (attendanceService *AttendanceService) SearchWorkshopWorkTimeStatics(operateInfo *domain.OperateInfo, cmd *query.SearchEmployeeAttendanceQuery) (int64, interface{}, error) {
if err := cmd.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var attendanceRepository domain.WorkshopWorkTimeRecordRepository
attendanceRepository, _, _ = factory.FastPgWorkshopWorkTimeRecord(transactionContext, 0)
queryOptions := utils.ObjectToMap(cmd)
count, attendances, err := attendanceRepository.Find(queryOptions)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var result = make([]*dto.WorkshopWorkTimeRecordDto, 0)
for i := range attendances {
newItem := &dto.WorkshopWorkTimeRecordDto{}
result = append(result, newItem.LoadDto(attendances[i], operateInfo.OrgId))
}
return count, result, nil
}
func NewAttendanceService(options map[string]interface{}) *AttendanceService {
newAttendanceService := &AttendanceService{}
return newAttendanceService
... ...
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/attendance/command"
"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/domainService"
)
func (attendanceService *AttendanceService) WorkerAttendanceReport(cmd *command.WorkerAttendanceReportCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); 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()
}()
//svr, _ := domainService.NewPGWorkshopWorkTimeStaticService(transactionContext.(*pgTransaction.TransactionContext))
//if _, err := svr.WorkshopWorkTimeStatic(cmd.ProductAttendanceRecord); err != nil {
// log.Logger.Error(err.Error())
// return nil, err
//}
attendanceReportService, _ := domainService.NewPGWorkerAttendanceReportService(transactionContext.(*pgTransaction.TransactionContext))
if _, err := attendanceReportService.Report(constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_COMPANYID, cmd.DeviceZkTeco); 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 struct{}{}, nil
}
... ...
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/attendance/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
)
// 审核工时
func (attendanceService *AttendanceService) WorkshopWorkTimeRecordStatics(cmd *command.WorkshopWorkTimeRecordStaticsCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); 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()
}()
svr, _ := domainService.NewPGWorkshopWorkTimeStaticService(transactionContext.(*pgTransaction.TransactionContext))
if _, err := svr.WorkshopWorkTimeStatic(cmd.ProductAttendanceRecord); err != nil {
log.Logger.Error(err.Error())
return nil, err
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct{}{}, nil
}
... ...
... ... @@ -36,6 +36,15 @@ func (crontabService *CrontabService) initTask() {
return srv.PullPrdMoNewest()
})
task.AddTask("PullPrdMoK3cloud", PullPrdMoK3cloud)
autoApproveAttendanceRecord := task.NewTask("autoApproveAttendanceRecord", "0 */2 * * * *", AutoApproveProductAttendanceRecord)
task.AddTask("autoApproveAttendanceRecord", autoApproveAttendanceRecord)
autoApproveRecord := task.NewTask("autoApproveRecord", "0 */2 * * * *", AutoApproveProductRecord)
task.AddTask("autoApproveRecord", autoApproveRecord)
autoFlushDeviceDailyRunningRecord := task.NewTask("autoFlushDeviceDailyRunningRecord", "0 */1 * * * *", AutoFlushDeviceDailyRunningRecord)
task.AddTask("autoFlushDeviceDailyRunningRecord", autoFlushDeviceDailyRunningRecord)
}
func (crontabService *CrontabService) StartCrontabTask() {
... ...
package crontab
import (
"context"
"fmt"
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/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/log"
)
// 定时审核生产考勤记录
func AutoApproveProductAttendanceRecord(ctx context.Context) error {
defer func() {
if r := recover(); r != nil {
log.Logger.Error(fmt.Sprintf("%v", r))
}
}()
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()
}()
attendanceRecordDao, _ := dao.NewAttendanceRecordDao(transactionContext.(*pgTransaction.TransactionContext))
var records []*domain.ProductAttendanceRecord
_, records, err = attendanceRecordDao.RecentUnApprovedAttendanceRecord(24, 2)
if err != nil {
return err
}
approveAttendanceRecordsService, _ := domainService.NewPGApproveAttendanceRecordsService(transactionContext.(*pgTransaction.TransactionContext))
if _, err = approveAttendanceRecordsService.BatchApproveAttendanceRecords(nil, records, 0, 0, domain.AttendanceAutoApproved); err != nil {
return err
}
if err = transactionContext.CommitTransaction(); err != nil {
return err
}
return nil
}
... ...
package crontab
import (
"context"
"fmt"
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/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/log"
)
// 定时审核生产记录
func AutoApproveProductRecord(ctx context.Context) error {
defer func() {
if r := recover(); r != nil {
log.Logger.Error(fmt.Sprintf("%v", r))
}
}()
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()
}()
attendanceRecordDao, _ := dao.NewProductRecordDao(transactionContext.(*pgTransaction.TransactionContext))
var records []*domain.ProductRecord
_, records, err = attendanceRecordDao.RecentUnApprovedProductRecord(24, 2, domain.RecordTypeSecondLevelWeigh)
if err != nil {
return err
}
approveAttendanceRecordsService, _ := domainService.NewPGProductRecordService(transactionContext.(*pgTransaction.TransactionContext))
if _, err = approveAttendanceRecordsService.BatchApprove(records, 0, 0, domain.AttendanceAutoApproved); err != nil {
return err
}
if err = transactionContext.CommitTransaction(); err != nil {
return err
}
return nil
}
... ...
package crontab
import (
"context"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"time"
)
// 定时刷新设备每日运行记录
func AutoFlushDeviceDailyRunningRecord(ctx context.Context) error {
defer func() {
if r := recover(); r != nil {
log.Logger.Error(fmt.Sprintf("%v", r))
}
}()
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("【定时刷新设备每日运行记录】 启动")
deviceDailyRunningRecordRepository, _, _ := factory.FastPgDeviceDailyRunningRecord(transactionContext, 0)
// 获取redis里当天的记录
span := time.Duration(20)
t := time.Now().Add(-time.Minute * span)
records, err := redis.GetDeviceDailyAllRecord(t)
if err != nil {
log.Logger.Error(err.Error())
return err
}
for _, v := range records {
if v.UpdatedAt.Add(time.Minute * 5).Before(time.Now()) {
log.Logger.Debug(fmt.Sprintf("【定时刷新设备每日运行记录】 跳过记录 %v 最后更新时间:%v", v, v.UpdatedAt))
continue
}
// 更新设备效率 OEE = tu * pu * qu
if _, err := deviceDailyRunningRecordRepository.Save(v); err != nil {
log.Logger.Error(err.Error())
continue
} else {
log.Logger.Debug(fmt.Sprintf("【定时刷新设备每日运行记录】 刷新记录 %v", v))
}
}
if err = transactionContext.CommitTransaction(); err != nil {
return err
}
return nil
}
... ...
... ... @@ -22,11 +22,11 @@ type CreateDeviceCommand struct {
// 设备类型
DeviceType string `cname:"设备类型" json:"deviceType" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
WorkshopId int `cname:"车间ID" json:"workshopId"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
LineId int `cname:"生产线ID" json:"lineId"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
SectionId int `cname:"工段ID" json:"sectionId"`
// 品牌
Brand string `cname:"品牌" json:"brand"`
// 设备状态 1:正常 2:封存 3:报废
... ...
... ... @@ -20,13 +20,13 @@ type UpdateDeviceCommand struct {
// 设备类型
DeviceType string `cname:"设备类型" json:"deviceType" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
WorkshopId int `cname:"车间ID" json:"workshopId"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
LineId int `cname:"生产线ID" json:"lineId" `
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
SectionId int `cname:"工段ID" json:"sectionId"`
// 品牌
Brand string `cname:"品牌" json:"brand" valid:"Required"`
Brand string `cname:"品牌" json:"brand"`
// 设备状态 1:正常 2:封存 3:报废
DeviceStatus int `cname:"设备状态 1:正常 2:封存 3:报废" json:"deviceStatus" valid:"Required"`
// 风险等级 1:高 2:中 3:低
... ...
package dto
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
... ... @@ -24,7 +25,7 @@ type DeviceDto struct {
// 所属位置
*domain.WorkStation
// 生产单个产品的时间(单位:秒)
UnitProductionSecTime int `json:"unitProductionSecTime"`
UnitProductionSecTime string `json:"unitProductionSecTime"`
// 组织名称
OrgName string `json:"orgName"`
... ... @@ -36,6 +37,7 @@ func (d *DeviceDto) LoadDto(m *domain.Device, orgId int) *DeviceDto {
d.DeviceId = m.DeviceId
d.DeviceCode = m.DeviceCode
d.DeviceName = m.DeviceName
d.DeviceModel = m.DeviceModel
d.DeviceType = m.DeviceType
d.Brand = m.Brand
d.DeviceStatus = m.DeviceStatus
... ... @@ -46,7 +48,9 @@ func (d *DeviceDto) LoadDto(m *domain.Device, orgId int) *DeviceDto {
d.OrgName = m.Ext.OrgName
}
if m.Ext != nil && m.Ext.DeviceExt != nil {
d.UnitProductionSecTime = m.Ext.DeviceExt.UnitProductionSecTime
if m.Ext.DeviceExt.UnitProductionSecTime > 0 {
d.UnitProductionSecTime = fmt.Sprintf("%v", m.Ext.DeviceExt.UnitProductionSecTime)
}
}
return d
}
... ...
... ... @@ -38,9 +38,12 @@ func (deviceService *DeviceService) CreateDevice(operateInfo *domain.OperateInfo
}()
var workStation *domain.WorkStation
_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if cmd.WorkshopId != 0 {
_, workshop, err := factory.FastPgWorkshop(transactionContext, cmd.WorkshopId) //, cmd.LineId, cmd.SectionId
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
workStation, _ = workshop.FindWorkStationOrNil(cmd.WorkshopId, cmd.LineId, cmd.SectionId)
}
var userService = domainService.NewUserService()
... ... @@ -272,9 +275,16 @@ func (deviceService *DeviceService) UpdateDevice(cmd *command.UpdateDeviceComman
}
var workStation *domain.WorkStation
_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId, factory.WithSetPrincipal())
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId, factory.WithSetPrincipal())
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
if cmd.WorkshopId != 0 {
_, workshop, err := factory.FastPgWorkshop(transactionContext, cmd.WorkshopId) //, cmd.LineId, cmd.SectionId
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
workStation, _ = workshop.FindWorkStationOrNil(cmd.WorkshopId, cmd.LineId, cmd.SectionId)
}
device.WorkStation = workStation
... ... @@ -340,7 +350,9 @@ func (deviceService *DeviceService) SearchDevice(operateInfo *domain.OperateInfo
for i := range devices {
item := devices[i]
newJobDto := &dto.DeviceDto{}
item.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId)
if item.WorkStation != nil && item.WorkStation.WorkshopId > 0 {
newJobDto.WorkStation = workshops.FindWorkStationOrNil(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId)
}
newJobDto.LoadDto(item, operateInfo.OrgId)
result = append(result, newJobDto)
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CreateDeviceCollectionCommand struct {
// 数据采集ID
DeviceCollectionId int64 `cname:"数据采集ID" json:"deviceCollectionId,string" valid:"Required"`
// 车间名
WorkShopName string `cname:"车间名" json:"workShopName" valid:"Required"`
// 启动状态 1-启动 0-停止
StartupStatus int64 `cname:"启动状态 1-启动 0-停止" json:"startupStatus,string" valid:"Required"`
// 设备名
DeviceSn string `cname:"设备名" json:"deviceSn" valid:"Required"`
// 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障
ComStatus int64 `cname:"通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障" json:"comStatus,string" valid:"Required"`
// 设备数据值
Values string `cname:"设备数据值" json:"values" valid:"Required"`
}
func (createDeviceCollectionCommand *CreateDeviceCollectionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createDeviceCollectionCommand *CreateDeviceCollectionCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createDeviceCollectionCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createDeviceCollectionCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RemoveDeviceCollectionCommand struct {
// 数据采集ID
DeviceCollectionId int64 `cname:"数据采集ID" json:"deviceCollectionId,string" valid:"Required"`
}
func (removeDeviceCollectionCommand *RemoveDeviceCollectionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeDeviceCollectionCommand *RemoveDeviceCollectionCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeDeviceCollectionCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeDeviceCollectionCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type UpdateDeviceCollectionCommand struct {
// 数据采集ID
DeviceCollectionId int64 `cname:"数据采集ID" json:"deviceCollectionId,string" valid:"Required"`
// 车间名
WorkShopName string `cname:"车间名" json:"workShopName" valid:"Required"`
// 启动状态 1-启动 0-停止
StartupStatus int64 `cname:"启动状态 1-启动 0-停止" json:"startupStatus,string" valid:"Required"`
// 设备名
DeviceSn string `cname:"设备名" json:"deviceSn" valid:"Required"`
// 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障
ComStatus int64 `cname:"通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障" json:"comStatus,string" valid:"Required"`
// 设备数据值
Values string `cname:"设备数据值" json:"values" valid:"Required"`
}
func (updateDeviceCollectionCommand *UpdateDeviceCollectionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateDeviceCollectionCommand *UpdateDeviceCollectionCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateDeviceCollectionCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateDeviceCollectionCommand).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetDeviceCollectionQuery struct {
// 数据采集ID
DeviceCollectionId int64 `cname:"数据采集ID" json:"deviceCollectionId,string" valid:"Required"`
}
func (getDeviceCollectionQuery *GetDeviceCollectionQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getDeviceCollectionQuery *GetDeviceCollectionQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getDeviceCollectionQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getDeviceCollectionQuery).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ListDeviceCollectionQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listDeviceCollectionQuery *ListDeviceCollectionQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listDeviceCollectionQuery *ListDeviceCollectionQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listDeviceCollectionQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listDeviceCollectionQuery).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
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/deviceCollection/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
type DeviceCollectionService struct {
}
// 创建
func (deviceCollectionService *DeviceCollectionService) CreateDeviceCollection(createDeviceCollectionCommand *command.CreateDeviceCollectionCommand) (interface{}, error) {
if err := createDeviceCollectionCommand.ValidateCommand(); 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()
}()
newDeviceCollection := &domain.DeviceCollection{
DeviceCollectionId: createDeviceCollectionCommand.DeviceCollectionId,
WorkShopName: createDeviceCollectionCommand.WorkShopName,
StartupStatus: createDeviceCollectionCommand.StartupStatus,
DeviceSn: createDeviceCollectionCommand.DeviceSn,
ComStatus: createDeviceCollectionCommand.ComStatus,
Values: createDeviceCollectionCommand.Values,
}
var deviceCollectionRepository domain.DeviceCollectionRepository
if value, err := factory.CreateDeviceCollectionRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
deviceCollectionRepository = value
}
if deviceCollection, err := deviceCollectionRepository.Save(newDeviceCollection); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return deviceCollection, nil
}
}
// 返回
func (deviceCollectionService *DeviceCollectionService) GetDeviceCollection(getDeviceCollectionQuery *query.GetDeviceCollectionQuery) (interface{}, error) {
if err := getDeviceCollectionQuery.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 deviceCollectionRepository domain.DeviceCollectionRepository
if value, err := factory.CreateDeviceCollectionRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
deviceCollectionRepository = value
}
deviceCollection, err := deviceCollectionRepository.FindOne(map[string]interface{}{"deviceCollectionId": getDeviceCollectionQuery.DeviceCollectionId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if deviceCollection == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getDeviceCollectionQuery.DeviceCollectionId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return deviceCollection, nil
}
}
// 返回列表
func (deviceCollectionService *DeviceCollectionService) ListDeviceCollection(listDeviceCollectionQuery *query.ListDeviceCollectionQuery) (interface{}, error) {
if err := listDeviceCollectionQuery.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 deviceCollectionRepository domain.DeviceCollectionRepository
if value, err := factory.CreateDeviceCollectionRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
deviceCollectionRepository = value
}
if count, deviceCollections, err := deviceCollectionRepository.Find(tool_funs.SimpleStructToMap(listDeviceCollectionQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"deviceCollections": deviceCollections,
}, nil
}
}
// 移除
func (deviceCollectionService *DeviceCollectionService) RemoveDeviceCollection(removeDeviceCollectionCommand *command.RemoveDeviceCollectionCommand) (interface{}, error) {
if err := removeDeviceCollectionCommand.ValidateCommand(); 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 deviceCollectionRepository domain.DeviceCollectionRepository
if value, err := factory.CreateDeviceCollectionRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
deviceCollectionRepository = value
}
deviceCollection, err := deviceCollectionRepository.FindOne(map[string]interface{}{"deviceCollectionId": removeDeviceCollectionCommand.DeviceCollectionId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if deviceCollection == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeDeviceCollectionCommand.DeviceCollectionId)))
}
if deviceCollection, err := deviceCollectionRepository.Remove(deviceCollection); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return deviceCollection, nil
}
}
// 更新
func (deviceCollectionService *DeviceCollectionService) UpdateDeviceCollection(updateDeviceCollectionCommand *command.UpdateDeviceCollectionCommand) (interface{}, error) {
if err := updateDeviceCollectionCommand.ValidateCommand(); 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 deviceCollectionRepository domain.DeviceCollectionRepository
if value, err := factory.CreateDeviceCollectionRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
deviceCollectionRepository = value
}
deviceCollection, err := deviceCollectionRepository.FindOne(map[string]interface{}{"deviceCollectionId": updateDeviceCollectionCommand.DeviceCollectionId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if deviceCollection == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDeviceCollectionCommand.DeviceCollectionId)))
}
if err := deviceCollection.Update(tool_funs.SimpleStructToMap(updateDeviceCollectionCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if deviceCollection, err := deviceCollectionRepository.Save(deviceCollection); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return deviceCollection, nil
}
}
func NewDeviceCollectionService(options map[string]interface{}) *DeviceCollectionService {
newDeviceCollectionService := &DeviceCollectionService{}
return newDeviceCollectionService
}
... ...
... ... @@ -140,7 +140,7 @@ func FastPgProductGroup(transactionContext application.TransactionContext, id in
rep = value
}
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if mod, err = rep.FindOne(map[string]interface{}{"productGroupId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该生产班组不存在")
}
... ... @@ -169,7 +169,7 @@ func FastPgProduct(transactionContext application.TransactionContext, id int, op
rep = value
}
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if mod, err = rep.FindOne(map[string]interface{}{"productId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该产品不存在")
}
... ... @@ -195,7 +195,7 @@ func FastPgDevice(transactionContext application.TransactionContext, id int, opt
rep = value
}
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if mod, err = rep.FindOne(map[string]interface{}{"deviceId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该设备档案不存在")
}
... ... @@ -221,7 +221,7 @@ func FastPgProductCalendar(transactionContext application.TransactionContext, id
rep = value
}
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if mod, err = rep.FindOne(map[string]interface{}{"productCalendar": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间日历不存在")
}
... ... @@ -247,7 +247,7 @@ func FastPgUnitConversion(transactionContext application.TransactionContext, id
rep = value
}
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if mod, err = rep.FindOne(map[string]interface{}{"unitConversionId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该单位换算不存在")
}
... ... @@ -283,6 +283,32 @@ func FastPgProductPlan(transactionContext application.TransactionContext, id int
return rep, mod, err
}
// FastPgProductPlan 快速返回生产计划对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgProductPlanDispatchRecord(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductPlanDispatchRecordRepository, *domain.ProductPlanDispatchRecord, error) {
var rep domain.ProductPlanDispatchRecordRepository
var mod *domain.ProductPlanDispatchRecord
var err error
if value, err := CreateProductPlanDispatchRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productPlanDispatchRecordId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该生产计划调度记录不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
return rep, mod, err
}
// FastPgAttendance 快速返回考勤记录
//
// transactionContext 事务
... ... @@ -309,6 +335,84 @@ func FastPgAttendance(transactionContext application.TransactionContext, id int,
return rep, mod, err
}
// FastPgProductRecord 快速返回生产记录
//
// transactionContext 事务
// id 对象唯一标识
func FastPgProductRecord(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductRecordRepository, *domain.ProductRecord, error) {
var rep domain.ProductRecordRepository
var mod *domain.ProductRecord
var err error
if value, err := CreateProductRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productRecordId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该记录不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
return rep, mod, err
}
// FastPgWorkshopWorkTimeRecord 快速返回生产记录
//
// transactionContext 事务
// id 对象唯一标识
func FastPgWorkshopWorkTimeRecord(transactionContext application.TransactionContext, id int, options ...option) (domain.WorkshopWorkTimeRecordRepository, *domain.WorkshopWorkTimeRecord, error) {
var rep domain.WorkshopWorkTimeRecordRepository
var mod *domain.WorkshopWorkTimeRecord
var err error
if value, err := CreateWorkshopWorkTimeRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"workshopWorkTimeRecordId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该记录不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
return rep, mod, err
}
// FastPgDeviceDailyRunningRecord 快速返回设备每日运行记录
//
// transactionContext 事务
// id 对象唯一标识
func FastPgDeviceDailyRunningRecord(transactionContext application.TransactionContext, id int, options ...option) (domain.DeviceDailyRunningRecordRepository, *domain.DeviceDailyRunningRecord, error) {
var rep domain.DeviceDailyRunningRecordRepository
var mod *domain.DeviceDailyRunningRecord
var err error
if value, err := CreateDeviceDailyRunningRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"deviceDailyRunningRecordId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该记录不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
return rep, mod, err
}
/***** 2.配置 *****/
type FastOptions struct {
... ...
... ... @@ -85,3 +85,59 @@ func CreateWorkshopRepository(options map[string]interface{}) (domain.WorkshopRe
}
return repository.NewWorkshopRepository(transactionContext)
}
func CreateEmployeeProductRecordRepository(options map[string]interface{}) (domain.EmployeeProductRecordRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewEmployeeProductRecordRepository(transactionContext)
}
func CreateWorkshopProductRecordRepository(options map[string]interface{}) (domain.WorkshopProductRecordRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewWorkshopProductRecordRepository(transactionContext)
}
func CreateWorkshopWorkTimeRecordRepository(options map[string]interface{}) (domain.WorkshopWorkTimeRecordRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewWorkshopWorkTimeRecordRepository(transactionContext)
}
func CreateProductPlanDispatchRecordRepository(options map[string]interface{}) (domain.ProductPlanDispatchRecordRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewProductPlanDispatchRecordRepository(transactionContext)
}
func CreateDeviceCollectionRepository(options map[string]interface{}) (domain.DeviceCollectionRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewDeviceCollectionRepository(transactionContext)
}
func CreateDeviceRunningRecordRepository(options map[string]interface{}) (domain.DeviceRunningRecordRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewDeviceRunningRecordRepository(transactionContext)
}
func CreateDeviceDailyRunningRecordRepository(options map[string]interface{}) (domain.DeviceDailyRunningRecordRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewDeviceDailyRunningRecordRepository(transactionContext)
}
... ...
... ... @@ -23,7 +23,7 @@ type CreateProductCalendarCommand struct {
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
// 日历选择
CalendarSelected []string `cname:"日历选择" json:"calendarSelected" valid:"Required"`
CalendarSelected []int `cname:"日历选择" json:"calendarSelected" valid:"Required"`
// 上岗时间
InWorkAt string `cname:"上岗时间" json:"inWorkAt" valid:"Required"`
// 下岗时间
... ...
... ... @@ -2,7 +2,7 @@ package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"strings"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
)
type ProductCalendarDto struct {
... ... @@ -17,7 +17,7 @@ type ProductCalendarDto struct {
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `json:"workOn,omitempty"`
// 日历选择
CalendarSelected []string `json:"calendarSelected,omitempty"`
CalendarSelected []int `json:"calendarSelected,omitempty"`
// 上岗时间
InWorkAt string `json:"inWorkAt,omitempty"`
// 下岗时间
... ... @@ -27,7 +27,7 @@ type ProductCalendarDto struct {
// 工时 (单位 h)
WorkTime float64 `json:"workTime,omitempty"`
// 已选择日历
CalendarSelectedString string `json:"calendarSelectedString,omitempty"`
//CalendarSelectedString string `json:"calendarSelectedString,omitempty"`
// 组织名称
OrgName string `json:"orgName"`
// 权限标识 (当前登录组织匹配为true,否则false)
... ... @@ -38,12 +38,12 @@ func (d *ProductCalendarDto) LoadDto(m *domain.ProductCalendar, orgId int) *Prod
d.ProductCalendarId = m.ProductCalendarId
d.WorkStation = m.WorkStation
d.WorkOn = m.WorkOn
d.CalendarSelected = m.CalendarSelected
d.CalendarSelected = utils.ToArrayInt(m.CalendarSelected)
d.InWorkAt = m.InWorkAt
d.OutWorkAt = m.OutWorkAt
d.BreakTime = m.BreakTime
d.WorkTime = m.WorkTime
d.CalendarSelectedString = strings.Join(m.CalendarSelected, "/")
//d.CalendarSelectedString = strings.Join(m.CalendarSelected, "/")
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
... ...
... ... @@ -66,7 +66,7 @@ func (productCalendarService *ProductCalendarService) CreateProductCalendar(oper
OrgId: cmd.OrgId,
WorkStation: workStation,
WorkOn: cmd.WorkOn,
CalendarSelected: cmd.CalendarSelected,
CalendarSelected: utils.ToArrayString(cmd.CalendarSelected),
InWorkAt: cmd.InWorkAt,
OutWorkAt: cmd.OutWorkAt,
BreakTime: cmd.BreakTime,
... ... @@ -85,7 +85,10 @@ func (productCalendarService *ProductCalendarService) CreateProductCalendar(oper
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productCalendar, nil
result := &dto.ProductCalendarDto{}
result.LoadDto(productCalendar, 0)
return result, nil
}
}
... ... @@ -317,13 +320,16 @@ func (productCalendarService *ProductCalendarService) UpdateProductCalendar(cmd
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productCalendar, nil
result := &dto.ProductCalendarDto{}
result.LoadDto(productCalendar, 0)
return result, nil
}
}
// 返回工厂日历服务列表
func (productCalendarService *ProductCalendarService) SearchProductCalendar(operateInfo *domain.OperateInfo, listProductCalendarQuery *query.SearchProductCalendarQuery) (int64, interface{}, error) {
if err := listProductCalendarQuery.ValidateQuery(); err != nil {
func (productCalendarService *ProductCalendarService) SearchProductCalendar(operateInfo *domain.OperateInfo, cmd *query.SearchProductCalendarQuery) (int64, interface{}, error) {
if err := cmd.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -339,7 +345,12 @@ func (productCalendarService *ProductCalendarService) SearchProductCalendar(oper
var productCalendarRepository domain.ProductCalendarRepository
productCalendarRepository, _, _ = factory.FastPgProductCalendar(transactionContext, 0)
count, productCalendars, err := productCalendarRepository.Find(utils.ObjectToMap(listProductCalendarQuery))
workshops, _ := factory.FastPgWorkshops(transactionContext, operateInfo.CompanyId)
queryOptions := utils.ObjectToMap(cmd)
delete(queryOptions, "workshopName")
queryOptions = workshops.FindByNameWithQuery(queryOptions, cmd.WorkshopName, "", "")
count, productCalendars, err := productCalendarRepository.Find(queryOptions)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -352,6 +363,7 @@ func (productCalendarService *ProductCalendarService) SearchProductCalendar(oper
item := productCalendars[i]
newJobDto := &dto.ProductCalendarDto{}
newJobDto.LoadDto(item, operateInfo.OrgId)
newJobDto.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId)
result = append(result, newJobDto)
}
... ...
... ... @@ -25,7 +25,7 @@ type CreateProductGroupCommand struct {
// 班组长Id
GroupLeaderId int `cname:"班组长" json:"groupLeaderId,omitempty"`
// 帮组成员列表
GroupMembers []int `cname:"帮组成员列表" json:"groupMembers" valid:"Required"`
GroupMembers []int `cname:"帮组成员列表" json:"groupMembers"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
}
... ...
... ... @@ -22,7 +22,7 @@ type UpdateProductGroupCommand struct {
// 班组长Id
GroupLeaderId int `cname:"班组长" json:"groupLeaderId,omitempty"`
// 帮组成员列表
GroupMembers []int `cname:"帮组成员列表" json:"groupMembers" valid:"Required"`
GroupMembers []int `cname:"帮组成员列表" json:"groupMembers"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
}
... ...
... ... @@ -16,9 +16,9 @@ type ProductGroupDto struct {
// 班组名称
GroupName string `json:"groupName,omitempty"`
// 班组长
GroupLeader string `json:"groupLeader,omitempty"`
GroupLeader string `json:"groupLeader"`
// 帮组成员列表
GroupMembers string `json:"groupMembers,omitempty"`
GroupMembers string `json:"groupMembers"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `json:"workOn,omitempty"`
// 工作位置
... ... @@ -32,7 +32,9 @@ type ProductGroupDto struct {
func (d *ProductGroupDto) LoadDto(m *domain.ProductGroup, orgId int) *ProductGroupDto {
d.ProductGroupId = m.ProductGroupId
d.GroupName = m.GroupName
d.GroupLeader = m.GroupLeader.UserName
if m.GroupLeader != nil {
d.GroupLeader = m.GroupLeader.UserName
}
var members []string
for i := range m.GroupMembers {
members = append(members, m.GroupMembers[i].UserName)
... ...
... ... @@ -2,6 +2,7 @@ package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils/converter"
"strings"
)
... ... @@ -11,12 +12,15 @@ type ProductGroupEmployeesDto struct {
UserId int `json:"userId,omitempty"`
// 用户姓名
UserName string `json:"userName,omitempty"`
// 生产小组ID
ProductGroupId int `json:"productGroupId,omitempty"`
// 班组名称
GroupName string `json:"groupName,omitempty"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOnDescription string `json:"workOn,omitempty"`
// 工作位置键值 (车间ID+'.'+生产线ID+'.'+工段ID)
//WorkStationId string `json:"workStationId,omitempty"`
UserNamePinyin string `json:"pinyin"`
}
func NewProductGroupEmployeesDto(group *domain.ProductGroup) []*ProductGroupEmployeesDto {
... ... @@ -34,10 +38,14 @@ func NewGroupEmployee(group *domain.ProductGroup, u *domain.User) *ProductGroupE
item := &ProductGroupEmployeesDto{}
item.UserId = u.UserId
item.UserName = u.UserName
item.ProductGroupId = group.ProductGroupId
item.GroupName = group.GroupName
workOns := domain.WorkOnDescription(group.WorkOn)
item.WorkOnDescription = strings.Join(workOns, ",")
//item.WorkStationId = group.WorkStation.WorkStationId
if len(item.UserName) > 0 {
item.UserNamePinyin = converter.ToPinYin(item.UserName, "")
}
return item
}
... ... @@ -63,9 +71,37 @@ func (d *ProductGroupEmployeesDtos) LoadDto(groups ...*domain.ProductGroup) {
}
}
func (d *ProductGroupEmployeesDtos) LoadDtoV2(list ...*domain.ProductAttendanceRecord) {
var mapUser = make(map[int]int)
for _, v := range list {
item := &ProductGroupEmployeesDto{}
item.UserId = v.ProductWorker.UserId
item.UserName = v.ProductWorker.UserName
item.ProductGroupId = 0
item.GroupName = ""
if len(item.UserName) > 0 {
item.UserNamePinyin = converter.ToPinYin(item.UserName, "")
}
if _, ok := mapUser[item.UserId]; ok {
continue
} else {
mapUser[item.UserId] = item.UserId
}
d.Append(item)
}
}
func NewProductGroupEmployeesDtos() *ProductGroupEmployeesDtos {
return &ProductGroupEmployeesDtos{
Result: make([]*ProductGroupEmployeesDto, 0),
MapResult: make(map[int]*ProductGroupEmployeesDto),
}
}
func (ms *ProductGroupEmployeesDtos) Len() int { return len(ms.Result) }
func (ms *ProductGroupEmployeesDtos) Less(i, j int) bool {
return ms.Result[i].UserNamePinyin < ms.Result[j].UserNamePinyin
}
func (ms *ProductGroupEmployeesDtos) Swap(i, j int) {
ms.Result[i], ms.Result[j] = ms.Result[j], ms.Result[i]
}
... ...
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
}
... ...
... ... @@ -11,6 +11,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"sort"
"time"
)
... ... @@ -44,15 +45,19 @@ func (productGroupService *ProductGroupService) CreateProductGroup(operateInfo *
}
var leader *domain.User
var members []*domain.User
var members = make([]*domain.User, 0)
userService := domainService.NewUserService()
leader, err = userService.User(cmd.GroupLeaderId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if cmd.GroupLeaderId > 0 {
leader, err = userService.User(cmd.GroupLeaderId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
members, err = userService.Users(cmd.GroupMembers)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if len(cmd.GroupMembers) > 0 {
members, err = userService.Users(cmd.GroupMembers)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
var org *domain.Org
... ... @@ -129,6 +134,9 @@ func (productGroupService *ProductGroupService) GetProductGroup(getProductGroupQ
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
//if productGroup.GroupLeader==nil{
// productGroup.GroupLeader = &domain.User{}
//}
return productGroup, nil
}
... ... @@ -291,15 +299,19 @@ func (productGroupService *ProductGroupService) UpdateProductGroup(cmd *command.
}
var leader *domain.User
var members []*domain.User
var members = make([]*domain.User, 0)
userService := domainService.NewUserService()
leader, err = userService.User(cmd.GroupLeaderId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if cmd.GroupLeaderId > 0 {
leader, err = userService.User(cmd.GroupLeaderId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
members, err = userService.Users(cmd.GroupMembers)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if len(cmd.GroupMembers) > 0 {
members, err = userService.Users(cmd.GroupMembers)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
productGroup.GroupLeader = leader
productGroup.GroupMembers = members
... ... @@ -358,7 +370,7 @@ func (productGroupService *ProductGroupService) SearchProductGroup(operateInfo *
item := productGroups[i]
newItem := &dto.ProductGroupDto{}
newItem.LoadDto(productGroups[i], operateInfo.OrgId)
item.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId)
newItem.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId)
results = append(results, newItem)
}
if err := transactionContext.CommitTransaction(); err != nil {
... ... @@ -383,9 +395,7 @@ func (productGroupService *ProductGroupService) SearchProductGroupEmployees(oper
transactionContext.RollbackTransaction()
}()
//workshops, _ := factory.FastPgWorkshops(transactionContext, operateInfo.CompanyId)
queryOptions := utils.ObjectToMap(cmd)
//queryOptions = workshops.FindByNameWithQuery(queryOptions, cmd.WorkshopName, cmd.LineName, "")
var productGroupRepository domain.ProductGroupRepository
productGroupRepository, _, _ = factory.FastPgProductGroup(transactionContext, 0)
... ... @@ -401,6 +411,7 @@ func (productGroupService *ProductGroupService) SearchProductGroupEmployees(oper
items := dto.NewProductGroupEmployeesDto(item)
results.Append(items...)
}
sort.Stable(results)
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -409,6 +420,72 @@ func (productGroupService *ProductGroupService) SearchProductGroupEmployees(oper
}, nil
}
// 返回在当前工段上打卡的所有用户
func (productGroupService *ProductGroupService) SearchProductGroupEmployeesV2(operateInfo *domain.OperateInfo, cmd *query.SearchProductGroupEmployeesQuery) (int64, interface{}, error) {
if err := cmd.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
queryOptions := utils.ObjectToMap(cmd)
queryOptions["signBeginTime"] = utils.GetZeroTime(time.Now())
var attendanceRecordRepository domain.ProductAttendanceRecordRepository
attendanceRecordRepository, _, _ = factory.FastPgAttendance(transactionContext, 0)
_, productGroups, err := attendanceRecordRepository.Find(queryOptions)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var results = dto.NewProductGroupEmployeesDtos()
results.LoadDtoV2(productGroups...)
sort.Stable(results)
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return int64(len(results.Result)), map[string]interface{}{
"employees": results.Result,
}, 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
... ...
... ... @@ -97,7 +97,7 @@ func (productJobService *ProductJobService) GetProductJob(getProductJobQuery *qu
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
productJob.WorkStation, _ = workshop.FindWorkStation(productJob.WorkStation.WorkshopId, productJob.WorkStation.LineId, productJob.WorkStation.SectionId)
productJob.WorkStation.Principal = workshop.Principal
newJobDto := &dto.ProductJobDto{}
newJobDto.LoadDto(productJob, 0)
... ... @@ -335,9 +335,11 @@ func (productJobService *ProductJobService) SearchProductJob(operateInfo *domain
var result = make([]*dto.ProductJobDto, 0)
for i := range productJobs {
item := productJobs[i]
item.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId)
newJobDto := &dto.ProductJobDto{}
newJobDto.LoadDto(item, operateInfo.OrgId)
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
... ...
... ... @@ -17,7 +17,7 @@ type CreateProductPlanCommand struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 批号
BatchNumber string `cname:"批号" json:"batchNumber" valid:"Required"`
BatchNumber string `cname:"批号" json:"batchNumber"`
// 生产日期
ProductDate string `cname:"生产日期" json:"productDate" valid:"Required"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
... ... @@ -28,17 +28,14 @@ type CreateProductPlanCommand struct {
//PlanProductName string `cname:"计划的产品名称" json:"planProductName"`
// 产品ID
ProductId int `cname:"产品ID" json:"productId" valid:"Required"`
// 投入量规格 默认份
DevotedUnit string `cname:"投入量规格" json:"devotedUnit" `
// 数量(保留两位小数)
Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
// 单位
//Unit string `cname:"单位" json:"unit" `
// 单份重量(原材料)
//nitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
// 重量
Weight float64 `cname:"重量" json:"weight" valid:"Required"`
// 备注
Remark string `cname:"备注" json:"remark"`
// 生产日期
ProductDateTime time.Time `cname:"生产日期" json:"-" `
}
... ... @@ -49,8 +46,8 @@ func (createProductPlanCommand *CreateProductPlanCommand) Valid(validation *vali
validation.Error(err.Error())
return
}
if t, err := time.Parse("2006/01/02", createProductPlanCommand.ProductDate); err != nil {
validation.Error("时间格式有误 2006/01/02")
if t, err := time.Parse("2006-01-02", createProductPlanCommand.ProductDate); err != nil {
validation.Error("时间格式有误" + createProductPlanCommand.ProductDate)
return
} else {
createProductPlanCommand.ProductDateTime = t
... ...
... ... @@ -9,8 +9,26 @@ import (
)
type ReceiveMaterialCommand struct {
// 企业id
CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
// 生产计划ID
ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
ProductPlanId int `cname:"生产计划" json:"productPlanId" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段" json:"sectionId" valid:"Required"`
// 生产小组ID
ProductGroupId int `cname:"生产小组" json:"productGroupId"`
// 员工Id 用户唯一标识
EmployeeId int `cname:"员工" json:"employeeId" valid:"Required"`
// 物料ID
UnitConversionId int `cname:"物料ID" json:"unitConversionId" valid:"Required"`
// 重量
Weigh float64 `cname:"重量" json:"weigh" valid:"Required"`
}
func (receiveMaterialCommand *ReceiveMaterialCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -9,8 +9,26 @@ import (
)
type ReturnMaterialCommand struct {
// 企业id
CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
// 生产计划ID
ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
ProductPlanId int `cname:"生产计划" json:"productPlanId" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段" json:"sectionId" valid:"Required"`
// 生产小组ID
ProductGroupId int `cname:"生产小组" json:"productGroupId"`
// 员工Id 用户唯一标识
EmployeeId int `cname:"员工" json:"employeeId" valid:"Required"`
// 物料ID
UnitConversionId int `cname:"物料ID" json:"unitConversionId" valid:"Required"`
// 重量
Weigh float64 `cname:"重量" json:"weigh" valid:"Required"`
}
func (returnMaterialCommand *ReturnMaterialCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -10,7 +10,7 @@ import (
type SetOfflineCommand struct {
// 生产计划ID
ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
ProductPlanId int `cname:"生产计划ID" json:"productPlanDispatchRecordId" valid:"Required"`
}
func (setOfflineCommand *SetOfflineCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -12,9 +12,9 @@ type SetOnlineCommand struct {
// 生产计划ID
ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
WorkshopId int `cname:"车间ID" json:"workshopId" `
// 生产线ID
//LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
}
... ...
... ... @@ -9,8 +9,26 @@ import (
)
type SubmitProductRecordCommand struct {
// 企业id
CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
// 生产计划ID
ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
ProductPlanId int `cname:"生产计划" json:"productPlanId" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段" json:"sectionId" valid:"Required"`
// 生产小组ID
ProductGroupId int `cname:"生产小组" json:"productGroupId"`
// 员工Id 用户唯一标识
EmployeeId int `cname:"员工" json:"employeeId" valid:"Required"`
// 物料ID
UnitConversionId int `cname:"物料ID" json:"unitConversionId"`
// 重量
Weigh float64 `cname:"重量" json:"weigh" valid:"Required"`
}
func (submitProductRecordCommand *SubmitProductRecordCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -9,10 +9,10 @@ import (
)
type SwitchCommand struct {
// 下线计划ID
FromProductPlanId int `cname:"下线计划ID" json:"fromProductPlanId,omitempty"`
// 上线计划ID
ToProductPlanId int `cname:"上线计划ID" json:"toProductPlanId,omitempty"`
// 已上线计划ID
FromProductPlanDispatchRecordId int `cname:"已上线计划ID" json:"productPlanDispatchRecordId,omitempty" valid:"Required"`
// 计划ID
ToProductPlanId int `cname:"计划ID" json:"productPlanId,omitempty" valid:"Required"`
}
func (switchCommand *SwitchCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -19,7 +19,7 @@ type UpdateProductPlanCommand struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 批号
BatchNumber string `cname:"批号" json:"batchNumber" valid:"Required"`
BatchNumber string `cname:"批号" json:"batchNumber"`
// 生产日期
ProductDate string `cname:"生产日期" json:"productDate" valid:"Required"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
... ... @@ -30,6 +30,8 @@ type UpdateProductPlanCommand struct {
PlanProductName string `cname:"计划的产品名称" json:"planProductName"`
// 产品ID
ProductId int `cname:"产品ID" json:"productId" valid:"Required"`
// 投入量规格 默认份
DevotedUnit string `cname:"投入量规格" json:"devotedUnit" `
// 数量(保留两位小数)
Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
// 单位
... ... @@ -39,7 +41,7 @@ type UpdateProductPlanCommand struct {
// 重量
Weight float64 `cname:"重量" json:"weight"`
// 备注
Remark string `cname:"备注" json:"remark" valid:"Required"`
Remark string `cname:"备注" json:"remark"`
// 生产日期
ProductDateTime time.Time `cname:"生产日期" json:"productDateTime" `
}
... ... @@ -49,8 +51,8 @@ func (updateProductPlanCommand *UpdateProductPlanCommand) Valid(validation *vali
validation.Error(err.Error())
return
}
if t, err := time.Parse("2006/01/02", updateProductPlanCommand.ProductDate); err != nil {
validation.Error("时间格式有误 2006/01/02")
if t, err := time.Parse("2006-01-02", updateProductPlanCommand.ProductDate); err != nil {
validation.Error("时间格式有误")
return
} else {
updateProductPlanCommand.ProductDateTime = t
... ...
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"strings"
)
type ProductPlanDispatchRecordDto struct {
// 生产计划ID
ProductPlanId int `json:"productPlanDispatchRecordId,omitempty"`
// 批号
BatchNumber string `json:"batchNumber,omitempty"`
// 生产日期
ProductDate string `json:"productDate,omitempty"`
// 车间
//*domain.Workshop
*domain.WorkStation
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `json:"workOn,omitempty"`
// 上班班次描述
WorkOnDescription string `json:"workOnDescription"`
// 机台 (A、B、C、D 区分机器大小)
Machine string `json:"machine,omitempty"`
// 计划的产品名称
PlanProductName string `json:"planProductName,omitempty"`
// 计划投入
*domain.UnitQuantity
// 计划状态 (1:上线 2:下线 默认下线)
PlanDispatchStatus int `json:"planDispatchStatus,omitempty"`
// 工作位置
//WorkStation *WorkStation `json:"workStation,omitempty"`
// 总产能
//TotalProduct float64 `json:"totalProduct"`
// 备注
Remark string `json:"remark,omitempty"`
// 组织名称
OrgName string `json:"orgName"`
// 权限标识 (当前登录组织匹配为true,否则false)
AuthFlag bool `json:"authFlag"`
}
func (d *ProductPlanDispatchRecordDto) LoadDto(m *domain.ProductPlanDispatchRecord, orgId int) *ProductPlanDispatchRecordDto {
d.ProductPlanId = m.ProductPlanDispatchRecordId
d.BatchNumber = m.BatchNumber
d.ProductDate = m.ProductDate.Format("2006/01/02")
d.WorkStation = m.WorkStation
d.WorkOn = m.PlanDispatchRecordExt.WorkOn
d.PlanProductName = m.PlanDispatchRecordExt.PlanProductName
//d.UnitQuantity = m.PlanDevoted
d.PlanDispatchStatus = m.PlanDispatchStatus
//d.TotalProduct = 0
d.Machine = m.PlanDispatchRecordExt.Machine
d.Remark = m.PlanDispatchRecordExt.Remark
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
}
workOnDesc := domain.WorkOnDescription(m.PlanDispatchRecordExt.WorkOn)
d.WorkOnDescription = strings.Join(workOnDesc, ",")
return d
}
... ...
... ... @@ -23,9 +23,13 @@ type ProductPlanDto struct {
// 上班班次描述
WorkOnDescription string `json:"workOnDescription"`
// 机台 (A、B、C、D 区分机器大小)
Machine string `json:"machine,omitempty"`
Machine string `json:"machine"`
// 产品ID
ProductId int `json:"productId,omitempty"`
// 计划的产品名称
PlanProductName string `json:"planProductName,omitempty"`
// 投入量规格 默认份
DevotedUnit string `json:"devotedUnit" `
// 计划投入
*domain.UnitQuantity
// 计划状态 (1:上线 2:下线 默认下线)
... ... @@ -45,12 +49,19 @@ type ProductPlanDto struct {
func (d *ProductPlanDto) LoadDto(m *domain.ProductPlan, orgId int) *ProductPlanDto {
d.ProductPlanId = m.ProductPlanId
d.BatchNumber = m.BatchNumber
d.ProductDate = m.ProductDate.Format("2006/01/02")
d.ProductDate = m.ProductDate.Format("2006-01-02")
d.WorkshopId = m.Workshop.WorkshopId
d.WorkshopName = m.Workshop.WorkshopName
d.WorkOn = m.WorkOn
d.Machine = m.Machine
d.PlanProductName = m.PlanProductName
d.UnitQuantity = m.PlanDevoted
d.DevotedUnit = "份"
if m.Ext.ProductPlanExt != nil {
d.DevotedUnit = m.Ext.ProductPlanExt.DevotedUnit
d.ProductId = m.Ext.ProductPlanExt.ProductId
}
d.PlanStatus = m.PlanStatus
d.TotalProduct = 0
d.Remark = m.Remark
... ...
... ... @@ -28,6 +28,8 @@ type SearchProductPlanQuery struct {
BatchNumber string `cname:"批号" json:"batchNumber"`
// 车间名称
WorkshopName string `cname:"车间名称" json:"workshopName"`
// 车间ID
WorkshopId string `cname:"车间ID" json:"workshopId"`
}
func (cmd *SearchProductPlanQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -3,6 +3,7 @@ package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/command"
... ... @@ -10,7 +11,9 @@ import (
"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/domainService"
"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"
"time"
)
... ... @@ -59,6 +62,16 @@ func (productPlanService *ProductPlanService) CreateProductPlan(cmd *command.Cre
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(cmd.BatchNumber) == 0 {
generator := redis.NewPlanBatchCodeCache(cmd.CompanyId)
code, err := redis.GenCode(generator)
if err != nil {
log.Logger.Error(err.Error())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "服务器异常")
}
cmd.BatchNumber = code
}
newProductPlan := &domain.ProductPlan{
CompanyId: cmd.CompanyId,
OrgId: cmd.OrgId,
... ... @@ -84,8 +97,10 @@ func (productPlanService *ProductPlanService) CreateProductPlan(cmd *command.Cre
ProductCode: product.ProductCode,
ProductName: product.ProductName,
//ProductSpec: product.ProductSpec,
DevotedUnit: cmd.DevotedUnit,
}),
}
if cmd.Weight > 0 {
newProductPlan.PlanDevoted.Weight = cmd.Weight
}
... ... @@ -259,7 +274,7 @@ func (productPlanService *ProductPlanService) UpdateProductPlan(cmd *command.Upd
ProductId: product.ProductId,
ProductCode: product.ProductCode,
ProductName: product.ProductName,
//ProductSpec: product.ProductSpec,
DevotedUnit: cmd.DevotedUnit,
})
productPlan.PlanDevoted.UnitWeight = product.ProductSpec.UnitWeight
cmd.PlanProductName = product.ProductName
... ... @@ -339,9 +354,9 @@ func (productPlanService *ProductPlanService) SetOffline(setOfflineCommand *comm
transactionContext.RollbackTransaction()
}()
var productPlanRepository domain.ProductPlanRepository
var productPlan *domain.ProductPlan
productPlanRepository, productPlan, _ = factory.FastPgProductPlan(transactionContext, setOfflineCommand.ProductPlanId)
var productPlanRepository domain.ProductPlanDispatchRecordRepository
var productPlan *domain.ProductPlanDispatchRecord
productPlanRepository, productPlan, _ = factory.FastPgProductPlanDispatchRecord(transactionContext, setOfflineCommand.ProductPlanId)
if err = productPlan.ChangeStatus(domain.PlanOffline); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -372,45 +387,33 @@ func (productPlanService *ProductPlanService) SetOnline(cmd *command.SetOnlineCo
defer func() {
transactionContext.RollbackTransaction()
}()
var productPlanRepository domain.ProductPlanRepository
var productPlan *domain.ProductPlan
productPlanRepository, productPlan, err = factory.FastPgProductPlan(transactionContext, cmd.ProductPlanId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err = productPlan.ChangeStatus(domain.PlanOnline); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var workshop *domain.Workshop
_, workshop, err = factory.FastPgWorkshop(transactionContext, cmd.WorkshopId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var productPlan *domain.ProductPlan
line, section, err := workshop.FindSectionById(cmd.SectionId)
_, productPlan, err = factory.FastPgProductPlan(transactionContext, cmd.ProductPlanId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
cmd.WorkshopId = productPlan.Workshop.WorkshopId
var workStation *domain.WorkStation
workStation, err = workshop.FindWorkStation(workshop.WorkshopId, line.LineId, section.SectionId)
_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
productPlan.WorkStation = workStation
var productPlanDispatch *domain.ProductPlanDispatchRecord
productPlanDispatch = domain.NewProductPlanDispatchRecord(productPlan, workStation)
if productPlan, err = productPlanRepository.Save(productPlan); err != nil {
var productPlanDispatchRepository, _, _ = factory.FastPgProductPlanDispatchRecord(transactionContext, 0)
if productPlanDispatch, err = productPlanDispatchRepository.Save(productPlanDispatch); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productPlan, nil
return productPlanDispatch, nil
}
// 换单
... ... @@ -428,9 +431,10 @@ func (productPlanService *ProductPlanService) Exchange(switchCommand *command.Sw
defer func() {
transactionContext.RollbackTransaction()
}()
var fromPlan, toPlan *domain.ProductPlan
var productPlanRepository domain.ProductPlanRepository
productPlanRepository, fromPlan, err = factory.FastPgProductPlan(transactionContext, switchCommand.FromProductPlanId)
var fromPlan *domain.ProductPlanDispatchRecord
var toPlan *domain.ProductPlan
var productPlanDispatchRecordRepository domain.ProductPlanDispatchRecordRepository
productPlanDispatchRecordRepository, fromPlan, err = factory.FastPgProductPlanDispatchRecord(transactionContext, switchCommand.FromProductPlanDispatchRecordId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -443,22 +447,18 @@ func (productPlanService *ProductPlanService) Exchange(switchCommand *command.Sw
if err = fromPlan.ChangeStatus(domain.PlanOffline); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if _, err = productPlanRepository.Save(fromPlan); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var workStation *domain.WorkStation
fromWorkStation := fromPlan.WorkStation
_, workStation, err = factory.FastPgWorkstation(transactionContext, fromWorkStation.WorkshopId, fromWorkStation.LineId, fromWorkStation.SectionId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// 新的上线、如果存在一条同一个批次、工段的调度记录 则不做更新
if fromPlan.PlanDispatchRecordExt.ProductPlanId == toPlan.ProductPlanId && fromPlan.ProductDate == toPlan.ProductDate {
log.Logger.Info("换单的批次与当前批次一致,跳过")
return struct{}{}, nil
}
// 计划上线
toPlan.WorkStation = workStation
if err = toPlan.ChangeStatus(domain.PlanOnline); err != nil {
if _, err = productPlanDispatchRecordRepository.Save(fromPlan); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if _, err = productPlanRepository.Save(toPlan); err != nil {
toProductPlanDispatchRecord := domain.NewProductPlanDispatchRecord(toPlan, fromPlan.WorkStation)
if _, err = productPlanDispatchRecordRepository.Save(toProductPlanDispatchRecord); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -483,10 +483,17 @@ func (productPlanService *ProductPlanService) ReceiveMaterial(receiveMaterialCom
defer func() {
transactionContext.RollbackTransaction()
}()
productRecordService, _ := domainService.NewPGProductRecordService(transactionContext.(*pg.TransactionContext))
_, err = productRecordService.SubmitProductRecord(domain.RecordTypeReceiveMaterial, tool_funs.SimpleStructToMap(receiveMaterialCommand))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return struct{}{}, nil
}
// 退料
... ... @@ -504,10 +511,18 @@ func (productPlanService *ProductPlanService) ReturnMaterial(returnMaterialComma
defer func() {
transactionContext.RollbackTransaction()
}()
productRecordService, _ := domainService.NewPGProductRecordService(transactionContext.(*pg.TransactionContext))
_, err = productRecordService.SubmitProductRecord(domain.RecordTypeReturnMaterial, tool_funs.SimpleStructToMap(returnMaterialCommand))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return struct{}{}, nil
}
// 提交成品记录 (成品 二级品)
... ... @@ -525,10 +540,59 @@ func (productPlanService *ProductPlanService) SubmitProductRecord(submitProductR
defer func() {
transactionContext.RollbackTransaction()
}()
productRecordService, _ := domainService.NewPGProductRecordService(transactionContext.(*pg.TransactionContext))
_, err = productRecordService.SubmitProductRecord(domain.RecordTypeSecondLevelWeigh, tool_funs.SimpleStructToMap(submitProductRecordCommand))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return struct{}{}, nil
}
// 搜索生产上线计划记录
func (productPlanService *ProductPlanService) SearchProductPlanOnlineDispatchRecord(operateInfo *domain.OperateInfo, cmd *query.SearchProductPlanQuery) (int64, interface{}, error) {
if err := cmd.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var productPlanRepository domain.ProductPlanDispatchRecordRepository
if value, err := factory.CreateProductPlanDispatchRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productPlanRepository = value
}
queryOptions := utils.ObjectToMap(cmd)
queryOptions["planDispatchStatus"] = 1
count, productPlans, err := productPlanRepository.Find(queryOptions)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var result = make([]*dto.ProductPlanDispatchRecordDto, 0)
for i := range productPlans {
item := productPlans[i]
newItem := &dto.ProductPlanDispatchRecordDto{}
newItem.LoadDto(item, operateInfo.OrgId)
result = append(result, newItem)
}
return count, result, nil
}
func NewProductPlanService(options map[string]interface{}) *ProductPlanService {
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ApproveProductRecordCommand struct {
// 生产记录ID
ProductRecordId int `cname:"生产记录ID" json:"productRecordId" valid:"Required"`
// 审核人
ApproveUserId int `cname:"审核人" json:"approveUserId" valid:"Required"`
// 审核后重量
WeighAfter float64 `cname:"审核后重量" json:"weighAfter" valid:"Required"`
// 审核时间
//ApproveAt string `cname:"审核时间" json:"approveAt" valid:"Required"`
}
func (approveProductRecordCommand *ApproveProductRecordCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (approveProductRecordCommand *ApproveProductRecordCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(approveProductRecordCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(approveProductRecordCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CreateProductRecordCommand struct {
// 生产记录ID
ProductRecordId int `cname:"生产记录ID" json:"productRecordId" valid:"Required"`
}
func (createProductRecordCommand *CreateProductRecordCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createProductRecordCommand *CreateProductRecordCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createProductRecordCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createProductRecordCommand).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
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"reflect"
"strings"
)
type ProductRecordStaticsCommand struct {
*domain.ProductRecord
}
// Type is a string value that indicates the type of the task.
//func (t *ProductRecordStaticsCommand) Type() string
// Payload is the data needed for task execution.
//func (t *ProductRecordStaticsCommand) Payload() []byte
func (removeProductRecordCommand *ProductRecordStaticsCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProductRecordCommand *ProductRecordStaticsCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeProductRecordCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeProductRecordCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RemoveProductRecordCommand struct {
// 生产记录ID
ProductRecordId int `cname:"生产记录ID" json:"productRecordId" valid:"Required"`
}
func (removeProductRecordCommand *RemoveProductRecordCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProductRecordCommand *RemoveProductRecordCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeProductRecordCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeProductRecordCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type UpdateProductRecordCommand struct {
// 生产记录ID
ProductRecordId int `cname:"生产记录ID" json:"productRecordId" valid:"Required"`
}
func (updateProductRecordCommand *UpdateProductRecordCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateProductRecordCommand *UpdateProductRecordCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateProductRecordCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateProductRecordCommand).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
}
... ...
package dto
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
type EmployeeProductRecordDto struct {
// 员工产能记录ID
EmployeeProductRecordId int `json:"productRecordId"`
// 生产工人
ProductWorker *domain.User `json:"productWorker,omitempty"`
*domain.WorkStation
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `json:"workOn"`
// 生产日期
//ProductDate string `json:"productDate"`
// 计划的产品名称
PlanProductName string `json:"planProductName,omitempty"`
// 批号
BatchNumber string `json:"batchNumber,omitempty"`
// 参与类型 1:正常 2:支援
ParticipateType int `json:"participateType"`
// 产能
ProductWeigh float64 `json:"productWeigh"`
// 二级品产能
SecondLevelWeigh float64 `json:"secondLevelWeigh"`
// 创建时间
CreatedAt string `json:"createdAt,omitempty"`
// 组织名称
OrgName string `json:"orgName"`
// 权限标识 (当前登录组织匹配为true,否则false)
AuthFlag bool `json:"authFlag"`
// 合格率 百分比
QualificationRate int `json:"qualificationRate"`
// 考勤类型 1.正常 2.支援
ParticipateTypeDescription string `json:"participateTypeDescription"`
// 员工类型描述 1:固定 2:派遣 3.临时
EmployeeTypeDescription string `json:"employeeTypeDescription"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOnDescription string `json:"workOnDescription,omitempty"`
}
func (d *EmployeeProductRecordDto) LoadDto(m *domain.EmployeeProductRecord, orgId int) *EmployeeProductRecordDto {
d.EmployeeProductRecordId = m.EmployeeProductRecordId
d.ProductWorker = m.ProductWorker
d.WorkStation = m.WorkStation
d.WorkOn = m.WorkOn
d.PlanProductName = m.ProductRecordInfo.PlanProductName
d.BatchNumber = m.ProductRecordInfo.BatchNumber
d.ParticipateType = m.ParticipateType
d.ProductWeigh = m.RealProductWeigh()
d.SecondLevelWeigh = m.SecondLevelWeigh
d.QualificationRate = m.QualificationRate()
d.CreatedAt = m.CreatedAt.Format("2006-01-02")
d.ParticipateTypeDescription = domain.ParticipateTypeDescription(m.ParticipateType)
d.EmployeeTypeDescription = domain.EmployeeTypeDescription(m.ProductWorker.EmployeeType)
d.WorkOnDescription = domain.WorkOnDescriptions(m.WorkOn)
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
}
return d
}
... ...
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"time"
)
// 二级品记录
type ProductLevelTwoRecord struct {
// 生产记录ID
ProductRecordId int `json:"productRecordId,omitempty"`
// 生产工人
ProductWorker *domain.User `json:"productWorker,omitempty"`
*domain.WorkStation
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `json:"workOn"`
// 产能 - 审核前
WeighBefore float64 `json:"weighBefore"`
// 产能-审核后
WeighAfter float64 `json:"weighAfter"`
// 审核状态 1:未审核 2:已审核
ApproveStatus int `json:"approveStatus"`
// 审核人
ApproveUser *domain.User `json:"approveUser"`
// 审核时间
ApproveAt string `json:"approveAt"`
// 计划的产品名称
PlanProductName string `json:"planProductName,omitempty"`
// 批号
BatchNumber string `json:"batchNumber,omitempty"`
// 创建日期
CreatedDate string `json:"createdDate,omitempty"`
// 创建时间
CreatedAt string `json:"createdAt,omitempty"`
// 组织名称
OrgName string `json:"orgName"`
// 权限标识 (当前登录组织匹配为true,否则false)
AuthFlag bool `json:"authFlag"`
}
func (d *ProductLevelTwoRecord) LoadDto(m *domain.ProductRecord, orgId int) *ProductLevelTwoRecord {
d.ProductRecordId = m.ProductRecordId
d.ProductWorker = m.ProductWorker
d.WorkStation = m.WorkStation
d.WeighBefore = m.ProductRecordInfo.WeighBefore
d.WeighAfter = m.ProductRecordInfo.WeighAfter
d.ApproveStatus = m.ProductRecordInfo.ApproveStatus
if m.ProductRecordInfo.ApproveAt > 0 {
d.ApproveAt = time.Unix(m.ProductRecordInfo.ApproveAt, 0).Format("2006-01-02 15:04:05")
d.ApproveUser = m.ProductRecordInfo.ApproveUser
}
d.PlanProductName = m.ProductRecordInfo.PlanProductName
d.BatchNumber = m.ProductRecordInfo.BatchNumber
d.CreatedDate = m.CreatedAt.Format("2006-01-02")
d.CreatedAt = m.CreatedAt.Format("2006-01-02 15:04:05")
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
}
return d
}
... ...
package dto
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
type WorkshopProductRecordDto struct {
// 员工产能记录ID
WorkshopProductRecordId int `json:"productRecordId"`
// 生产工人
//ProductWorker *domain.User `json:"productWorker,omitempty"`
*domain.WorkStation
// 生产日期
//ProductDate string `json:"productDate"`
// 计划的产品名称
PlanProductName string `json:"planProductName,omitempty"`
// 批号
BatchNumber string `json:"batchNumber,omitempty"`
// 参与类型 1:正常 2:支援
//ParticipateType int `json:"participateType"`
// 投入量
DevotedProductWeigh float64 `json:"devotedProductWeigh"`
// 产能
ProductWeigh float64 `json:"productWeigh"`
// 二级品产能
SecondLevelWeigh float64 `json:"secondLevelWeigh"`
// 创建时间
CreatedAt string `json:"createdAt,omitempty"`
// 组织名称
OrgName string `json:"orgName"`
// 权限标识 (当前登录组织匹配为true,否则false)
AuthFlag bool `json:"authFlag"`
// 合格率 百分比
QualificationRate int `json:"qualificationRate"`
}
func (d *WorkshopProductRecordDto) LoadDto(m *domain.WorkshopProductRecord, orgId int) *WorkshopProductRecordDto {
d.WorkshopProductRecordId = m.WorkshopProductRecordId
//d.ProductWorker = m.ProductWorker
d.WorkStation = m.WorkStation
d.PlanProductName = m.ProductRecordInfo.PlanProductName
d.BatchNumber = m.ProductRecordInfo.BatchNumber
//d.ParticipateType = m.ParticipateType
d.DevotedProductWeigh = m.DevotedProductWeigh()
d.ProductWeigh = m.RealProductWeigh()
d.SecondLevelWeigh = m.SecondLevelWeigh
d.QualificationRate = m.QualificationRate()
d.CreatedAt = m.ProductDate
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
}
return d
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetProductRecordQuery struct {
// 生产记录ID
ProductRecordId int `cname:"生产记录ID" json:"productRecordId" valid:"Required"`
}
func (getProductRecordQuery *GetProductRecordQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getProductRecordQuery *GetProductRecordQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getProductRecordQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getProductRecordQuery).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ListProductRecordQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listProductRecordQuery *ListProductRecordQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProductRecordQuery *ListProductRecordQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listProductRecordQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listProductRecordQuery).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
}
... ...
package query
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type SearchEmployeeProductRecordQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset"`
// 查询限制
Limit int `cname:"查询限制" json:"limit"`
// 当前公司
CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
// 当前登录的组织
OrgId int `cname:"当前登录的组织" json:"orgId,omitempty"`
// 匹配多个组织
InOrgIds []int `cname:"匹配多个组织" json:"inOrgIds,omitempty"`
// 页码
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 int `cname:"员工类型 1:固定 2:派遣 3.临时" json:"employeeType"`
// 开始时间
BeginTime string `cname:"开始时间" json:"beginTime"`
// 结束时间
EndTime string `cname:"结束时间" json:"endTime"`
// 开始时间
ProductBeginTime time.Time `cname:"开始时间" json:"productBeginTime"`
// 结束时间
ProductEndTime time.Time `cname:"结束时间" json:"productEndTime"`
}
func (cmd *SearchEmployeeProductRecordQuery) Valid(validation *validation.Validation) {
cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize)
var err error
if len(cmd.BeginTime) > 0 {
if cmd.ProductBeginTime, err = time.Parse("2006-01-02 15:04:05", cmd.BeginTime); err != nil {
log.Logger.Error(err.Error())
validation.Error("开始时间有误")
return
}
}
if len(cmd.EndTime) > 0 {
if cmd.ProductEndTime, err = time.Parse("2006-01-02 15:04:05", cmd.EndTime); err != nil {
log.Logger.Error(err.Error())
validation.Error("结束时间有误")
return
}
}
}
func (cmd *SearchEmployeeProductRecordQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(cmd)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(cmd).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
}
... ...
package query
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type SearchProductRecordQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset"`
// 查询限制
Limit int `cname:"查询限制" json:"limit"`
// 当前公司
CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
// 当前登录的组织
OrgId int `cname:"当前登录的组织" json:"orgId,omitempty"`
// 匹配多个组织
InOrgIds []int `cname:"匹配多个组织" json:"inOrgIds,omitempty"`
// 页码
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"`
// 生产记录类型:1:领料 2:退料 4:称重 8:二级品称重
ProductRecordType int `cname:"生产记录类型:1:领料 2:退料 4:称重 8:二级品称重"`
// 生产线名称
LineName string `cname:"生产线名称" json:"lineName,omitempty"`
// 工段名称
SectionName string `cname:"工段名称" json:"sectionName,omitempty"`
// 员工类型 1:固定 2:派遣 3.临时
EmployeeType int `cname:"员工类型 1:固定 2:派遣 3.临时" json:"employeeType"`
// 开始时间
BeginTime string `cname:"开始时间" json:"beginTime"`
// 结束时间
EndTime string `cname:"结束时间" json:"endTime"`
// 开始时间
ProductBeginTime time.Time `cname:"开始时间" json:"productBeginTime"`
// 结束时间
ProductEndTime time.Time `cname:"结束时间" json:"productEndTime"`
}
func (cmd *SearchProductRecordQuery) Valid(validation *validation.Validation) {
cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize)
var err error
if len(cmd.BeginTime) > 0 {
if cmd.ProductBeginTime, err = time.Parse("2006-01-02 15:04:05", cmd.BeginTime); err != nil {
log.Logger.Error(err.Error())
validation.Error("开始时间有误")
return
}
}
if len(cmd.EndTime) > 0 {
if cmd.ProductEndTime, err = time.Parse("2006-01-02 15:04:05", cmd.EndTime); err != nil {
log.Logger.Error(err.Error())
validation.Error("结束时间有误")
return
}
}
}
func (cmd *SearchProductRecordQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(cmd)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(cmd).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
}
... ...
package query
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type SearchWorkshopProductRecordQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset"`
// 查询限制
Limit int `cname:"查询限制" json:"limit"`
// 当前公司
CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
// 当前登录的组织
OrgId int `cname:"当前登录的组织" json:"orgId,omitempty"`
// 匹配多个组织
InOrgIds []int `cname:"匹配多个组织" json:"inOrgIds,omitempty"`
// 页码
PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
// 页数
PageSize int `cname:"页数" json:"pageSize,omitempty"`
// 品名
PlanProductName string `cname:"品名" json:"planProductName,omitempty"`
// 工段名称
SectionName string `cname:"工段名称" json:"sectionName,omitempty"`
// 开始时间
BeginTime string `cname:"开始时间" json:"beginTime"`
// 结束时间
EndTime string `cname:"结束时间" json:"endTime"`
// 开始时间
ProductBeginTime time.Time `cname:"开始时间" json:"productBeginTime"`
// 结束时间
ProductEndTime time.Time `cname:"结束时间" json:"productEndTime"`
}
func (cmd *SearchWorkshopProductRecordQuery) Valid(validation *validation.Validation) {
cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize)
var err error
if len(cmd.BeginTime) > 0 {
if cmd.ProductBeginTime, err = time.Parse("2006-01-02 15:04:05", cmd.BeginTime); err != nil {
log.Logger.Error(err.Error())
validation.Error("开始时间有误")
return
}
}
if len(cmd.EndTime) > 0 {
if cmd.ProductEndTime, err = time.Parse("2006-01-02 15:04:05", cmd.EndTime); err != nil {
log.Logger.Error(err.Error())
validation.Error("结束时间有误")
return
}
}
}
func (cmd *SearchWorkshopProductRecordQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(cmd)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(cmd).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
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"time"
)
// 生产记录服务
type ProductRecordService struct {
}
// 生产记录审核
func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *command.ApproveProductRecordCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); 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()
}()
svr, err := domainService.NewPGProductRecordService(transactionContext.(*pgTransaction.TransactionContext))
if _, err = svr.Approve(cmd.ProductRecordId, cmd.ApproveUserId, cmd.WeighAfter, time.Now()); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct{}{}, nil
}
// 创建生产记录服务
func (productRecordService *ProductRecordService) CreateProductRecord(createProductRecordCommand *command.CreateProductRecordCommand) (interface{}, error) {
if err := createProductRecordCommand.ValidateCommand(); 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()
}()
newProductRecord := &domain.ProductRecord{
ProductRecordId: createProductRecordCommand.ProductRecordId,
}
var productRecordRepository domain.ProductRecordRepository
if value, err := factory.CreateProductRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productRecordRepository = value
}
if productRecord, err := productRecordRepository.Save(newProductRecord); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productRecord, nil
}
}
// 返回生产记录服务
func (productRecordService *ProductRecordService) GetProductRecord(getProductRecordQuery *query.GetProductRecordQuery) (interface{}, error) {
if err := getProductRecordQuery.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 productRecordRepository domain.ProductRecordRepository
if value, err := factory.CreateProductRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productRecordRepository = value
}
productRecord, err := productRecordRepository.FindOne(map[string]interface{}{"productRecordId": getProductRecordQuery.ProductRecordId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productRecord == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductRecordQuery.ProductRecordId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var result = &dto.ProductLevelTwoRecord{}
return result.LoadDto(productRecord, productRecord.OrgId), nil
}
}
// 返回生产记录服务列表
func (productRecordService *ProductRecordService) ListProductRecord(listProductRecordQuery *query.ListProductRecordQuery) (interface{}, error) {
if err := listProductRecordQuery.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 productRecordRepository domain.ProductRecordRepository
if value, err := factory.CreateProductRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productRecordRepository = value
}
if count, productRecords, err := productRecordRepository.Find(tool_funs.SimpleStructToMap(listProductRecordQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"productRecords": productRecords,
}, nil
}
}
// 移除生产记录服务
func (productRecordService *ProductRecordService) RemoveProductRecord(removeProductRecordCommand *command.RemoveProductRecordCommand) (interface{}, error) {
if err := removeProductRecordCommand.ValidateCommand(); 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 productRecordRepository domain.ProductRecordRepository
if value, err := factory.CreateProductRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productRecordRepository = value
}
productRecord, err := productRecordRepository.FindOne(map[string]interface{}{"productRecordId": removeProductRecordCommand.ProductRecordId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productRecord == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProductRecordCommand.ProductRecordId)))
}
if productRecord, err := productRecordRepository.Remove(productRecord); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productRecord, nil
}
}
// 更新生产记录服务
func (productRecordService *ProductRecordService) UpdateProductRecord(updateProductRecordCommand *command.UpdateProductRecordCommand) (interface{}, error) {
if err := updateProductRecordCommand.ValidateCommand(); 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 productRecordRepository domain.ProductRecordRepository
if value, err := factory.CreateProductRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productRecordRepository = value
}
productRecord, err := productRecordRepository.FindOne(map[string]interface{}{"productRecordId": updateProductRecordCommand.ProductRecordId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productRecord == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductRecordCommand.ProductRecordId)))
}
if err := productRecord.Update(tool_funs.SimpleStructToMap(updateProductRecordCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if productRecord, err := productRecordRepository.Save(productRecord); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productRecord, nil
}
}
// 返回生产记录服务列表
func (productRecordService *ProductRecordService) SearchProductRecord(operateInfo *domain.OperateInfo, listProductRecordQuery *query.SearchProductRecordQuery) (int64, interface{}, error) {
if err := listProductRecordQuery.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var productRecordRepository domain.ProductRecordRepository
productRecordRepository, _, _ = factory.FastPgProductRecord(transactionContext, 0)
count, productRecords, err := productRecordRepository.Find(utils.ObjectToMap(listProductRecordQuery))
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var result = make([]*dto.ProductLevelTwoRecord, 0)
for i := range productRecords {
item := productRecords[i]
newItem := &dto.ProductLevelTwoRecord{}
newItem.LoadDto(item, operateInfo.OrgId)
result = append(result, newItem)
}
return count, result, nil
}
// 生产记录统计
func (productRecordService *ProductRecordService) ProductRecordStatics(cmd *command.ProductRecordStaticsCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); 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 _ domain.ProductRecordRepository
var productRecord *domain.ProductRecord = cmd.ProductRecord
//_,productRecord,err = factory.FastPgProductRecord(transactionContext,cmd.ProductRecordId)
//if err!=nil{
// log.Logger.Error(err.Error())
// return nil, nil
//}
//
if productRecord == nil {
return nil, nil
}
svr, _ := domainService.NewPGProductRecordService(transactionContext.(*pgTransaction.TransactionContext))
if _, err = svr.EmployeeProductStatics(productRecord); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if _, err = svr.WorkshopProductStatics(productRecord); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
func NewProductRecordService(options map[string]interface{}) *ProductRecordService {
newProductRecordService := &ProductRecordService{}
return newProductRecordService
}
... ...
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/application/productRecord/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/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/utils"
)
// 返回员工生产记录服务列表
func (productRecordService *ProductRecordService) SearchEmployeeProductRecord(operateInfo *domain.OperateInfo, listProductRecordQuery *query.SearchEmployeeProductRecordQuery) (int64, interface{}, error) {
if err := listProductRecordQuery.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
//var productRecordRepository domain.ProductRecordRepository
//productRecordRepository,_,_ = factory.FastPgProductRecord(transactionContext,0)
productRecordRepository, _ := dao.NewEmployeeProductRecordDao(transactionContext.(*pgTransaction.TransactionContext))
options := utils.ObjectToMap(listProductRecordQuery)
count, productRecords, err := productRecordRepository.SearchEmployeeProductRecord(options)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var result = make([]*dto.EmployeeProductRecordDto, 0)
for i := range productRecords {
item := productRecords[i]
newItem := &dto.EmployeeProductRecordDto{}
newItem.LoadDto(item, operateInfo.OrgId)
result = append(result, newItem)
}
return count, result, nil
}
... ...
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/application/productRecord/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/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/utils"
)
// 返回员工生产记录服务列表
func (productRecordService *ProductRecordService) SearchWorkshopProductRecord(operateInfo *domain.OperateInfo, listProductRecordQuery *query.SearchWorkshopProductRecordQuery) (int64, interface{}, error) {
if err := listProductRecordQuery.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
//var productRecordRepository domain.ProductRecordRepository
//productRecordRepository,_,_ = factory.FastPgProductRecord(transactionContext,0)
productRecordRepository, _ := dao.NewWorkshopProductRecordDao(transactionContext.(*pgTransaction.TransactionContext))
options := utils.ObjectToMap(listProductRecordQuery)
count, productRecords, err := productRecordRepository.SearchWorkshopProductRecord(options)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var result = make([]*dto.WorkshopProductRecordDto, 0)
for i := range productRecords {
item := productRecords[i]
newItem := &dto.WorkshopProductRecordDto{}
newItem.LoadDto(item, operateInfo.OrgId)
result = append(result, newItem)
}
return count, result, nil
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CommonStatisticsQuery struct {
Action string `cname:"查询类别" json:"actionType" valid:"Required"`
QueryOptions map[string]interface{} `json:"queryOptions"`
}
func (checkUndertakerQuery *CommonStatisticsQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (checkUndertakerQuery *CommonStatisticsQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(checkUndertakerQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(checkUndertakerQuery).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
}
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"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/application/statistics/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
)
// CommonStatisticsService 通用的统计服务
type CommonStatisticsService struct {
}
// CommonStatisticsService 通用的统计服务
func (svr *CommonStatisticsService) CommonStatisticsService(cmd *query.CommonStatisticsQuery) (interface{}, error) {
if err := cmd.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
var 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()
}()
statisticsService, _ := domainService.NewPGCommonStatisticsService(transactionContext.(*pg.TransactionContext))
response, err := statisticsService.CommonStatistics(cmd.Action, cmd.QueryOptions)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return response, nil
}
func NewCommonStatisticsService(options map[string]interface{}) *CommonStatisticsService {
newProductSectionService := &CommonStatisticsService{}
return newProductSectionService
}
... ...
package syncdata
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"strconv"
"strings"
"time"
... ... @@ -181,8 +183,15 @@ func (srv *PullDataK3CloudService) PullMaterial(timeFilter time.Time) error {
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var userService = domainService.NewUserService()
org, err := userService.Organization(constant.MANUFACTURE_DEFAULT_ORGID)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//MaterialK3cloud表数据到Proudct表
err = materialDao.SyncDataProudct(nowTime.Unix())
err = materialDao.SyncDataProudct(nowTime.Unix(), org.OrgName)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type WorkshopDataConsumeCommand struct {
*domain.DeviceCollection
// 企业id
CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
}
func (updateWorkshopCommand *WorkshopDataConsumeCommand) Valid(validation *validation.Validation) {
}
func (updateWorkshopCommand *WorkshopDataConsumeCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateWorkshopCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateWorkshopCommand).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
}
... ...
... ... @@ -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 {
... ... @@ -175,7 +182,7 @@ func (workshopService *WorkshopService) RemoveWorkshop(removeWorkshopCommand *co
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeWorkshopCommand.WorkshopId)))
}
if !workshop.CanRemove() {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当车间下存在线别")
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前车间下存在线别,不可删除")
}
if workshop, err := workshopRepository.Remove(workshop); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"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/application/workshop/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
)
func (workshopService *WorkshopService) WorkshopConsume(cmd *command.WorkshopDataConsumeCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); 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()
}()
consumeService, _ := domainService.NewPGWorkshopDataConsumeService(transactionContext.(*pg.TransactionContext))
if _, err := consumeService.Consume(cmd.CompanyId, cmd.OrgId, cmd.DeviceCollection); err != nil {
log.Logger.Error(err.Error())
return nil, err
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct{}{}, nil
}
... ...
package constant
import (
"os"
"strconv"
)
var (
// 生产制造 - 称重系统 - 默认公司
MANUFACTURE_DEFAULT_COMPANYID = 1
// 生产制造 - 称重系统 - 默认组织
MANUFACTURE_DEFAULT_ORGID = 1
)
func init() {
if os.Getenv("MANUFACTURE_DEFAULT_COMPANYID") != "" {
MANUFACTURE_DEFAULT_COMPANYID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_DEFAULT_COMPANYID"))
}
if os.Getenv("MANUFACTURE_DEFAULT_ORGID") != "" {
MANUFACTURE_DEFAULT_ORGID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_DEFAULT_ORGID"))
}
}
... ...
... ... @@ -2,17 +2,21 @@ package constant
import "os"
var MQTT_TOPIC = "/MQTT"
//设备商提供的测试地址
var MQTT_HOST = "175.24.122.87"
//内网测试地址
//var MQTT_HOST = "192.168.100.222"
var MQTT_PORT = "1883"
var MQTT_USER = "user111"
var MQTT_PASSWORD = "user111"
var MQTT_USER = ""
var MQTT_PASSWORD = ""
//内网测试地址
//var MQTT_HOST = "192.168.100.222"
//var MQTT_PORT = "1883"
//var MQTT_USER = "admin"
//var MQTT_PASSWORD = "123456"
func init(){
func init() {
if os.Getenv("MQTT_HOST") != "" {
MQTT_HOST = os.Getenv("MQTT_HOST")
}
... ... @@ -25,4 +29,4 @@ func init(){
if os.Getenv("MQTT_PASSWORD") != "" {
MQTT_PASSWORD = os.Getenv("MQTT_PASSWORD")
}
}
\ No newline at end of file
}
... ...
... ... @@ -10,6 +10,12 @@ var (
DISABLE_REPOSITORY_CACHE = false
// 缓存过期时间 单位秒
REPOSITORY_CACHE_EXPIRE = 30 * 60
REDIS_ADDRESS = ""
// redis 考勤机打卡消息队列
REDIS_ZKTECO_KEY = "allied-creation-zkteco"
// redis 车间数据消息队列
REDIS_WORKSHOP_KEY = "allied-creation-workshop"
)
func init() {
... ... @@ -29,4 +35,5 @@ func init() {
if os.Getenv("DISABLE_REPOSITORY_CACHE") != "" {
DISABLE_REPOSITORY_CACHE = true
}
REDIS_ADDRESS = REDIS_HOST + ":" + REDIS_PORT
}
... ...
... ... @@ -103,9 +103,9 @@ func (device *Device) Update(data map[string]interface{}) error {
}
if device.Ext == nil {
device.Ext = &Ext{}
if device.Ext.DeviceExt == nil {
device.Ext.DeviceExt = &DeviceExt{}
}
}
if device.Ext != nil && device.Ext.DeviceExt == nil {
device.Ext.DeviceExt = &DeviceExt{}
}
if orgName, ok := data["orgName"]; ok {
device.Ext.OrgName = orgName.(string)
... ... @@ -127,6 +127,16 @@ func (device *Device) Valid() error {
return nil
}
// 标记为生产设备
func (device *Device) MarkAsProductDevice() bool {
if device.Ext.DeviceExt.IsProductDevice == 1 {
return false
}
device.Ext.DeviceExt.IsProductDevice = 1
device.UpdatedAt = time.Now()
return true
}
// 导入设备数据体
type ImportDeviceItem struct {
// 设备编号
... ... @@ -183,3 +193,13 @@ func (item *ImportDeviceItem) Valid() error {
}
return nil
}
type Devices []*Device
func (devices Devices) ToMap() map[string]*Device {
var resp = make(map[string]*Device)
for _, v := range devices {
resp[v.DeviceCode] = v
}
return resp
}
... ...
package domain
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"time"
)
// 设备采集数据
type DeviceCollection struct {
// 数据采集ID
DeviceCollectionId int64 `json:"deviceCollectionId,string"`
// 车间名
WorkShopName string `json:"workShopName"`
// 采集时间
CollectionTime time.Time `json:"collectionTime"`
// 设备名
DeviceSn string `json:"deviceSn"`
// 设备类型
DeviceType string `json:"deviceType"`
// 启动状态 1-启动 0-停止
StartupStatus int64 `json:"startupStatus"`
// 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障
ComStatus int64 `json:"comStatus"`
// 设备数据值
Values interface{} `json:"values"`
}
var (
// 包馅机
DeviceTypeBaoXianJi = "BXJ"
// 打浆机
DeviceTypeDaJiangJi = "DJJ"
// 面包屑机
DeviceTypeMianBaoXieJi = "MBXJ"
// 油炸机
DeviceTypeYouZhaJi = "YZJ"
// 串串机
DeviceTypeChuanChuanJi = "CCJ"
// 速冻线
DeviceTypeSuDongXian = "SDX"
// 封口机
DeviceTypeFengKouJi = "FKJ"
// 封箱机
DeviceTypeFengXiangJi = "FXJ"
)
type DeviceCollectionRepository interface {
Save(deviceCollection *DeviceCollection) (*DeviceCollection, error)
Remove(deviceCollection *DeviceCollection) (*DeviceCollection, error)
FindOne(queryOptions map[string]interface{}) (*DeviceCollection, error)
Find(queryOptions map[string]interface{}) (int64, []*DeviceCollection, error)
}
func (deviceCollection *DeviceCollection) Identify() interface{} {
if deviceCollection.DeviceCollectionId == 0 {
return nil
}
return deviceCollection.DeviceCollectionId
}
func (deviceCollection *DeviceCollection) Update(data map[string]interface{}) error {
if workShopName, ok := data["workShopName"]; ok {
deviceCollection.WorkShopName = workShopName.(string)
}
if deviceSn, ok := data["deviceSn"]; ok {
deviceCollection.DeviceSn = deviceSn.(string)
}
if deviceType, ok := data["deviceType"]; ok {
deviceCollection.DeviceSn = deviceType.(string)
}
if startupStatus, ok := data["startupStatus"]; ok {
deviceCollection.StartupStatus = startupStatus.(int64)
}
if comStatus, ok := data["comStatus"]; ok {
deviceCollection.ComStatus = comStatus.(int64)
}
if values, ok := data["values"]; ok {
deviceCollection.Values = values
}
return nil
}
func TaskDeviceCollection() string {
return fmt.Sprintf("%v:task:device-collection:report", constant.CACHE_PREFIX)
}
... ...