作者 Administrator

合并分支 'test' 到 'master'

Test



查看合并请求 !4
正在显示 61 个修改的文件 包含 4419 行增加56 行删除

要显示太多修改。

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

FROM 192.168.0.243:5000/mmm/allied-creation-manufacture:20210809
FROM 192.168.0.243:5000/mmm/allied-creation-user:20210809
ENV APP_DIR $GOPATH/src/project-20211220
RUN mkdir -p $APP_DIR
WORKDIR $APP_DIR/
... ...
FROM golang:alpine
ENV APP_DIR $GOPATH/src/project-20211220
ENV POSTGRESQL_DB_NAME="" \
POSTGRESQL_USER="" \
POSTGRESQL_PASSWORD="" \
POSTGRESQL_HOST="" \
POSTGRESQL_PORT="" \
REDIS_HOST="" \
REDIS_PORT="" \
REDIS_AUTH="" \
LOG_LEVEL="debug" \
ERROR_BASE_CODE="1" \
ERROR_BASE_CODE_MULTIPLE="2000" \
ENABLE_KAFKA_LOG="false" \
HTTP_PORT="8082" \
SERVICE_ENV="prd" \
ALLIED_CREATION_USER_HOST="https://allied-creation-user-prd.fjmaimaimai.com" \
MANUFACTURE_DEFAULT_COMPANYID="1" \
MANUFACTURE_DEFAULT_ORGID="1" \
MANUFACTURE_DEFAULT_WORKSHOPID="2" \
MANUFACTURE_PRODUCT_TYPE="0502010004ST,0502010004ST" \
MQTT_HOST="47.97.5.102" \
MQTT_PORT="6000"
RUN mkdir -p $APP_DIR
WORKDIR $APP_DIR/
COPY ./pkg pkg
COPY ./config config
COPY ./go.mod go.mod
COPY ./go.sum go.sum
COPY ./main.go main.go
RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"]
ENV GO111MODULE on
ENV GOPROXY https://goproxy.cn
RUN ["go","mod","tidy"]
RUN ["go","build"]
RUN ["ls"]
ENTRYPOINT ["./allied-creation-manufacture"]
\ No newline at end of file
... ...
#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
}
```
... ...
... ... @@ -52,12 +52,54 @@ spec:
- mountPath: /opt/logs
name: accesslogs
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: "1000"
volumes:
value: "2000"
- name: ENABLE_KAFKA_LOG
value: "true"
- name: HTTP_PORT
value: "8082"
- name: SERVICE_ENV
value: "dev"
- name: accesslogs
emptyDir: {}
\ No newline at end of file
... ...
apiVersion: v1
kind: Service
metadata:
name: allied-creation-manufacture
namespace: mmm-suplus-prd
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-prd
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:master
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: "prd"
- name: ALLIED_CREATION_GATEWAY_HOST
value: "https://allied-creation-gateway-prd.fjmaimaimai.com"
- name: ALLIED_CREATION_USER_HOST
value: "https://allied-creation-user-prd.fjmaimaimai.com"
- name: ALLIED_CREATION_BASIC_HOST
value: "https://allied-creation-basic-prd.fjmaimaimai.com"
- name: ALLIED_CREATION_MANUFACTURE_HOST
value: "http://allied-creation-manufacture-prd.fjmaimaimai.com"
- name: SMS_SERVE_HOST
value: "https://sms.fjmaimaimai.com:9897"
- name: MANUFACTURE_DEFAULT_COMPANYID
value: "4"
- name: MANUFACTURE_DEFAULT_ORGID
value: "44"
- name: MANUFACTURE_DEFAULT_WORKSHOPID
value: "1"
- name: MANUFACTURE_PRODUCT_TYPE
value: "0502010001ST,0502010007ST,0502010008ST,0502010009ST,0502010010ST,0502010011ST,0502010014ST,0502010016ST,0502010018ST,0502010020ST,0502010021ST,0502010022ST,0502010023ST"
- name: MQTT_HOST
value: "47.97.5.102"
- name: MQTT_PORT
value: "6000"
\ No newline at end of file
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-prd get pods | grep -q allied-creation-manufacture
if [ "$?" == "1" ];then
kubectl create -f /tmp/prd/allied-creation-manufacture/allied-creation-manufacture.yaml --record
kubectl -n mmm-suplus-prd 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-prd 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/prd/allied-creation-manufacture/allied-creation-manufacture.yaml
kubectl -n mmm-suplus-prd get svc | grep -q allied-creation-manufacture
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-prd get svc | grep -q allied-creation-manufacture
done
kubectl -n mmm-suplus-prd get pods | grep -q allied-creation-manufacture
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-prd get pods | grep -q allied-creation-manufacture
done
kubectl create -f /tmp/prd/allied-creation-manufacture/allied-creation-manufacture.yaml --record
kubectl -n mmm-suplus-prd 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-prd 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
... ...
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: "test"
- 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"
- name: MANUFACTURE_DEFAULT_WORKSHOPID
value: "28"
- name: MANUFACTURE_PRODUCT_TYPE
value: "SG,SG"
- name: MQTT_HOST
value: "47.97.5.102"
- name: MQTT_PORT
value: "6000"
\ 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
... ...
... ... @@ -5,24 +5,36 @@ go 1.16
require (
github.com/ajg/form v1.5.1 // indirect
github.com/beego/beego/v2 v2.0.1
github.com/bwmarrin/snowflake v0.3.0
github.com/eclipse/paho.mqtt.golang v1.3.5
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/gavv/httpexpect v2.0.0+incompatible
github.com/go-pg/pg/v10 v10.9.0
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/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/moul/http2curl v1.0.0 // indirect
github.com/mozillazg/go-pinyin v0.19.0
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/sirupsen/logrus v1.8.0
github.com/smartystreets/goconvey v1.7.2 // indirect
github.com/stretchr/testify v1.7.0
github.com/tidwall/gjson v1.13.0
github.com/valyala/fasthttp v1.32.0 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect
github.com/yudai/gojsondiff v1.0.0 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/yudai/pp v2.0.1+incompatible // indirect
golang.org/x/text v0.3.6
)
replace github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v0.0.0-20210608073225-c852ce95ae34
replace github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v0.0.0-20220120032512-24dfab2b4987
... ...
... ... @@ -32,6 +32,8 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4=
github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
github.com/casbin/casbin v1.7.0/go.mod h1:c67qKN6Oum3UF5Q1+BByfFxkwKvhwW57ITjqwtzR1KE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
... ... @@ -61,6 +63,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=
... ... @@ -68,6 +72,8 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 h1:YEetp8
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/eclipse/paho.mqtt.golang v1.3.5 h1:sWtmgNxYM9P2sP+xEItMozsR3w0cqZFlqnNN1bdl41Y=
github.com/eclipse/paho.mqtt.golang v1.3.5/go.mod h1:eTzb4gxwwyWpqBUHGQZ4ABAV7+Jgm1PklsYT/eo8Hcc=
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/elastic/go-elasticsearch/v6 v6.8.5/go.mod h1:UwaDJsD3rWLM5rKNFzv9hgox93HoX8utj1kxD9aFUcI=
github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
... ... @@ -110,6 +116,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=
... ... @@ -152,16 +160,19 @@ 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=
github.com/google/gops v0.3.7/go.mod h1:bj0cwMmX1X4XIJFTjR99R5sCxNssNJ8HebFNvoQlmgY=
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 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
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=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
... ... @@ -177,6 +188,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=
... ... @@ -246,6 +259,8 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/moul/http2curl v1.0.0 h1:dRMWoAtb+ePxMlLkrCbAqh4TlPHXvoGUSQ323/9Zahs=
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
github.com/mozillazg/go-pinyin v0.19.0 h1:p+J8/kjJ558KPvVGYLvqBhxf8jbZA2exSLCs2uUVN8c=
github.com/mozillazg/go-pinyin v0.19.0/go.mod h1:iR4EnMMRXkfpFVV5FMi4FNB6wGq9NV6uDWbUuPhP4Yc=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
... ... @@ -261,6 +276,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=
... ... @@ -268,6 +284,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=
... ... @@ -305,6 +322,12 @@ github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFB
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a h1:9ZKAASQSHhDYGoxY8uLVpewe1GDZ2vu2Tr/vTdVAkFQ=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/richardlehane/mscfb v1.0.3 h1:rD8TBkYWkObWO0oLDFCbwMeZ4KoalxQy+QgniCj3nKI=
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=
... ... @@ -316,6 +339,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=
... ... @@ -331,6 +356,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=
... ... @@ -347,8 +374,14 @@ github.com/syndtr/goleveldb v0.0.0-20160425020131-cfa635847112/go.mod h1:Z4AUp2K
github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
github.com/tal-tech/go-zero v1.0.27 h1:QMIbaTxibMc/OsO5RTAuKZ8ndbl2dGN6pITQEtp2x/A=
github.com/tal-tech/go-zero v1.0.27/go.mod h1:JtNXlsh/CgeIHyQnt5C5M2IcSevW7V0NAnqO93TQgm8=
github.com/tiptok/egglib-go v0.0.0-20210608073225-c852ce95ae34 h1:9iDNyYbfpv5KLWDLpDywD/aIODg+PNnwn+v9on7KGlE=
github.com/tiptok/egglib-go v0.0.0-20210608073225-c852ce95ae34/go.mod h1:KT8WFA2LPo5zVKbomCR6HocO4prnIY9DUVGekA3Ifo4=
github.com/tidwall/gjson v1.13.0 h1:3TFY9yxOQShrvmjdM76K+jc66zJeT6D3/VFFYCGQf7M=
github.com/tidwall/gjson v1.13.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tiptok/egglib-go v0.0.0-20220120032512-24dfab2b4987 h1:0e2hOSL+//5AL7e1r3xCGEugsOPsw2POAm82VZvWLe4=
github.com/tiptok/egglib-go v0.0.0-20220120032512-24dfab2b4987/go.mod h1:xl9i83IKNUkwlobRF6XLKn1RRbZsT+7yhCicpTGWTKc=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYmW5DyG0UqvY96Bu5QYsTLvCHdrgo=
... ... @@ -381,6 +414,10 @@ github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg=
github.com/xuri/efp v0.0.0-20210322160811-ab561f5b45e3 h1:EpI0bqf/eX9SdZDwlMmahKM+CDBgNbsXMhsN28XrM8o=
github.com/xuri/efp v0.0.0-20210322160811-ab561f5b45e3/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
github.com/xuri/excelize/v2 v2.4.1 h1:veeeFLAJwsNEBPBlDepzPIYS1eLyBVcXNZUW79exZ1E=
github.com/xuri/excelize/v2 v2.4.1/go.mod h1:rSu0C3papjzxQA3sdK8cU544TebhrPUoTOaGPIh0Q1A=
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2/go.mod h1:hzfGeIUDq/j97IG+FhNqkowIyEcD88LrW6fyU3K3WqY=
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 h1:6fRhSjgLCkTD3JnJxvaJ4Sj+TYblw757bqYgZaOq5ZY=
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmvncFJFHJ7Gvn9wZArjbV5/FppcK2fKk/tI=
... ... @@ -413,6 +450,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=
... ... @@ -427,9 +466,12 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210218145215-b8e89b74b9df/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb h1:fqpd0EBDzlHRCjiphRR5Zo/RSWWQlWv34418dnEixWk=
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
... ... @@ -456,6 +498,7 @@ golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
... ... @@ -463,8 +506,9 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210510120150-4163338589ed h1:p9UgmWI9wKpfYmgaV/IZKGdXc5qEK45tDwwwDyjS26I=
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985 h1:4CSI6oo7cOjJKajidEljs9h+uP0rRZBPPPhcCbj5mw8=
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
... ... @@ -504,8 +548,9 @@ golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210218155724-8ebf48af031b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015 h1:hZR0X1kPW+nwyJ9xRxqZk1vx5RUObAPBdKVvXPDUH/E=
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
... ... @@ -515,6 +560,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=
... ...
... ... @@ -5,8 +5,13 @@ import (
"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/port/task"
"time"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/crontab"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
... ... @@ -15,9 +20,11 @@ import (
)
func main() {
log.Logger.Info("server start ....")
log.Logger.Info(fmt.Sprintf("ENABLE_KAFKA_LOG:%v", constant.ENABLE_KAFKA_LOG))
defer func() {
if r := recover(); r != nil {
log.Logger.Error(fmt.Sprintf("%v", r))
}
}()
if constant.ENABLE_KAFKA_LOG {
w, _ := logrus.NewKafkaWriter(constant.KAFKA_HOST, constant.TOPIC_LOG_STASH, false)
log.Logger.AddHook(w)
... ... @@ -28,7 +35,17 @@ func main() {
MaxSize: 1024 * 1024 * 2,
})
log.Logger.AddHook(bw)
redis.InitRedis()
log.Logger.Info("server start ....")
log.Logger.Debug(fmt.Sprintf("ENABLE_KAFKA_LOG:%v", constant.ENABLE_KAFKA_LOG))
go mqtt.Start(log.Logger)
go task.Run()
cron := crontab.NewCrontabService(nil)
cron.StartCrontabTask()
defer cron.StopCrontabTask()
time.Sleep(time.Second)
log.Logger.Info("server start!")
web.Run()
log.Logger.Info("server stop!")
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ApproveAttendanceCommand struct {
// 考勤记录ID
ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"`
// 工时
WorkTimeAfter float64 `cname:"工时" json:"workTimeAfter,omitempty"`
// 审核人Id
ApproveUserId int `json:"approveUserId,omitempty"`
}
func (approveAttendanceCommand *ApproveAttendanceCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (approveAttendanceCommand *ApproveAttendanceCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(approveAttendanceCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(approveAttendanceCommand).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"
"time"
"github.com/beego/beego/v2/core/validation"
)
type CreateAttendanceCommand struct {
// 考勤记录ID
//ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"`
// 考勤类型 1.正常 2.支援
AttendanceType int `json:"attendanceType,omitempty"`
// 生产班组Id
ProductGroupId int `json:"productGroupId,omitempty" valid:"Required"`
// 生产工人
ProductWorkerId int `json:"productWorkerId,omitempty" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 签到
SignIn time.Time `json:"signIn,omitempty"`
// 签退
SignOut time.Time `json:"signOut,omitempty"`
// 考勤状态 1.未审核 2:已审核 3.自动审核
//AttendanceStatus int `json:"attendanceStatus,omitempty"`
}
func (createAttendanceCommand *CreateAttendanceCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createAttendanceCommand *CreateAttendanceCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createAttendanceCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createAttendanceCommand).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 RemoveAttendanceCommand struct {
// 考勤记录ID
ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"`
}
func (removeAttendanceCommand *RemoveAttendanceCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeAttendanceCommand *RemoveAttendanceCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeAttendanceCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeAttendanceCommand).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 UpdateAttendanceCommand struct {
// 考勤记录ID
ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"`
}
func (updateAttendanceCommand *UpdateAttendanceCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateAttendanceCommand *UpdateAttendanceCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateAttendanceCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateAttendanceCommand).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 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
}
... ...
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"time"
)
type AttendanceRecordDto struct {
// 考勤记录ID
ProductAttendanceId int `json:"productAttendanceId"`
// 企业id
//CompanyId int `json:"companyId,omitempty"`
// 组织ID
//OrgId int `json:"orgId,omitempty"`
// 考勤类型 1.正常 2.支援
AttendanceType int `json:"attendanceType,omitempty"`
// 班组名称
GroupName string `json:"groupName"`
// 生产工人
ProductWorker *domain.User `json:"productWorker,omitempty"`
// 审核人
ApproveUser *domain.User `json:"approveUser"`
//*domain.ProductAttendanceRecordExt
ApproveAt string `json:"approveAt"`
// 工作位置
*domain.WorkStation
// 签到
SignIn string `json:"signIn"`
// 签退
SignOut string `json:"signOut"`
// 考勤状态 1.未审核 2:已审核 3.自动审核
AttendanceStatus int `json:"attendanceStatus"`
// 工时(审核前)
WorkTimeBefore float64 `json:"workTimeBefore"`
// 工时(审核后)
WorkTimeAfter float64 `json:"workTimeAfter"`
// 签到日期
SignDate string `json:"signDate"`
// 组织名称
OrgName string `json:"orgName"`
// 权限标识 (当前登录组织匹配为true,否则false)
AuthFlag bool `json:"authFlag"`
}
func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId int) *AttendanceRecordDto {
d.ProductAttendanceId = m.ProductAttendanceId
d.AttendanceType = m.AttendanceType
d.ProductWorker = m.ProductWorker
d.WorkStation = m.WorkStation
if !m.SignIn.IsZero() {
d.SignIn = m.SignIn.Local().Format("15:04:05")
d.SignDate = m.SignIn.Local().Format("2006-01-02")
}
if !m.SignOut.IsZero() {
d.SignOut = m.SignOut.Local().Format("15:04:05")
}
d.WorkTimeBefore = utils.Round(m.WorkTimeBefore, 1)
d.WorkTimeAfter = m.WorkTimeAfter
d.AttendanceStatus = m.AttendanceStatus
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
//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.Local().Format("2006-01-02 15:04:05")
}
d.GroupName = m.Ext.AttendanceExt.GroupName
}
}
return d
}
... ...
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
)
type EmployeeAttendanceRecordDto struct {
// 考勤记录ID
ProductAttendanceId int `json:"productAttendanceId"`
// 签到日期
SignDate string `json:"signDate"`
// 工作位置
*domain.WorkStation
// 班组名称
GroupName string `json:"groupName"`
// 生产工人
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.Local().Format("2006-01-02")
}
d.WorkTime = utils.Round(m.WorkTimeAfter, 1)
//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
if m.Ext.AttendanceExt != nil {
d.GroupName = m.Ext.AttendanceExt.GroupName
}
}
return d
}
... ...
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
)
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
if m.WorkshopWorkTimeRecordInfo != nil {
d.WorkshopWorkTimeRecordInfo = &domain.WorkshopWorkTimeRecordInfo{}
d.WorkshopWorkTimeRecordInfo.EPTWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EPTWorkTime, 1)
d.WorkshopWorkTimeRecordInfo.EDWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EDWorkTime, 1)
d.WorkshopWorkTimeRecordInfo.EFTWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EFTWorkTime, 1)
}
d.WorkStation = m.WorkStation
d.RecordDate = m.RecordDate.Local().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"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetAttendanceQuery struct {
// 考勤记录ID
ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"`
}
func (getAttendanceQuery *GetAttendanceQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getAttendanceQuery *GetAttendanceQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getAttendanceQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getAttendanceQuery).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 ListAttendanceQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listAttendanceQuery *ListAttendanceQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listAttendanceQuery *ListAttendanceQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listAttendanceQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listAttendanceQuery).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"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type SearchAttendanceQuery 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"`
// 姓名
UserName string `cname:"姓名" json:"userName,omitempty"`
// 考勤状态 1.未审核 2:已审核 3.自动审核
AttendanceStatus int `cname:"考勤状态 1.未审核 2:已审核 3.自动审核" json:"attendanceStatus,omitempty"`
}
func (cmd *SearchAttendanceQuery) Valid(validation *validation.Validation) {
cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize)
}
func (cmd *SearchAttendanceQuery) 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 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"`
// 考勤状态 1.未审核 2:已审核 3.自动审核
InAttendanceStatus []int `cname:"考勤状态 1.未审核 2:已审核 3.自动审核" json:"inAttendanceStatus,omitempty"`
// 开始时间
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.ParseInLocation("2006-01-02 15:04:05", cmd.BeginTime, time.Local); err != nil {
log.Logger.Error(err.Error())
validation.Error("开始时间有误")
return
}
}
if len(cmd.EndTime) > 0 {
if cmd.SignEndTime, err = time.ParseInLocation("2006-01-02 15:04:05", cmd.EndTime, time.Local); err != nil {
log.Logger.Error(err.Error())
validation.Error("结束时间有误")
return
}
if cmd.SignBeginTime.Equal(cmd.SignEndTime) {
cmd.SignEndTime = cmd.SignEndTime.Add(time.Hour * 24)
}
}
//cmd.AttendanceStatus = 6 // 审核 + 自动审核
cmd.InAttendanceStatus = []int{2, 3}
}
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
}
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/query"
"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/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"time"
)
type AttendanceService struct {
}
// 审核工时
func (attendanceService *AttendanceService) ApproveAttendance(cmd *command.ApproveAttendanceCommand) (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 productAttendanceRecordRepository domain.ProductAttendanceRecordRepository
var attendance *domain.ProductAttendanceRecord
productAttendanceRecordRepository, attendance, err = factory.FastPgAttendance(transactionContext, cmd.ProductAttendanceId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var user *domain.User
userService := domainService.NewUserService()
user, err = userService.User(cmd.ApproveUserId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
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())
}
return struct{}{}, nil
}
// 创建
func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain.OperateInfo, cmd *command.CreateAttendanceCommand) (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 user *domain.User
userService := domainService.NewUserService()
user, err = userService.User(cmd.ProductWorkerId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
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())
}
var org *domain.Org
org, err = userService.Organization(operateInfo.OrgId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var productGroup *domain.ProductGroup
_, productGroup, err = factory.FastPgProductGroup(transactionContext, cmd.ProductGroupId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
newAttendance := &domain.ProductAttendanceRecord{
//ProductAttendanceId: cmd.ProductAttendanceId,
CompanyId: operateInfo.CompanyId,
OrgId: operateInfo.OrgId,
AttendanceType: cmd.AttendanceType,
ProductWorker: user,
WorkStation: workStation,
SignIn: cmd.SignIn,
SignOut: cmd.SignOut,
AttendanceStatus: domain.AttendanceNotApprove,
WorkTimeBefore: 0,
WorkTimeAfter: 0,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Ext: domain.NewExt(org.OrgName).WithAttendanceExt(&domain.ProductAttendanceRecordExt{
GroupName: productGroup.GroupName,
ProductGroupId: productGroup.ProductGroupId,
}),
}
newAttendance.WorkTimeBefore = newAttendance.ComputeWorkTimeBefore()
var attendanceRepository domain.ProductAttendanceRecordRepository
attendanceRepository, _, _ = factory.FastPgAttendance(transactionContext, 0)
if attendance, err := attendanceRepository.Save(newAttendance); 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 attendance, nil
}
}
// 返回
func (attendanceService *AttendanceService) GetAttendance(getAttendanceQuery *query.GetAttendanceQuery) (interface{}, error) {
if err := getAttendanceQuery.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 attendanceRepository domain.ProductAttendanceRecordRepository
var attendance *domain.ProductAttendanceRecord
_, attendance, err = factory.FastPgAttendance(transactionContext, getAttendanceQuery.ProductAttendanceId)
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())
}
result := &dto.AttendanceRecordDto{}
result.LoadDto(attendance, 0)
return result, nil
}
// 返回列表
func (attendanceService *AttendanceService) ListAttendance(listAttendanceQuery *query.ListAttendanceQuery) (interface{}, error) {
if err := listAttendanceQuery.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 attendanceRepository attendance.AttendanceRepository
//if value, err := factory.CreateAttendanceRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// attendanceRepository = value
//}
//if count, attendances, err := attendanceRepository.Find(tool_funs.SimpleStructToMap(listAttendanceQuery)); 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,
// "attendances": attendances,
// }, nil
//}
return nil, nil
}
// 移除
func (attendanceService *AttendanceService) RemoveAttendance(removeAttendanceCommand *command.RemoveAttendanceCommand) (interface{}, error) {
if err := removeAttendanceCommand.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 attendanceRepository domain.ProductAttendanceRecordRepository
var attendance *domain.ProductAttendanceRecord
attendanceRepository, attendance, err = factory.FastPgAttendance(transactionContext, removeAttendanceCommand.ProductAttendanceId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if attendance, err := attendanceRepository.Remove(attendance); 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 attendance, nil
}
}
// 更新
func (attendanceService *AttendanceService) UpdateAttendance(updateAttendanceCommand *command.UpdateAttendanceCommand) (interface{}, error) {
if err := updateAttendanceCommand.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 attendanceRepository attendance.AttendanceRepository
//if value, err := factory.CreateAttendanceRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// attendanceRepository = value
//}
//attendance, err := attendanceRepository.FindOne(map[string]interface{}{"attendanceId": updateAttendanceCommand.AttendanceId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if attendance == nil {
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateAttendanceCommand.AttendanceId)))
//}
//if err := attendance.Update(tool_funs.SimpleStructToMap(updateAttendanceCommand)); err != nil {
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
//}
//if attendance, err := attendanceRepository.Save(attendance); 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 attendance, nil
//}
return nil, nil
}
// 返回列表
func (attendanceService *AttendanceService) SearchAttendance(operateInfo *domain.OperateInfo, cmd *query.SearchAttendanceQuery) (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.AttendanceRecordDto, 0)
for i := range attendances {
newItem := &dto.AttendanceRecordDto{}
result = append(result, newItem.LoadDto(attendances[i], operateInfo.OrgId))
}
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_ORGID, 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
}
... ...
package crontab
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"github.com/beego/beego/v2/task"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/syncdata"
)
type CrontabService struct {
}
func NewCrontabService(options map[string]interface{}) *CrontabService {
newCrontabService := &CrontabService{}
return newCrontabService
}
func (crontabService *CrontabService) initTask() {
//拉取物料数据 每5分执行
pullMaterialK3cloud := task.NewTask("pullMaterialK3cloud", "0 */5 0 * * *", func(ctx context.Context) error {
srv := syncdata.PullDataK3CloudService{}
return srv.PullMaterialNewest()
})
task.AddTask("pullMaterialK3cloud", pullMaterialK3cloud)
//拉取物料分组数据 每5分执行
pullMaterialGroupK3cloud := task.NewTask("pullMaterialGroupK3cloud", "0 */5 0 * * *", func(ctx context.Context) error {
srv := syncdata.PullDataK3CloudService{}
return srv.PullMaterialGroup()
})
task.AddTask("pullMaterialGroupK3cloud", pullMaterialGroupK3cloud)
//拉取订生产订单数据 每5分执行
PullPrdMoK3cloud := task.NewTask("PullPrdMoK3cloud", "0 */5 0 * * *", func(ctx context.Context) error {
srv := syncdata.PullDataK3CloudService{}
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("定时刷新设备每日运行记录", "0 */1 * * * *", AutoFlushDeviceDailyRunningRecord)
task.AddTask("autoFlushDeviceDailyRunningRecord", autoFlushDeviceDailyRunningRecord)
autoFlushDeviceDailyRunningRecordOEE := task.NewTask("定时刷新设备每日运行记录-OEE", "0 */10 * * * *", AutoFlushDeviceDailyRunningRecordOEE)
task.AddTask("autoFlushDeviceDailyRunningRecordOEE", autoFlushDeviceDailyRunningRecordOEE)
autoWorkshopPlanCompletionRecord := task.NewTask("定时刷新昨日车间计划完成纪录", "0 5 1-17/1 * * *", AutoWorkshopPlanCompletionRecord)
task.AddTask("autoWorkshopPlanCompletionRecord", autoWorkshopPlanCompletionRecord)
autoTodayWorkshopPlanCompletionRecord := task.NewTask("定时刷新当天车间计划完成纪录", "0 0 1-23/1 * * *", AutoTodayWorkshopPlanCompletionRecord) // 1:00, 4:00, 每三个小时运行一次
task.AddTask("autoTodayWorkshopPlanCompletionRecord", autoTodayWorkshopPlanCompletionRecord)
syncProductPlan := task.NewTask("定时同步车间计划", "0 */5 * * * *", SyncProductPlan)
task.AddTask("SyncProductPlan", syncProductPlan)
syncProduct := task.NewTask("定时同步产品信息", "0 */30 * * * *", SyncProduct)
task.AddTask("syncProduct", syncProduct)
}
func (crontabService *CrontabService) StartCrontabTask() {
crontabService.initTask()
task.StartTask()
log.Logger.Info("crontab start!")
}
func (crontabService *CrontabService) StopCrontabTask() {
task.StopTask()
log.Logger.Info("crontab stop!")
}
... ...
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), map[string]interface{}{"task": "定时审核生产考勤记录"})
}
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return err
}
if err := transactionContext.StartTransaction(); err != nil {
return err
}
defer func() {
if err != nil {
log.Logger.Error("【定时审核生产考勤记录】 失败:" + err.Error())
}
transactionContext.RollbackTransaction()
}()
attendanceRecordDao, _ := dao.NewAttendanceRecordDao(transactionContext.(*pgTransaction.TransactionContext))
var records []*domain.ProductAttendanceRecord
_, records, err = attendanceRecordDao.RecentUnApprovedAttendanceRecord(24, 2)
if err != nil {
log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时审核生产考勤记录"})
return err
}
approveAttendanceRecordsService, _ := domainService.NewPGApproveAttendanceRecordsService(transactionContext.(*pgTransaction.TransactionContext))
if _, err = approveAttendanceRecordsService.BatchApproveAttendanceRecords(nil, records, 0, 0, domain.AttendanceAutoApproved); err != nil {
log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时审核生产考勤记录"})
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), map[string]interface{}{"task": "定时审核生产记录"})
}
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return err
}
if err := transactionContext.StartTransaction(); err != nil {
return err
}
defer func() {
if err != nil {
log.Logger.Error("【定时审核生产考勤记录】 失败:" + err.Error())
}
transactionContext.RollbackTransaction()
}()
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 {
log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时审核生产记录"})
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), map[string]interface{}{"task": "定时刷新设备每日运行记录"})
}
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return err
}
if err := transactionContext.StartTransaction(); err != nil {
return err
}
defer func() {
if err != nil {
log.Logger.Error("【定时刷新设备每日运行记录】 失败:" + err.Error())
}
transactionContext.RollbackTransaction()
}()
log.Logger.Debug("【定时刷新设备每日运行记录】 启动")
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.Debug(err.Error())
return err
}
for _, v := range records {
if v.UpdatedAt.Add(time.Minute * 20).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(), map[string]interface{}{"record": v})
continue
} else {
log.Logger.Debug(fmt.Sprintf("【定时刷新设备每日运行记录】 刷新记录 %v", v))
}
}
if err = transactionContext.CommitTransaction(); err != nil {
return err
}
return nil
}
... ...
package crontab
import (
"context"
"fmt"
"github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"time"
)
// 定时刷新设备每日运行记录
func AutoFlushDeviceDailyRunningRecordOEE(ctx context.Context) error {
defer func() {
if r := recover(); r != nil {
log.Logger.Error(fmt.Sprintf("%v", r), map[string]interface{}{"task": "定时刷新设备每日运行记录"})
}
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return err
}
if err := transactionContext.StartTransaction(); err != nil {
return err
}
defer func() {
if err != nil {
log.Logger.Error("【定时刷新设备每日运行记录-OEE】 失败:" + err.Error())
}
transactionContext.RollbackTransaction()
}()
log.Logger.Debug("【定时刷新设备每日运行记录-OEE】 启动")
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
}
total := 24 * 60 * 60
deviceRepository, _, _ := factory.FastPgDevice(transactionContext, 0)
workshopProductRecordDao, _ := dao.NewWorkshopProductRecordDao(transactionContext.(*pg.TransactionContext))
for _, v := range records {
//if v.UpdatedAt.Add(time.Minute * 5).Before(time.Now()) {
// log.Logger.Debug(fmt.Sprintf("【定时刷新设备每日运行记录-OEE】 跳过记录 %v 最后更新时间:%v", v, v.UpdatedAt))
// continue
//}
var (
pu float64 = 100
qu float64 = 100
)
// 更新设备效率 OEE = tu * pu * qu
/*
pu 性能利用
设备标准工时,
没有配置设备标准工时的为100
*/
// 只计算串串机
if v.DeviceRunningRecordInfo.DeviceType == domain.DeviceTypeChuanChuanJi {
// 设备数据(标准工时)
device, err := deviceRepository.FindOne(map[string]interface{}{"deviceId": v.DeviceId})
if device != nil && err == nil {
if device.Ext.DeviceExt != nil {
pu = utils.Round((float64(v.DeviceRunningRecordInfo.Count)*100.0)/(float64(total)/device.Ext.DeviceExt.UnitProductionSecTime), 1)
}
}
// 工段对应二级品数据
record, err := workshopProductRecordDao.WorkStationProductRecord(v.CompanyId, v.OrgId, v.WorkStation.WorkStationId, t)
if record != nil && err == nil {
qu = float64(v.DeviceRunningRecordInfo.Count) * domainService.DefaultCCJUnitQuantity
qu = utils.Round((qu-record.SecondLevelWeigh)*100/qu, 1)
}
}
v.DeviceRunningRecordInfo.ResetOEE(pu, qu)
if _, err := deviceDailyRunningRecordRepository.Save(v); err != nil {
log.Logger.Error(err.Error())
continue
}
if err := redis.SaveDeviceDailyRunningRecord(v); err != nil {
log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时刷新设备每日运行记录"})
continue
}
log.Logger.Debug(fmt.Sprintf("【定时刷新设备每日运行记录-OEE】 刷新记录 %v", v))
}
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/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"time"
)
// 定时刷新车间计划完成纪录
func AutoWorkshopPlanCompletionRecord(ctx context.Context) error {
defer func() {
if r := recover(); r != nil {
log.Logger.Error(fmt.Sprintf("%v", r), map[string]interface{}{"task": "定时刷新车间计划完成纪录"})
}
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return err
}
if err := transactionContext.StartTransaction(); err != nil {
return err
}
defer func() {
if err != nil {
log.Logger.Error("【定时刷新车间计划备每日运行记录】 失败:" + err.Error())
}
transactionContext.RollbackTransaction()
}()
log.Logger.Debug("【定时刷新车间计划每日运行记录】 启动")
end := utils.GetZeroTime(time.Now())
begin := utils.GetZeroTime(end.Add(-time.Second))
approveAttendanceRecordsService, _ := domainService.NewPGWorkshopPlanCompletionRecordService(transactionContext.(*pgTransaction.TransactionContext))
if err = approveAttendanceRecordsService.WorkshopPlanCompletion(begin, end, "yesterday"); err != nil {
log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时刷新车间计划完成纪录"})
return err
}
if err = transactionContext.CommitTransaction(); err != nil {
return err
}
return nil
}
// 定时刷新当天车间计划完成纪录
func AutoTodayWorkshopPlanCompletionRecord(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("【定时刷新车间计划今日运行记录】 启动")
begin := utils.GetZeroTime(time.Now())
end := time.Now()
approveAttendanceRecordsService, _ := domainService.NewPGWorkshopPlanCompletionRecordService(transactionContext.(*pgTransaction.TransactionContext))
if err = approveAttendanceRecordsService.WorkshopPlanCompletion(begin, end, "today"); err != nil {
log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时刷新当天车间计划完成纪录"})
return err
}
if err = transactionContext.CommitTransaction(); err != nil {
return err
}
return nil
}
... ...
package crontab
import (
"context"
"fmt"
"github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/syncdata"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"runtime/debug"
"time"
)
// SyncProduct 定时同步产品
func SyncProduct(ctx context.Context) error {
defer func() {
if r := recover(); r != nil {
log.Logger.Error(fmt.Sprintf("%v", r), map[string]interface{}{"task": "定时同步产品", "stack": string(debug.Stack())})
}
}()
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("【定时同步同步产品信息】 启动")
pullK3CloudService := syncdata.PullDataK3CloudService{}
t := ctx.Value("fromTime")
var fromTime time.Time
if ctx != nil {
if t != nil {
if v, ok := t.(time.Time); ok {
fromTime = v
}
}
}
if fromTime.IsZero() {
fromTime, err = redis.GetLastFetchTime(redis.MaterialK3cloudFetchTimeKey())
if err != nil {
log.Logger.Error(err.Error())
return nil
}
}
if err := pullK3CloudService.SyncDataProduct(transactionContext.(*pg.TransactionContext), fromTime); err != nil {
log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时同步产品"})
return nil
}
if err = transactionContext.CommitTransaction(); err != nil {
return err
}
return nil
}
... ...
package crontab
import (
"context"
"fmt"
"github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/syncdata"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"runtime/debug"
"time"
)
// 定时同步生产计划
func SyncProductPlan(ctx context.Context) error {
defer func() {
if r := recover(); r != nil {
log.Logger.Error(fmt.Sprintf("%v", r), map[string]interface{}{"task": "定时同步车间计划", "stack": debug.Stack()})
}
}()
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("【定时同步车间计划】 启动")
pullK3CloudService := syncdata.PullDataK3CloudService{}
var fromTime time.Time
if ctx != nil {
t := ctx.Value("fromTime")
if t != nil {
if v, ok := t.(time.Time); ok {
fromTime = v
}
}
}
if err := pullK3CloudService.SyncDataProductPlan(transactionContext.(*pg.TransactionContext), fromTime); err != nil {
log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时同步车间计划"})
return nil
}
if err = transactionContext.CommitTransaction(); err != nil {
return err
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type BatchRemoveDeviceCommand struct {
// ID列表
IdList []int `cname:"ID列表" json:"idList" valid:"Required"`
}
func (removeDeviceCommand *BatchRemoveDeviceCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeDeviceCommand *BatchRemoveDeviceCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeDeviceCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeDeviceCommand).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
}
... ...
... ... @@ -22,21 +22,24 @@ 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" valid:"Required"`
Brand string `cname:"品牌" json:"brand"`
// 设备状态 1:正常 2:封存 3:报废
DeviceStatus int `cname:"设备状态 1:正常 2:封存 3:报废" json:"deviceStatus" valid:"Required"`
// 风险等级 1:高 2:中 3:低
RiskLevel int `cname:"风险等级 1:高 2:中 3:低" json:"riskLevel" valid:"Required"`
// 标准工时 生产单个产品的时间(单位:秒)
UnitProductionSecTime float64 `cname:"标准工时" json:"unitProductionSecTime"`
}
func (createDeviceCommand *CreateDeviceCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createDeviceCommand *CreateDeviceCommand) ValidateCommand() error {
... ...
... ... @@ -14,7 +14,7 @@ type RemoveDeviceCommand struct {
}
func (removeDeviceCommand *RemoveDeviceCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeDeviceCommand *RemoveDeviceCommand) ValidateCommand() error {
... ...
... ... @@ -20,21 +20,23 @@ 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:低
RiskLevel int `cname:"风险等级 1:高 2:中 3:低" json:"riskLevel" valid:"Required"`
// 标准工时
UnitProductionSecTime int `cname:"标准工时" json:"unitProductionSecTime"`
}
func (updateDeviceCommand *UpdateDeviceCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateDeviceCommand *UpdateDeviceCommand) ValidateCommand() error {
... ...
package dto
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
type DeviceDto struct {
// 设备Id
DeviceId int `json:"deviceId,omitempty"`
// 设备编号
DeviceCode string `json:"deviceCode,omitempty"`
// 设备名称
DeviceName string `json:"deviceName,omitempty"`
// 设备型号
DeviceModel string `json:"deviceModel,omitempty"`
// 设备类型
DeviceType string `json:"deviceType,omitempty"`
// 品牌
Brand string `json:"brand,omitempty"`
// 设备状态 1:正常 2:封存 3:报废
DeviceStatus int `json:"deviceStatus,omitempty"`
// 风险等级 1:高 2:中 3:低
RiskLevel int `json:"riskLevel,omitempty"`
// 所属位置
*domain.WorkStation
// 生产单个产品的时间(单位:秒)
UnitProductionSecTime string `json:"unitProductionSecTime"`
// 组织名称
OrgName string `json:"orgName"`
// 权限标识 (当前登录组织匹配为true,否则false)
AuthFlag bool `json:"authFlag"`
}
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
d.RiskLevel = m.RiskLevel
d.WorkStation = m.WorkStation
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
}
if m.Ext != nil && m.Ext.DeviceExt != nil {
if m.Ext.DeviceExt.UnitProductionSecTime > 0 {
d.UnitProductionSecTime = fmt.Sprintf("%v", m.Ext.DeviceExt.UnitProductionSecTime)
}
}
return d
}
... ...
... ... @@ -14,7 +14,7 @@ type GetDeviceQuery struct {
}
func (getDeviceQuery *GetDeviceQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getDeviceQuery *GetDeviceQuery) ValidateQuery() error {
... ...
... ... @@ -10,13 +10,13 @@ import (
type ListDeviceQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
Offset int `cname:"查询偏离量" json:"offset"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listDeviceQuery *ListDeviceQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listDeviceQuery *ListDeviceQuery) ValidateQuery() error {
... ...
package query
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type SearchDeviceQuery 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" valid:"Required"`
// 页码
PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
// 页数
PageSize int `cname:"页数" json:"pageSize,omitempty"`
// 设备名称
DeviceName string `json:"deviceName,omitempty"`
// 设备状态 1:正常 2:封存 3:报废
DeviceStatus int `json:"deviceStatus,omitempty"`
// 排除的设备列表
IncludeDevices []int `cname:"排除的设备列表" json:"includeDevices"`
}
func (cmd *SearchDeviceQuery) Valid(validation *validation.Validation) {
cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize)
}
func (cmd *SearchDeviceQuery) 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
}
... ...
... ... @@ -3,11 +3,16 @@ 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/device/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/device/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/device/query"
"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/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"time"
)
// 设备服务
... ... @@ -15,8 +20,10 @@ type DeviceService struct {
}
// 创建设备服务
func (deviceService *DeviceService) CreateDevice(createDeviceCommand *command.CreateDeviceCommand) (interface{}, error) {
if err := createDeviceCommand.ValidateCommand(); err != nil {
func (deviceService *DeviceService) CreateDevice(operateInfo *domain.OperateInfo, cmd *command.CreateDeviceCommand) (interface{}, error) {
cmd.OrgId = operateInfo.OrgId
cmd.CompanyId = operateInfo.CompanyId
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -29,27 +36,51 @@ func (deviceService *DeviceService) CreateDevice(createDeviceCommand *command.Cr
defer func() {
transactionContext.RollbackTransaction()
}()
var workStation *domain.WorkStation
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()
var org *domain.Org
org, err = userService.Organization(operateInfo.OrgId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
newDevice := &domain.Device{
CompanyId: createDeviceCommand.CompanyId,
OrgId: createDeviceCommand.OrgId,
DeviceCode: createDeviceCommand.DeviceCode,
DeviceName: createDeviceCommand.DeviceName,
DeviceModel: createDeviceCommand.DeviceModel,
DeviceType: createDeviceCommand.DeviceType,
//WorkshopId: createDeviceCommand.WorkshopId,
//LineId: createDeviceCommand.LineId,
//SectionId: createDeviceCommand.SectionId,
Brand: createDeviceCommand.Brand,
DeviceStatus: createDeviceCommand.DeviceStatus,
RiskLevel: createDeviceCommand.RiskLevel,
CompanyId: cmd.CompanyId,
OrgId: cmd.OrgId,
DeviceCode: cmd.DeviceCode,
DeviceName: cmd.DeviceName,
DeviceModel: cmd.DeviceModel,
DeviceType: cmd.DeviceType,
WorkStation: workStation,
Brand: cmd.Brand,
DeviceStatus: cmd.DeviceStatus,
RiskLevel: cmd.RiskLevel,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Ext: domain.NewExt(org.OrgName).WithDeviceExt(&domain.DeviceExt{UnitProductionSecTime: cmd.UnitProductionSecTime}),
}
deviceRepository, _, _ := factory.FastPgDevice(transactionContext, 0)
if total, _, err := deviceRepository.Find(map[string]interface{}{
"deviceCode": cmd.DeviceCode,
"companyId": cmd.CompanyId,
"orgId": cmd.OrgId,
"limit": 1,
}); err == nil && total > 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "设备编号重复")
}
var deviceRepository domain.DeviceRepository
if value, err := factory.CreateDeviceRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
if err := newDevice.Valid(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
deviceRepository = value
}
if device, err := deviceRepository.Save(newDevice); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -94,7 +125,10 @@ func (deviceService *DeviceService) GetDevice(getDeviceQuery *query.GetDeviceQue
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return device, nil
result := &dto.DeviceDto{}
result.LoadDto(device, 0)
return result, nil
}
}
... ... @@ -174,9 +208,9 @@ func (deviceService *DeviceService) RemoveDevice(removeDeviceCommand *command.Re
}
}
// 更新设备服务
func (deviceService *DeviceService) UpdateDevice(updateDeviceCommand *command.UpdateDeviceCommand) (interface{}, error) {
if err := updateDeviceCommand.ValidateCommand(); err != nil {
// 移除设备服务
func (deviceService *DeviceService) BatchRemoveDevice(cmd *command.BatchRemoveDeviceCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -197,16 +231,89 @@ func (deviceService *DeviceService) UpdateDevice(updateDeviceCommand *command.Up
} else {
deviceRepository = value
}
device, err := deviceRepository.FindOne(map[string]interface{}{"deviceId": updateDeviceCommand.DeviceId})
for i := range cmd.IdList {
id := cmd.IdList[i]
device, err := deviceRepository.FindOne(map[string]interface{}{"deviceId": id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if device == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDeviceCommand.DeviceId)))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", id))
}
if _, err := deviceRepository.Remove(device); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
if err := device.Update(tool_funs.SimpleStructToMap(updateDeviceCommand)); err != nil {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct {
}{}, nil
}
// 更新设备服务
func (deviceService *DeviceService) UpdateDevice(cmd *command.UpdateDeviceCommand) (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 deviceRepository domain.DeviceRepository
var device *domain.Device
deviceRepository, device, err = factory.FastPgDevice(transactionContext, cmd.DeviceId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
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())
//}
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
if cmd.DeviceCode != device.DeviceCode {
if total, _, err := deviceRepository.Find(map[string]interface{}{
"deviceCode": cmd.DeviceCode,
"companyId": device.CompanyId,
"orgId": device.OrgId,
"limit": 1,
}); err == nil && total > 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "设备编号重复")
}
}
var userService = domainService.NewUserService()
var org *domain.Org
org, err = userService.Organization(device.OrgId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
data := tool_funs.SimpleStructToMap(cmd)
data["orgName"] = org.OrgName
if err := device.Update(data); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if err := device.Valid(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if device, err := deviceRepository.Save(device); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -217,6 +324,133 @@ func (deviceService *DeviceService) UpdateDevice(updateDeviceCommand *command.Up
}
}
// 返回设备服务列表
func (deviceService *DeviceService) SearchDevice(operateInfo *domain.OperateInfo, listDeviceQuery *query.SearchDeviceQuery) (int64, interface{}, error) {
if err := listDeviceQuery.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()
}()
deviceRepository, _, _ := factory.FastPgDevice(transactionContext, 0)
count, devices, err := deviceRepository.Find(utils.ObjectToMap(listDeviceQuery))
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
workshops, _ := factory.FastPgWorkshops(transactionContext, operateInfo.CompanyId)
var result = make([]*dto.DeviceDto, 0)
for i := range devices {
item := devices[i]
newJobDto := &dto.DeviceDto{}
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)
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return count, result, nil
}
// 返回设备服务列表
func (deviceService *DeviceService) SelectorDeviceUnbounded(operateInfo *domain.OperateInfo, listDeviceQuery *query.SearchDeviceQuery) (int64, interface{}, error) {
if err := listDeviceQuery.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()
}()
deviceRepository, _, _ := factory.FastPgDevice(transactionContext, 0)
count, devices, err := deviceRepository.Find(utils.ObjectToMap(listDeviceQuery))
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
workshops, _ := factory.FastPgWorkshops(transactionContext, operateInfo.CompanyId)
productJobRepository, _, _ := factory.FastPgProductJob(transactionContext, 0)
_, productJobs, _ := productJobRepository.Find(map[string]interface{}{"companyId": listDeviceQuery.CompanyId})
var excludeMap = make(map[int]int)
var allBoundedDevice = make([]int, 0)
for i := range productJobs {
allBoundedDevice = append(allBoundedDevice, productJobs[i].RelatedDevices...)
}
for _, v := range allBoundedDevice {
exclude := false
for _, j := range listDeviceQuery.IncludeDevices {
if j == v {
exclude = true
}
}
if exclude {
continue
}
excludeMap[v] = v
}
var result = make([]*dto.DeviceDto, 0)
for i := range devices {
item := devices[i]
newJobDto := &dto.DeviceDto{}
if _, ok := excludeMap[item.DeviceId]; ok {
continue
}
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)
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return count, result, nil
}
// 批量添加产品服务
func (deviceService *DeviceService) BatchAddProduct(opt *domain.OperateInfo, list []*domain.ImportDeviceItem) ([]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
batchAddProductService, _ := domainService.NewPGBatchAddDeviceService(transactionContext.(*pgTransaction.TransactionContext))
var failRows []interface{}
if failRows, err = batchAddProductService.BatchAddDevice(opt, list); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if len(failRows) != 0 {
return failRows, nil //有错误行,回滚
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return failRows, nil
}
func NewDeviceService(options map[string]interface{}) *DeviceService {
newDeviceService := &DeviceService{}
return newDeviceService
... ...
package command
import (
"fmt"
"reflect"
"strings"
"time"
"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"`
// 采集时间
CollectionTime time.Time `cname:"采集时间" json:"collectionTime" valid:"Required"`
// 设备名
DeviceSn string `cname:"设备名" json:"deviceSn" valid:"Required"`
// 设备类型
DeviceType string `comment:"设备类型" json:"deviceType" valid:"Required"`
// 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障
ComStatus int64 `cname:"通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障" json:"comStatus"`
// 设备数据值
Values map[string]interface{} `cname:"设备数据值" json:"values" valid:"Required"`
// 预查
PreCheck bool `json:"check"`
}
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"
"time"
"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"`
// 采集时间
CollectionTime time.Time `cname:"采集时间" json:"collectionTime" valid:"Required"`
// 设备名
DeviceSn string `cname:"设备名" json:"deviceSn" valid:"Required"`
// 设备类型
DeviceType string `comment:"设备类型" json:"deviceType" valid:"Required"`
// 通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障
ComStatus int64 `cname:"通讯状态 1-通讯正常 0-设备未上电或与采集端通讯故障" json:"comStatus"`
// 设备数据值
Values map[string]interface{} `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 dto
import "time"
type DeviceCollectionDto 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 map[string]interface{} `json:"values"`
}
... ...
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"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type ListDeviceCollectionQuery struct {
// 查询偏离量
PageNumber int64 `cname:"查询偏离量" json:"pageNumber" `
// 查询限制
PageSize int64 `cname:"查询限制" json:"pageSize" valid:"Required"`
// 设备类型
DeviceType string `json:"deviceType" cname:"设备类型"`
// 车间名
WorkShopName string `json:"workShopName"`
// 开始时间
BeginTime string `cname:"开始时间" json:"beginTime"`
// 结束时间
EndTime string `cname:"结束时间" json:"endTime"`
// 开始时间
ProductBeginTime time.Time `cname:"开始时间" json:"productBeginTime"`
// 结束时间
ProductEndTime time.Time `cname:"结束时间" json:"productEndTime"`
}
func (cmd *ListDeviceCollectionQuery) Valid(validation *validation.Validation) {
var err error
if len(cmd.BeginTime) > 0 {
if cmd.ProductBeginTime, err = time.ParseInLocation("2006-01-02 15:04:05", cmd.BeginTime, time.Local); err != nil {
log.Logger.Error(err.Error())
validation.Error("开始时间有误")
return
}
}
if len(cmd.EndTime) > 0 {
if cmd.ProductEndTime, err = time.ParseInLocation("2006-01-02 15:04:05", cmd.EndTime, time.Local); err != nil {
log.Logger.Error(err.Error())
validation.Error("结束时间有误")
return
}
if cmd.ProductBeginTime.Equal(cmd.ProductEndTime) {
cmd.ProductEndTime = cmd.ProductEndTime.Add(time.Hour * 24)
}
}
}
func (cmd *ListDeviceCollectionQuery) 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 (
"errors"
"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"
"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"
"strconv"
"sync"
"time"
)
type DeviceCollectionService struct {
}
var (
DeviceDataCache = NewDeviceDataInstance()
)
// 创建
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,
DeviceType: createDeviceCollectionCommand.DeviceType,
StartupStatus: createDeviceCollectionCommand.StartupStatus,
DeviceSn: createDeviceCollectionCommand.DeviceSn,
ComStatus: createDeviceCollectionCommand.ComStatus,
CollectionTime: createDeviceCollectionCommand.CollectionTime,
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 map[string]interface{}{
"deviceCollection": deviceCollection,
}, nil
}
}
// 创建
func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createDeviceCollectionCommand *command.CreateDeviceCollectionCommand) (interface{}, error) {
if err := createDeviceCollectionCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
newDeviceCollection := &domain.DeviceCollection{
//DeviceCollectionId: createDeviceCollectionCommand.DeviceCollectionId,
WorkShopName: createDeviceCollectionCommand.WorkShopName,
DeviceType: createDeviceCollectionCommand.DeviceType,
StartupStatus: createDeviceCollectionCommand.StartupStatus,
DeviceSn: createDeviceCollectionCommand.DeviceSn,
ComStatus: createDeviceCollectionCommand.ComStatus,
CollectionTime: createDeviceCollectionCommand.CollectionTime,
Values: createDeviceCollectionCommand.Values,
LatestUpdateTime: time.Now(),
}
var lastDeviceCollectionRecord = &domain.DeviceCollection{}
var err error
if createDeviceCollectionCommand.PreCheck {
//前置验证,限制设备上报速率
if lastDeviceCollectionRecord, err = DeviceDataCache.Add(newDeviceCollection.DeviceSn, newDeviceCollection.DeviceType, newDeviceCollection); err != nil {
//log.Logger.Error(err.Error()+newDeviceCollection.DeviceSn)
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if lastDeviceCollectionRecord == nil {
//log.Logger.Error("未找到上一条设备数据")
return nil, nil
}
}
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 v, ok := newDeviceCollection.Values["Count"]; ok {
newDeviceCollection.Values["total"] = v // 记录原始值
newDeviceCollection.Values["Count"] = 0
curCount, errCurCount := strconv.Atoi(utils.AssertString(v))
lastCount, errLastCount := strconv.Atoi(utils.AssertString(lastDeviceCollectionRecord.Values["Count"]))
var count int
if errLastCount == nil && errCurCount == nil && lastCount <= curCount {
if lastCount <= curCount {
count = curCount - lastCount
} else {
count = 0
/*设备统计的数量超过一定范围会重置为0,特殊处理0操作*/
if lastCount > 10000000 && curCount < 1000 {
count = curCount
}
}
newDeviceCollection.Values["Count"] = count
newDeviceCollection.ProductCount = count
}
}
// TODO:测试假数据,后期注释掉
//if createDeviceCollectionCommand.DeviceType == domain.DeviceTypeChuanChuanJi {
// newDeviceCollection.Values["Count"] = rand.Intn(300)
//}
deviceCollection, err := deviceCollectionRepository.Save(newDeviceCollection)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = domainService.SendWorkshopDeviceData(deviceCollection)
if err != nil {
log.Logger.Error("车间设备数据加入redis失败:" + err.Error())
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 map[string]interface{}{
"deviceCollection": 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 tool_funs.SimpleWrapGridMap(count, 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 map[string]interface{}{
"deviceCollection": 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 map[string]interface{}{
"deviceCollection": deviceCollection,
}, nil
}
}
func NewDeviceCollectionService(options map[string]interface{}) *DeviceCollectionService {
newDeviceCollectionService := &DeviceCollectionService{}
return newDeviceCollectionService
}
const DefaultReceiveSpan = 60 // 60 sec
type DeviceDataInstance struct {
//deviceDataCache sync.Map
deviceDataLastTime sync.Map
}
func NewDeviceDataInstance() *DeviceDataInstance {
return &DeviceDataInstance{
deviceDataLastTime: sync.Map{},
}
}
func (d *DeviceDataInstance) Add(deviceSn, deviceType string, data interface{}) (*domain.DeviceCollection, error) {
// 获取数据上一次的
var v interface{}
var ok bool
var now = time.Now().Unix()
var t = now
if v, ok = d.deviceDataLastTime.Load(deviceSn); ok {
t = v.(int64)
} else {
d.deviceDataLastTime.Store(deviceSn, t)
redis.SaveDeviceRealTimeData(deviceSn, data, true)
return nil, errors.New(fmt.Sprintf("ingnore this record"))
}
// 60秒接受一次数据,暂时不用太多数据
if now < t+DefaultReceiveSpan {
return nil, errors.New(fmt.Sprintf("receive too fast wait %v sec", t+DefaultReceiveSpan-now))
}
// 从redis获取最后的数据进行处理
var result = &domain.DeviceCollection{}
if err := redis.GetDeviceRealTimeData(deviceSn, result); err != nil {
if err == domain.ErrorNotFound {
redis.SaveDeviceRealTimeData(deviceSn, data, true)
return nil, nil
}
return nil, err
}
//log.Logger.Debug("",map[string]interface{}{"t":t,"device":deviceSn})
d.deviceDataLastTime.Store(deviceSn, now)
return result, redis.SaveDeviceRealTimeData(deviceSn, data, false)
}
... ...
package command
import (
"encoding/json"
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
type ExportDataCommand struct {
//操作人
Operator *domain.OperateInfo `json:"-"`
// 业务编码
Ids []string `json:"ids"`
Where json.RawMessage `json:"where"`
// 业务编码
Code string `form:"code"`
}
func (exportDataCommand *ExportDataCommand) Valid(validation *validation.Validation) {
}
func (exportDataCommand *ExportDataCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(exportDataCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
func (exportDataCommand *ExportDataCommand) UnmarshalQuery(query interface{}) error {
return json.Unmarshal(exportDataCommand.Where, query)
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"io"
)
type ImportDataCommand struct {
//操作人
Operator *domain.OperateInfo `json:"-"`
Reader io.Reader `json:"-"`
FileExt string `json:"-"`
// 业务编码
Code string `form:"code"`
}
func (importDataCommand *ImportDataCommand) Valid(validation *validation.Validation) {
}
func (importDataCommand *ImportDataCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(importDataCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import ()
type CooperationUserListQuery struct {
//操作人
//Operator domain.Operator `json:"-"`
//用户名称
UserName string `json:"userName"`
//共创公司
CooperationCompany string `json:"cooperationCompany"`
SelectedField []string `json:"selectedField"`
}
... ...
package service
// ExportCompanyUser 导出公司用户信息列表
//func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCompanyUserData, error) {
// creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)
// result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
// Limit: 10000,
// CompanyId: companyUserListQuery.Operator.CompanyId,
// OrganizationId: 0,
// DepartmentId: 0,
// UserName: companyUserListQuery.UserName,
// DepName: companyUserListQuery.DepartmentName,
// Phone: "",
// UserType: domain.UserTypeEmployee,
// InOrgIds: companyUserListQuery.Operator.OrgIds,
// PullRealTime: true,
// })
// if err != nil {
// return ExportCompanyUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
// }
// return ExportCompanyUserData{
// SourceData: result.Users,
// SelectedField: companyUserListQuery.SelectedField,
// }, nil
//}
// ExportCooperationUser 导出共创用户信息列表
//func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.CooperationUserListQuery) (ExportCooperationUserData, error) {
// creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)
// result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
// Limit: 10000,
// CompanyId: companyUserListQuery.Operator.CompanyId,
// OrganizationId: 0,
// DepartmentId: 0,
// UserName: companyUserListQuery.UserName,
// CooperationCompany: companyUserListQuery.CooperationCompany,
// Phone: "",
// UserType: domain.UserTypeCooperation,
// InOrgIds: companyUserListQuery.Operator.OrgIds,
// })
// if err != nil {
// return ExportCooperationUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
// }
// return ExportCooperationUserData{SourceData: result.Users, SelectedField: companyUserListQuery.SelectedField}, nil
//}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/ecelData/command"
"strings"
"github.com/linmadan/egglib-go/utils/excel"
)
type ExcelDataService struct {
}
func NewExcelDataService(param map[string]interface{}) *ExcelDataService {
return &ExcelDataService{}
}
// 导入结果
func (srv ExcelDataService) importResultWithHeader(headers []excel.DataField, failRows []interface{}, totalRow int) interface{} {
var result = map[string]interface{}{
"successCount": 0,
"fail": struct{}{},
}
if len(failRows) == 0 {
result["successCount"] = totalRow
}
if len(failRows) > 0 {
fail := map[string]interface{}{
"body": failRows,
}
var header = make(map[string]string)
for i := 0; i < len(headers); i++ {
item := headers[i]
header[item.EnName] = item.CnName
}
fail["header"] = header
result["fail"] = fail
}
return result
}
func (srv ExcelDataService) fieldValueAllEmpty(param map[string]string) bool {
isAllEmpty := true
for _, v := range param {
value := strings.TrimSpace(v)
if len(value) > 0 {
isAllEmpty = false
}
}
return isAllEmpty
}
//// FileImportTemplate 导入模板
func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.ImportDataCommand) (interface{}, error) {
var mapTemplate = map[string]string{
//domain.ImportCompanyUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807485_EaxECeRz23WpzrMZmbwdEPRJ3Pdxpx5X.xlsx",
//domain.ImportOrganization: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807490_r2XWhGmbWWmpbeePBkZ3EJQFKcZEMpEm.xlsx",
//domain.ImportDividendsOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210927/object/1632743206_NPYTKw6RGhXn4TpYNEQhGGdCkXKXTnxM.xlsx",
//domain.ImportCooperationUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210926/object/1632635345_SbfzmkXjQHhCwPw4MB7zb5EBBtdp2MSE.xlsx",
//domain.ImportDividendsReturnOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210927/object/1632743214_rNHm6ZBXZaC5xKTrsE7M4h45MY6n6Ff3.xlsx",
}
var url string
var ok bool
if url, ok = mapTemplate[importDataCommand.Code]; !ok {
return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("模板:%v 不存在", importDataCommand.Code))
}
return map[string]string{
"url": url,
}, nil
}
func (srv ExcelDataService) GetExcelDataFields(code string) (interface{}, error) {
dataFields := []DataFieldOptions{}
//switch code {
//case domain.ExportCompanyUser:
// dataFileds = (ExportCompanyUserData{}).AllFields()
//case domain.ExportCooperationUser:
// dataFileds = (ExportCooperationUserData{}).AllFields()
//}
return dataFields, nil
}
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/excel"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/ecelData/command"
productService "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/product/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils/converter"
"strings"
)
// ImportProduct 导入生产信息
func (srv ExcelDataService) ImportProduct(importDataCommand *command.ImportDataCommand) (interface{}, error) {
excelImport := excel.NewExcelImport()
excelImport.RowBegin = 3 //第二行开始读取
excelImport.DataFields = []excel.DataField{
{EnName: "productCode", CnName: "产品编号"},
{EnName: "productName", CnName: "*品名"},
{EnName: "unit", CnName: "*规格"},
{EnName: "productCategory", CnName: "*类别"},
{EnName: "unitWeight", CnName: "投入单份重量"},
}
excelData, err := converter.OpenImportFileFromIoReader(excelImport, importDataCommand.Reader, importDataCommand.FileExt) //excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
items := make([]*domain.ImportProductItem, 0)
for _, v := range excelData {
item := &domain.ImportProductItem{
ProductCode: strings.TrimSpace(v["productCode"]),
ProductName: strings.TrimSpace(v["productName"]),
ProductCategory: strings.TrimSpace(v["productCategory"]),
Unit: strings.TrimSpace(v["unit"]),
UnitWeight: strings.TrimSpace(v["unitWeight"]),
}
items = append(items, item)
}
svr := productService.NewProductService(nil)
failRows, err := svr.BatchAddProduct(importDataCommand.Operator, items)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return srv.importResultWithHeader(excelImport.DataFields, failRows, len(items)), nil
}
... ...
package service
type DataFieldOptions struct {
EnName string `json:"enName"`
CnName string `json:"cnName"`
IsDefault bool `json:"isDefault"`
}
//
//// ExportCompanyUserData 导出公司用户数据
//type ExportCompanyUserData struct {
// SourceData []allied_creation_user.UserDetail
// SelectedField []string
//}
//
//var _ excel.ExcelMaker = (*ExportCompanyUserData)(nil)
//
//func (data ExportCompanyUserData) AllFields() []DataFieldOptions {
// return []DataFieldOptions{
// {EnName: "UserCode", CnName: "用户编码"},
// {EnName: "UserName", CnName: "用户姓名"},
// {EnName: "Phone", CnName: "手机号"},
// {EnName: "DepartmentName", CnName: "所属部门"},
// {EnName: "EnableStatus", CnName: "状态"},
// {EnName: "OrgName", CnName: "组织机构"},
// }
//}
//
//func (data ExportCompanyUserData) 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 ExportCompanyUserData) 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 "Phone":
// return data.SourceData[index].UserInfo.Phone
// case "DepartmentName":
// if data.SourceData[index].Department != nil {
// return data.SourceData[index].Department.DepartmentName
// } else {
// return ""
// }
// case "EnableStatus":
// status := data.SourceData[index].EnableStatus
// statusName := ""
// // 状态(1:启用 2:禁用 3:注销)
// switch status {
// case 1:
// statusName = "启用"
// case 2:
// statusName = "禁用"
// case 3:
// statusName = "注销"
// }
// return statusName
// case "OrgName":
// if data.SourceData[index].Org != nil {
// return data.SourceData[index].Org.OrgName
// } else {
// return ""
// }
// }
// return nil
//}
//
//func (data ExportCompanyUserData) DataListLen() int {
// return len(data.SourceData)
//}
//
//func (data ExportCompanyUserData) TableTitle() []string {
// return nil
//}
//
////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
//}
... ...
package factory
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
// FastPgWorkshop 快速返回车间对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgWorkshop(transactionContext application.TransactionContext, id int, options ...option) (domain.WorkshopRepository, *domain.Workshop, error) {
var rep domain.WorkshopRepository
var mod *domain.Workshop
var err error
if value, err := CreateWorkshopRepository(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{}{"workshopId": 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())
}
}
//if err = fastPgDataAuth(transactionContext, mod, options...); err != nil {
// return nil, nil, err
//}
return rep, mod, err
}
// FastPgWorkshop 快速返回车间对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgWorkshops(transactionContext application.TransactionContext, companyId int, options ...option) (domain.Workshops, error) {
var rep domain.WorkshopRepository
//var mod *domain.Workshop
var err error
if value, err := CreateWorkshopRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
_, workshops, err := rep.Find(map[string]interface{}{"companyId": companyId})
if err != nil {
return nil, err
}
if len(workshops) == 0 {
workshops = make([]*domain.Workshop, 0)
}
return workshops, err
}
// FastPgWorkstation 快速返回工作定位对象
//
// transactionContext 事务
// workshopId 车间ID
// lineId 生产线ID
// sectionId 对象ID
func FastPgWorkstation(transactionContext application.TransactionContext, workshopId, lineId, sectionId int, options ...option) (domain.WorkshopRepository, *domain.WorkStation, error) {
var rep domain.WorkshopRepository
var mod *domain.Workshop
var err error
if value, err := CreateWorkshopRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if mod, err = rep.FindOne(map[string]interface{}{"workshopId": workshopId}); 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())
}
workStation, err := mod.FindWorkStation(workshopId, lineId, sectionId)
if err != nil {
return rep, nil, err
}
o := NewFastOptions(options...)
if o.SetPrincipal {
workStation.Principal = mod.Principal
}
return rep, workStation, err
}
// FastPgProductJob 快速返回工位对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgProductJob(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductJobRepository, *domain.ProductJob, error) {
var rep domain.ProductJobRepository
var mod *domain.ProductJob
var err error
if value, err := CreateProductJobRepository(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{}{"productJobId": 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())
}
}
//if err = fastPgDataAuth(transactionContext, mod, options...); err != nil {
// return nil, nil, err
//}
return rep, mod, err
}
// FastPgProductGroup 快速返回生产组对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgProductGroup(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductGroupRepository, *domain.ProductGroup, error) {
var rep domain.ProductGroupRepository
var mod *domain.ProductGroup
var err error
if value, err := CreateProductGroupRepository(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{}{"productGroupId": 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())
}
}
//if err = fastPgDataAuth(transactionContext, mod, options...); err != nil {
// return nil, nil, err
//}
return rep, mod, err
}
// FastPgProduct 快速返回产品对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgProduct(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductRepository, *domain.Product, error) {
var rep domain.ProductRepository
var mod *domain.Product
var err error
if value, err := CreateProductRepository(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{}{"productId": 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
}
// FastPgDevice 快速返回设备对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgDevice(transactionContext application.TransactionContext, id int, options ...option) (domain.DeviceRepository, *domain.Device, error) {
var rep domain.DeviceRepository
var mod *domain.Device
var err error
if value, err := CreateDeviceRepository(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{}{"deviceId": 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
}
// FastPgProductCalendar 快速返回设备对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgProductCalendar(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductCalendarRepository, *domain.ProductCalendar, error) {
var rep domain.ProductCalendarRepository
var mod *domain.ProductCalendar
var err error
if value, err := CreateProductCalendarRepository(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{}{"productCalendarId": 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
}
// FastPgUnitConversion 快速返回单位换算对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgUnitConversion(transactionContext application.TransactionContext, id int, options ...option) (domain.UnitConversionRepository, *domain.UnitConversion, error) {
var rep domain.UnitConversionRepository
var mod *domain.UnitConversion
var err error
if value, err := CreateUnitConversionRepository(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{}{"unitConversionId": 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
}
// FastPgProductPlan 快速返回生产计划对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgProductPlan(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductPlanRepository, *domain.ProductPlan, error) {
var rep domain.ProductPlanRepository
var mod *domain.ProductPlan
var err error
if value, err := CreateProductPlanRepository(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{}{"productPlanId": 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
}
// 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 事务
// id 对象唯一标识
func FastPgAttendance(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductAttendanceRecordRepository, *domain.ProductAttendanceRecord, error) {
var rep domain.ProductAttendanceRecordRepository
var mod *domain.ProductAttendanceRecord
var err error
if value, err := CreateProductAttendanceRecordRepository(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{}{"productAttendanceRecordId": 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
}
// 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 {
DataAuthRequired bool
SetPrincipal bool
OperateInfo *domain.OperateInfo
}
func NewFastOptions(options ...option) *FastOptions {
o := &FastOptions{
DataAuthRequired: false,
}
for i := 0; i < len(options); i++ {
options[i](o)
}
return o
}
type option func(options *FastOptions)
// 需要数据权限
func WithDataAuthRequired() option {
return func(options *FastOptions) {
options.DataAuthRequired = true
}
}
// WithOperator 操作人
func WithOperator(op *domain.OperateInfo) option {
return func(options *FastOptions) {
options.OperateInfo = op
}
}
// WithOperator 操作人
func WithSetPrincipal() option {
return func(options *FastOptions) {
options.SetPrincipal = true
}
}
... ...