作者 Administrator

合并分支 'test' 到 'master'

Test



查看合并请求 !10
正在显示 60 个修改的文件 包含 4197 行增加94 行删除

要显示太多修改。

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

@@ -29,3 +29,5 @@ swagger.json @@ -29,3 +29,5 @@ swagger.json
29 swagger.yaml 29 swagger.yaml
30 *.log 30 *.log
31 lastupdate.tmp 31 lastupdate.tmp
  32 +allied-creation-manufacture
  33 +main_local.go
  1 +{
  2 + // 使用 IntelliSense 了解相关属性。
  3 + // 悬停以查看现有属性的描述。
  4 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
  5 + "version": "0.2.0",
  6 + "configurations": [
  7 + {
  8 + "name": "Launch file",
  9 + "type": "go",
  10 + "request": "launch",
  11 + "mode": "debug",
  12 + "program": "./main.go",
  13 + "buildFlags": "--tags=local"
  14 + }
  15 +
  16 + ]
  17 +}
1 # 生产制造项目说明 1 # 生产制造项目说明
2 2
  3 +- 开发环境服务器地址:http://allied-creation-manufacture-dev.fjmaimaimai.com
  4 +- 测试环境服务器地址: http://allied-creation-manufacture-test.fjmaimaimai.com
  5 +
  6 +- 前端调用的地址 http://allied-creation-gateway-dev.fjmaimaimai.com/v1/manufacture
  7 +- 前端调用的地址 http://allied-creation-gateway-test.fjmaimaimai.com/v1/manufacture
  8 +
3 ## 1.数据导入导出模块 9 ## 1.数据导入导出模块
4 10
5 -### 1.1.Excel导入流程 11 +### 1.1.Excel 导入流程
6 12
7 - 原型说明 13 - 原型说明
8 14
@@ -14,7 +20,6 @@ @@ -14,7 +20,6 @@
14 20
15 - [导入接口文档地址](https://doc-press.fjmaimaimai.com/team/frontend/plugins/business/import.html) 21 - [导入接口文档地址](https://doc-press.fjmaimaimai.com/team/frontend/plugins/business/import.html)
16 22
17 -  
18 ``` 23 ```
19 POST/v1/web/file-import 24 POST/v1/web/file-import
20 25
@@ -26,11 +31,10 @@ file 文件 @@ -26,11 +31,10 @@ file 文件
26 code 对应导入模块的编码 31 code 对应导入模块的编码
27 ``` 32 ```
28 33
29 -- ``对接步骤``以导入公司用户模块为例 34 +- `对接步骤`以导入公司用户模块为例
  35 +
  36 + 1.定义接口导入的`code`为`ADMIN_SYSTEM-MANAGE_BASE_USER` 2.根据接口解析导入文件的数据 3.调用基础库解析数据并传到后台
30 37
31 -1.定义接口导入的``code``为``ADMIN_SYSTEM-MANAGE_BASE_USER``  
32 -2.根据接口解析导入文件的数据  
33 -3.调用基础库解析数据并传到后台  
34 ```go 38 ```go
35 39
36 // 1.解析列 40 // 1.解析列
@@ -80,21 +84,23 @@ result, err := userGateway.UserBatchAdd(allied_creation_user.ReqBatchAddUser{ @@ -80,21 +84,23 @@ result, err := userGateway.UserBatchAdd(allied_creation_user.ReqBatchAddUser{
80 ``` 84 ```
81 85
82 ```go 86 ```go
  87 +
83 ``` 88 ```
84 89
85 -### 2.2 Excel导出流程 90 +### 2.2 Excel 导出流程
86 91
87 - 功能原型说明 92 - 功能原型说明
88 93
89 -实现可以自定义选择列进行导出,以及选择导出格式,导出格式有 ``xlsx``\\``csv``,功能如下图所示: 94 +实现可以自定义选择列进行导出,以及选择导出格式,导出格式有 `xlsx`\\`csv`,功能如下图所示:
90 95
91 ![](https://timeless-world.oss-cn-shenzhen.aliyuncs.com/opportunity/dev_online/20220225/object/1645789890_JbTa22EtANsD3fm2nJ4aH6FJkHzXaHJB.png) 96 ![](https://timeless-world.oss-cn-shenzhen.aliyuncs.com/opportunity/dev_online/20220225/object/1645789890_JbTa22EtANsD3fm2nJ4aH6FJkHzXaHJB.png)
92 97
93 - 前后端交互说明 98 - 前后端交互说明
94 99
95 -``接口定义`` 100 +`接口定义`
96 101
97 导出接口 102 导出接口
  103 +
98 ```shell 104 ```shell
99 POST /v1/web/file-export 105 POST /v1/web/file-export
100 106
@@ -130,9 +136,7 @@ GET/v1/web/file-export/fields/:code @@ -130,9 +136,7 @@ GET/v1/web/file-export/fields/:code
130 136
131 - 交互流程 137 - 交互流程
132 138
133 -1.前台根据 ``导出列查询接口`` 获取可以导出的列;  
134 -2.勾选需要导出的列、文件格式,调用 ``导出接口`` 向后台发起导出数据请求;  
135 - 139 + 1.前台根据 `导出列查询接口` 获取可以导出的列; 2.勾选需要导出的列、文件格式,调用 `导出接口` 向后台发起导出数据请求;
136 140
137 #### 2.2.1 后端导出实现 141 #### 2.2.1 后端导出实现
138 142
@@ -148,6 +152,7 @@ type ExcelMaker interface { @@ -148,6 +152,7 @@ type ExcelMaker interface {
148 ``` 152 ```
149 153
150 如下所示 154 如下所示
  155 +
151 ```go 156 ```go
152 //ExportCooperationUserData 导出共创用户数据 157 //ExportCooperationUserData 导出共创用户数据
153 type ExportCooperationUserData struct { 158 type ExportCooperationUserData struct {
@@ -2,7 +2,7 @@ apiVersion: v1 @@ -2,7 +2,7 @@ apiVersion: v1
2 kind: Service 2 kind: Service
3 metadata: 3 metadata:
4 name: allied-creation-manufacture 4 name: allied-creation-manufacture
5 - namespace: mmm-suplus-test 5 + namespace: mmm-suplus-dev
6 labels: 6 labels:
7 k8s-app: allied-creation-manufacture 7 k8s-app: allied-creation-manufacture
8 spec: 8 spec:
@@ -17,7 +17,7 @@ apiVersion: extensions/v1beta1 @@ -17,7 +17,7 @@ apiVersion: extensions/v1beta1
17 kind: Deployment 17 kind: Deployment
18 metadata: 18 metadata:
19 name: allied-creation-manufacture 19 name: allied-creation-manufacture
20 - namespace: mmm-suplus-test 20 + namespace: mmm-suplus-dev
21 labels: 21 labels:
22 k8s-app: allied-creation-manufacture 22 k8s-app: allied-creation-manufacture
23 spec: 23 spec:
@@ -97,29 +97,29 @@ spec: @@ -97,29 +97,29 @@ spec:
97 - name: HTTP_PORT 97 - name: HTTP_PORT
98 value: "8082" 98 value: "8082"
99 - name: SERVICE_ENV 99 - name: SERVICE_ENV
100 - value: "test" 100 + value: "dev"
101 - name: SUPLUS_ADMIN_BASE_HOST 101 - name: SUPLUS_ADMIN_BASE_HOST
102 value: "http://suplus-admin-base-dev.fjmaimaimai.com" 102 value: "http://suplus-admin-base-dev.fjmaimaimai.com"
103 - name: ALLIED_CREATION_GATEWAY_HOST 103 - name: ALLIED_CREATION_GATEWAY_HOST
104 - value: "https://allied-creation-gateway-test.fjmaimaimai.com" 104 + value: "http://allied-creation-gateway-dev.fjmaimaimai.com"
105 - name: ALLIED_CREATION_USER_HOST 105 - name: ALLIED_CREATION_USER_HOST
106 - value: "https://allied-creation-user-test.fjmaimaimai.com" 106 + value: "http://allied-creation-user-dev.fjmaimaimai.com"
107 - name: ALLIED_CREATION_COOPERATION_HOST 107 - name: ALLIED_CREATION_COOPERATION_HOST
108 - value: "https://allied-creation-cooperation-test.fjmaimaimai.com" 108 + value: "http://allied-creation-cooperation-dev.fjmaimaimai.com"
109 - name: ALLIED_CREATION_BASIC_HOST 109 - name: ALLIED_CREATION_BASIC_HOST
110 - value: "https://allied-creation-basic-test.fjmaimaimai.com" 110 + value: "http://allied-creation-basic-dev.fjmaimaimai.com"
111 - name: ALLIED_CREATION_MANUFACTURE_HOST 111 - name: ALLIED_CREATION_MANUFACTURE_HOST
112 - value: "http://allied-creation-manufacture-test.fjmaimaimai.com" 112 + value: "http://allied-creation-manufacture-dev.fjmaimaimai.com"
113 - name: SMS_SERVE_HOST 113 - name: SMS_SERVE_HOST
114 value: "https://sms.fjmaimaimai.com:9897" 114 value: "https://sms.fjmaimaimai.com:9897"
115 - name: SUPLUS_SALE_APP 115 - name: SUPLUS_SALE_APP
116 - value: "http://suplus-sale-app-gateway-test.fjmaimaimai.com" 116 + value: "http://suplus-sale-app-gateway-dev.fjmaimaimai.com"
117 - name: MANUFACTURE_DEFAULT_COMPANYID 117 - name: MANUFACTURE_DEFAULT_COMPANYID
118 - value: "23" 118 + value: "1"
119 - name: MANUFACTURE_DEFAULT_ORGID 119 - name: MANUFACTURE_DEFAULT_ORGID
120 - value: "487" 120 + value: "1"
121 - name: MANUFACTURE_DEFAULT_WORKSHOPID 121 - name: MANUFACTURE_DEFAULT_WORKSHOPID
122 - value: "28" 122 + value: "2"
123 - name: MANUFACTURE_PRODUCT_TYPE 123 - name: MANUFACTURE_PRODUCT_TYPE
124 value: "SG,SG" 124 value: "SG,SG"
125 - name: MQTT_HOST 125 - name: MQTT_HOST
1 #!/bin/bash 1 #!/bin/bash
2 export PATH=/root/local/bin:$PATH 2 export PATH=/root/local/bin:$PATH
3 -kubectl -n <replace-your-k8s-namespace> get pods | grep -q project 3 +kubectl -n mmm-suplus-dev get pods | grep -q allied-creation-manufacture
4 if [ "$?" == "1" ];then 4 if [ "$?" == "1" ];then
5 - kubectl create -f /tmp/dev/project/project.yaml --record  
6 - kubectl -n <replace-your-k8s-namespace> get svc | grep -q project 5 + kubectl create -f /tmp/dev/allied-creation-manufacture/allied-creation-manufacture.yaml --record
  6 + kubectl -n mmm-suplus-dev get svc | grep -q allied-creation-manufacture
7 if [ "$?" == "0" ];then 7 if [ "$?" == "0" ];then
8 - echo "project service install success!" 8 + echo "allied-creation-manufacture service install success!"
9 else 9 else
10 - echo "project service install fail!" 10 + echo "allied-creation-manufacture service install fail!"
11 fi 11 fi
12 - kubectl -n <replace-your-k8s-namespace> get pods | grep -q project 12 + kubectl -n mmm-suplus-dev get pods | grep -q allied-creation-manufacture
13 if [ "$?" == "0" ];then 13 if [ "$?" == "0" ];then
14 - echo "project deployment install success!" 14 + echo "allied-creation-manufacture deployment install success!"
15 else 15 else
16 - echo "project deployment install fail!" 16 + echo "allied-creation-manufacture deployment install fail!"
17 fi 17 fi
18 else 18 else
19 - kubectl delete -f /tmp/dev/project/project.yaml  
20 - kubectl -n <replace-your-k8s-namespace> get svc | grep -q project 19 + kubectl delete -f /tmp/dev/allied-creation-manufacture/allied-creation-manufacture.yaml
  20 + kubectl -n mmm-suplus-dev get svc | grep -q allied-creation-manufacture
21 while [ "$?" == "0" ] 21 while [ "$?" == "0" ]
22 do 22 do
23 - kubectl -n <replace-your-k8s-namespace> get svc | grep -q project 23 + kubectl -n mmm-suplus-dev get svc | grep -q allied-creation-manufacture
24 done 24 done
25 - kubectl -n <replace-your-k8s-namespace> get pods | grep -q project 25 + kubectl -n mmm-suplus-dev get pods | grep -q allied-creation-manufacture
26 while [ "$?" == "0" ] 26 while [ "$?" == "0" ]
27 do 27 do
28 - kubectl -n <replace-your-k8s-namespace> get pods | grep -q project 28 + kubectl -n mmm-suplus-dev get pods | grep -q allied-creation-manufacture
29 done 29 done
30 - kubectl create -f /tmp/dev/project/project.yaml --record  
31 - kubectl -n <replace-your-k8s-namespace> get svc | grep -q project 30 + kubectl create -f /tmp/dev/allied-creation-manufacture/allied-creation-manufacture.yaml --record
  31 + kubectl -n mmm-suplus-dev get svc | grep -q allied-creation-manufacture
32 if [ "$?" == "0" ];then 32 if [ "$?" == "0" ];then
33 - echo "project service update success!" 33 + echo "allied-creation-manufacture service update success!"
34 else 34 else
35 - echo "project service update fail!" 35 + echo "allied-creation-manufacture service update fail!"
36 fi 36 fi
37 - kubectl -n <replace-your-k8s-namespace> get pods | grep -q project 37 + kubectl -n mmm-suplus-dev get pods | grep -q allied-creation-manufacture
38 if [ "$?" == "0" ];then 38 if [ "$?" == "0" ];then
39 - echo "project deployment update success!" 39 + echo "allied-creation-manufacture deployment update success!"
40 else 40 else
41 - echo "project deployment update fail!" 41 + echo "allied-creation-manufacture deployment update fail!"
42 fi 42 fi
43 fi 43 fi
  1 +//go:build !local
  2 +// +build !local
  3 +
1 package main 4 package main
2 5
3 import ( 6 import (
4 "fmt" 7 "fmt"
  8 + "time"
  9 +
5 "github.com/beego/beego/v2/server/web" 10 "github.com/beego/beego/v2/server/web"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/crontab" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/crontab"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
@@ -9,7 +14,6 @@ import ( @@ -9,7 +14,6 @@ import (
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" 14 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/mqtt" 15 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/mqtt"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/task" 16 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/task"
12 - "time"  
13 17
14 _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" 18 _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
15 _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg" 19 _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
1 package dto 1 package dto
2 2
3 import ( 3 import (
  4 + "time"
  5 +
4 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
6 - "time"  
7 ) 8 )
8 9
9 type AttendanceRecordDto struct { 10 type AttendanceRecordDto struct {
@@ -63,7 +64,9 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i @@ -63,7 +64,9 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i
63 d.WorkTimeAfter = m.WorkTimeAfter 64 d.WorkTimeAfter = m.WorkTimeAfter
64 d.AttendanceStatus = m.AttendanceStatus 65 d.AttendanceStatus = m.AttendanceStatus
65 d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId) 66 d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
  67 + if m.Ext != nil {
66 d.OrgName = m.Ext.OrgName 68 d.OrgName = m.Ext.OrgName
  69 + }
67 d.ApproveUser = m.ApproveUser() 70 d.ApproveUser = m.ApproveUser()
68 d.GroupName = m.GroupName() 71 d.GroupName = m.GroupName()
69 if m.Ext != nil && m.Ext.AttendanceExt != nil { 72 if m.Ext != nil && m.Ext.AttendanceExt != nil {
@@ -2,6 +2,8 @@ package service @@ -2,6 +2,8 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "time"
  6 +
5 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
6 "github.com/linmadan/egglib-go/transaction/pg" 8 "github.com/linmadan/egglib-go/transaction/pg"
7 "github.com/linmadan/egglib-go/utils/xtime" 9 "github.com/linmadan/egglib-go/utils/xtime"
@@ -13,12 +15,16 @@ import ( @@ -13,12 +15,16 @@ import (
13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao" 15 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
14 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" 16 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
15 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" 17 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
16 - "time"  
17 ) 18 )
18 19
19 type AttendanceService struct { 20 type AttendanceService struct {
20 } 21 }
21 22
  23 +func NewAttendanceService(options map[string]interface{}) *AttendanceService {
  24 + newAttendanceService := &AttendanceService{}
  25 + return newAttendanceService
  26 +}
  27 +
22 // 审核工时 28 // 审核工时
23 func (attendanceService *AttendanceService) ApproveAttendance(cmd *command.ApproveAttendanceCommand) (interface{}, error) { 29 func (attendanceService *AttendanceService) ApproveAttendance(cmd *command.ApproveAttendanceCommand) (interface{}, error) {
24 if err := cmd.ValidateCommand(); err != nil { 30 if err := cmd.ValidateCommand(); err != nil {
@@ -426,8 +432,3 @@ func (attendanceService *AttendanceService) SearchWorkshopWorkTimeStatics(operat @@ -426,8 +432,3 @@ func (attendanceService *AttendanceService) SearchWorkshopWorkTimeStatics(operat
426 } 432 }
427 return count, result, nil 433 return count, result, nil
428 } 434 }
429 -  
430 -func NewAttendanceService(options map[string]interface{}) *AttendanceService {  
431 - newAttendanceService := &AttendanceService{}  
432 - return newAttendanceService  
433 -}  
@@ -2,9 +2,10 @@ package service @@ -2,9 +2,10 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "strings"
  6 +
5 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/ecelData/command" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/ecelData/command"
7 - "strings"  
8 9
9 "github.com/linmadan/egglib-go/utils/excel" 10 "github.com/linmadan/egglib-go/utils/excel"
10 ) 11 )
@@ -51,7 +52,7 @@ func (srv ExcelDataService) fieldValueAllEmpty(param map[string]string) bool { @@ -51,7 +52,7 @@ func (srv ExcelDataService) fieldValueAllEmpty(param map[string]string) bool {
51 return isAllEmpty 52 return isAllEmpty
52 } 53 }
53 54
54 -//// FileImportTemplate 导入模板 55 +// // FileImportTemplate 导入模板
55 func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.ImportDataCommand) (interface{}, error) { 56 func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.ImportDataCommand) (interface{}, error) {
56 var mapTemplate = map[string]string{ 57 var mapTemplate = map[string]string{
57 //domain.ImportCompanyUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807485_EaxECeRz23WpzrMZmbwdEPRJ3Pdxpx5X.xlsx", 58 //domain.ImportCompanyUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807485_EaxECeRz23WpzrMZmbwdEPRJ3Pdxpx5X.xlsx",
@@ -59,6 +60,12 @@ func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.Import @@ -59,6 +60,12 @@ func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.Import
59 //domain.ImportDividendsOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210927/object/1632743206_NPYTKw6RGhXn4TpYNEQhGGdCkXKXTnxM.xlsx", 60 //domain.ImportDividendsOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210927/object/1632743206_NPYTKw6RGhXn4TpYNEQhGGdCkXKXTnxM.xlsx",
60 //domain.ImportCooperationUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210926/object/1632635345_SbfzmkXjQHhCwPw4MB7zb5EBBtdp2MSE.xlsx", 61 //domain.ImportCooperationUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210926/object/1632635345_SbfzmkXjQHhCwPw4MB7zb5EBBtdp2MSE.xlsx",
61 //domain.ImportDividendsReturnOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210927/object/1632743214_rNHm6ZBXZaC5xKTrsE7M4h45MY6n6Ff3.xlsx", 62 //domain.ImportDividendsReturnOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210927/object/1632743214_rNHm6ZBXZaC5xKTrsE7M4h45MY6n6Ff3.xlsx",
  63 + //二级品审核导入
  64 + //"ImportProductRecordLevel2": "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20221030/object/1667144411_R3h4nQxxcMJ7ympktMsYBBQ6bAcFC6xj.xlsx",
  65 + //工时管理导入
  66 + //"ImportAttendance": "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20221030/object/1667144523_w66QpzZTfxsmhbM5mmBrHjpytcydMNs2.xlsx",
  67 + //事故管理导入
  68 + // "ImportProductTrouble": "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20221030/object/1667144570_xYKYMrMnXWTyasDPnX2JNXEZHd3rJsWG.xlsx",
62 } 69 }
63 var url string 70 var url string
64 var ok bool 71 var ok bool
  1 +package service
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "strconv"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/linmadan/egglib-go/core/application"
  11 + "github.com/linmadan/egglib-go/utils/excel"
  12 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/ecelData/command"
  13 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  14 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  15 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
  16 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils/converter"
  17 +)
  18 +
  19 +type importAttendance struct {
  20 + ProductDate string `json:"productDate"` //日期
  21 + WorkshopName string `json:"workshopName"` //车间名称
  22 + LineName string `json:"lineName"` //线别名称
  23 + SectionName string `json:"sectionName"` //工位名称
  24 + WorkerName string `json:"workerName"` //工人姓名
  25 + AttendanceType string `json:"attendanceType"` //考勤类型 正常 支援
  26 + SignIn string `json:"signIn"` //上岗时间
  27 + SignOut string `json:"signOut"` //离岗时间
  28 + BreakTime string `json:"breakTime"` //休息时间
  29 + FailReason string `json:"failReason"` //数据校验失败的理由
  30 +}
  31 +
  32 +func (data *importAttendance) validField() error {
  33 + if len(data.ProductDate) == 0 {
  34 + return errors.New("日期未填写。")
  35 + }
  36 + if len(data.WorkerName) == 0 {
  37 + return errors.New("车间名称未填写。")
  38 + }
  39 + if len(data.LineName) == 0 {
  40 + return errors.New("线别名称未填写。")
  41 + }
  42 + if len(data.SectionName) == 0 {
  43 + return errors.New("工位名称未填写。")
  44 + }
  45 + if len(data.WorkerName) == 0 {
  46 + return errors.New("工人姓名未填写。")
  47 + }
  48 + if len(data.AttendanceType) == 0 {
  49 + return errors.New("类型未填写。")
  50 + }
  51 + if len(data.SignIn) == 0 {
  52 + return errors.New("上岗时间未填写。")
  53 + }
  54 + if len(data.SignOut) == 0 {
  55 + return errors.New("下岗时间未填写。")
  56 + }
  57 + if len(data.BreakTime) == 0 {
  58 + return errors.New("休息时间未填写。")
  59 + }
  60 +
  61 + return nil
  62 +}
  63 +
  64 +// 导入生产计划
  65 +func (srv ExcelDataService) ImportDataAttendance(importDataCommand *command.ImportDataCommand) (interface{}, error) {
  66 + excelImport := excel.NewExcelImport()
  67 + excelImport.RowBegin = 3 //第二行开始读取
  68 + excelImport.DataFields = []excel.DataField{
  69 + {EnName: "productDate", CnName: "日期"},
  70 + {EnName: "workshopName", CnName: "车间"},
  71 + {EnName: "lineName", CnName: "线别"},
  72 + {EnName: "sectionName", CnName: "工段"},
  73 + {EnName: "workerName", CnName: "姓名"},
  74 + {EnName: "attendanceType", CnName: "类型"},
  75 + {EnName: "signIn", CnName: "上岗时间"},
  76 + {EnName: "signOut", CnName: "离岗时间"},
  77 + {EnName: "breakTime", CnName: "休息时长(小时)"},
  78 + }
  79 + excelData, err := converter.OpenImportFileFromIoReader(excelImport, importDataCommand.Reader, importDataCommand.FileExt) //excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
  80 + if err != nil {
  81 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  82 + }
  83 + items := make([]importAttendance, 0)
  84 + for _, v := range excelData {
  85 + item := importAttendance{
  86 + ProductDate: strings.TrimSpace(v["productDate"]),
  87 + WorkshopName: strings.TrimSpace(v["workshopName"]),
  88 + LineName: strings.TrimSpace(v["lineName"]),
  89 + SectionName: strings.TrimSpace(v["sectionName"]),
  90 + WorkerName: strings.TrimSpace(v["workerName"]),
  91 + AttendanceType: strings.TrimSpace(v["attendanceType"]),
  92 + SignIn: strings.TrimSpace(v["signIn"]),
  93 + SignOut: strings.TrimSpace(v["signOut"]),
  94 + BreakTime: strings.TrimSpace(v["breakTime"]),
  95 + FailReason: "",
  96 + }
  97 + items = append(items, item)
  98 + }
  99 + failRows, err := srv.BatchAddAttendance(*importDataCommand.Operator, items)
  100 + if err != nil {
  101 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  102 + }
  103 + return srv.importResultWithHeader(excelImport.DataFields, failRows, len(items)), nil
  104 +}
  105 +
  106 +// BatchAddAttendance 工时管理,导入工时数据
  107 +func (srv ExcelDataService) BatchAddAttendance(operate domain.OperateInfo, param []importAttendance) (
  108 + failRows []interface{}, err error) {
  109 + transactionContext, err := factory.CreateTransactionContext(nil)
  110 + if err != nil {
  111 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  112 + }
  113 + if err := transactionContext.StartTransaction(); err != nil {
  114 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  115 + }
  116 + defer func() {
  117 + transactionContext.RollbackTransaction()
  118 + }()
  119 + //获取当前操作人
  120 + userSrv := domainService.NewUserService()
  121 + // operateUser, err := userSrv.User(operate.UserId)
  122 + // if err != nil {
  123 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, "查询操作人数据失败。"+err.Error())
  124 + // }
  125 + //获取当前操作人的组织
  126 + var org *domain.Org
  127 + org, err = userSrv.Organization(operate.OrgId)
  128 + if err != nil {
  129 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  130 + }
  131 +
  132 + //车间数据
  133 + //生产班组 数据
  134 + productGroupRepo, _ := factory.CreateProductGroupRepository(map[string]interface{}{
  135 + "transactionContext": transactionContext,
  136 + })
  137 +
  138 + _, productGroupList, err := productGroupRepo.Find(map[string]interface{}{
  139 + "companyId": operate.CompanyId,
  140 + "orgId": operate.OrgId,
  141 + })
  142 + if err != nil {
  143 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  144 + }
  145 +
  146 + //车间数据
  147 + workshopRepo, _ := factory.CreateWorkshopRepository(map[string]interface{}{
  148 + "transactionContext": transactionContext,
  149 + })
  150 +
  151 + //获取车间列表
  152 + _, workshopList, err := workshopRepo.Find(map[string]interface{}{
  153 + "companyId": operate.CompanyId,
  154 + "orgId": operate.OrgId,
  155 + })
  156 + if err != nil {
  157 + return nil, application.ThrowError(application.BUSINESS_ERROR, "获取车间列表失败"+err.Error())
  158 + }
  159 + //车间名称+/+工人名 作为键名
  160 + workerMap := map[string][]*domain.User{}
  161 + for _, v := range productGroupList {
  162 + for _, vv := range v.GroupMembers {
  163 + k := v.WorkStation.WorkshopName + "/" + vv.UserName
  164 + isIn := false
  165 + for _, vvv := range workerMap[k] {
  166 + if vvv.UserId == vv.UserId {
  167 + isIn = true
  168 + break
  169 + }
  170 + }
  171 + if !isIn {
  172 + workerMap[k] = append(workerMap[k], vv)
  173 + }
  174 + }
  175 + }
  176 +
  177 + //车间名称+/+线别名称+/+工段名称 作为键名
  178 + workStationMap := map[string]*domain.WorkStation{}
  179 + for _, v := range workshopList {
  180 + for _, v2 := range v.ProductLines {
  181 + for _, v3 := range v2.ProductSections {
  182 + workStationName := strings.Join([]string{
  183 + v.WorkshopName, v2.LineName, v3.SectionName,
  184 + }, "/")
  185 + workStationMap[workStationName] = domain.NewWorkStation(v, v2, v3)
  186 + }
  187 + }
  188 + }
  189 + var attendanceList []*domain.ProductAttendanceRecord
  190 + nowTime := time.Now()
  191 + //检查导入的数据
  192 + for i := range param {
  193 + //检查字段值
  194 + err := param[i].validField()
  195 + if err != nil {
  196 + param[i].FailReason = err.Error()
  197 + failRows = append(failRows, param[i])
  198 + continue
  199 + }
  200 + //检查日期格式
  201 + productDate, err := time.ParseInLocation("2006-01-02", param[i].ProductDate, time.Local)
  202 + if err != nil {
  203 + param[i].FailReason = "日期格式错误,例 2006-01-02。"
  204 + failRows = append(failRows, param[i])
  205 + continue
  206 + }
  207 + //检查类型
  208 + attendanceType := 0
  209 + // 考勤类型 1.正常 2.支援
  210 + if param[i].AttendanceType == "支援" {
  211 + attendanceType = 1
  212 + } else if param[i].AttendanceType == "正常" {
  213 + attendanceType = 2
  214 + } else {
  215 + param[i].FailReason = "类型内容异常。"
  216 + failRows = append(failRows, param[i])
  217 + continue
  218 + }
  219 + //检查上岗时间格式
  220 + signInStr := fmt.Sprintf("%s %s", param[i].ProductDate, param[i].SignIn)
  221 + signIn, err := time.ParseInLocation("2006-01-02 15:04:05", signInStr, time.Local)
  222 + if err != nil {
  223 + param[i].FailReason = "上岗时间格式错误,例 15:04:05。"
  224 + failRows = append(failRows, param[i])
  225 + continue
  226 + }
  227 +
  228 + //检查离岗时间格式
  229 + signOutStr := fmt.Sprintf("%s %s", param[i].ProductDate, param[i].SignOut)
  230 + signOut, err := time.ParseInLocation("2006-01-02 15:04:05", signOutStr, time.Local)
  231 + if err != nil {
  232 + param[i].FailReason = "离岗时间格式错误,例 15:04:05。"
  233 + failRows = append(failRows, param[i])
  234 + continue
  235 + }
  236 + //检查员工姓名
  237 + var worker *domain.User
  238 + workKey := param[i].WorkshopName + "/" + param[i].WorkerName
  239 + if u, ok := workerMap[workKey]; ok {
  240 + if len(u) > 1 {
  241 + param[i].FailReason = "当前车间存在重复的用户名"
  242 + failRows = append(failRows, param[i])
  243 + continue
  244 + }
  245 + worker = u[0]
  246 + } else {
  247 + param[i].FailReason = "当前车间不存在用户" + param[i].WorkerName
  248 + failRows = append(failRows, param[i])
  249 + continue
  250 + }
  251 + //检查工位
  252 + var workStation *domain.WorkStation
  253 + workStationName := param[i].WorkshopName + "/" + param[i].LineName + "/" + param[i].SectionName
  254 + if v, ok := workStationMap[workStationName]; ok {
  255 + workStation = v
  256 + } else {
  257 + param[i].FailReason = "车间、线别、工段不存在"
  258 + failRows = append(failRows, param[i])
  259 + continue
  260 + }
  261 + //休息时间(小时)
  262 + beakTime, err := strconv.ParseFloat(param[i].BreakTime, 64)
  263 + if err != nil {
  264 + param[i].FailReason = "休息时长填写错误"
  265 + failRows = append(failRows, param[i])
  266 + continue
  267 + }
  268 +
  269 + tempItem := &domain.ProductAttendanceRecord{
  270 + ProductAttendanceId: 0,
  271 + CompanyId: operate.CompanyId,
  272 + OrgId: operate.OrgId,
  273 + AttendanceType: attendanceType,
  274 + ProductWorker: worker,
  275 + WorkStation: workStation,
  276 + SignIn: signIn,
  277 + SignOut: signOut,
  278 + AttendanceStatus: domain.AttendanceAutoApproved, //自动审核
  279 + WorkTimeBefore: 0.0,
  280 + WorkTimeAfter: 0.0,
  281 + CreatedAt: nowTime,
  282 + UpdatedAt: nowTime,
  283 + DeletedAt: time.Time{},
  284 + ProductDate: productDate,
  285 + Ext: &domain.Ext{
  286 + OrgName: org.OrgName,
  287 + DeviceExt: &domain.DeviceExt{},
  288 + ProductPlanExt: &domain.ProductPlanExt{},
  289 + AttendanceExt: &domain.ProductAttendanceRecordExt{},
  290 + },
  291 + }
  292 + //计算工时
  293 + workTime := tempItem.ComputeWorkTime(beakTime)
  294 + tempItem.WorkTimeAfter = workTime
  295 + tempItem.WorkTimeBefore = workTime
  296 + attendanceList = append(attendanceList, tempItem)
  297 + }
  298 + if len(failRows) > 0 {
  299 + return failRows, nil
  300 + }
  301 + attendanceRepo, _ := factory.CreateProductAttendanceRecordRepository(map[string]interface{}{
  302 + "transactionContext": transactionContext,
  303 + })
  304 + for i := range attendanceList {
  305 + _, err = attendanceRepo.Save(attendanceList[i])
  306 + if err != nil {
  307 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  308 + }
  309 + }
  310 + if err := transactionContext.CommitTransaction(); err != nil {
  311 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  312 + }
  313 + return nil, nil
  314 +}
  1 +package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "github.com/linmadan/egglib-go/utils/excel"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/ecelData/command"
  7 + productRecordCommand "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/command"
  8 + productRecordService "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/service"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils/converter"
  10 +)
  11 +
  12 +// ImportProductCapacities 导入产能数据
  13 +func (srv ExcelDataService) ImportProductCapacities(importDataCommand *command.ImportDataCommand) (interface{}, error) {
  14 + excelImport := excel.NewExcelImport()
  15 + excelImport.RowBegin = 3 //第二行开始读取
  16 + excelImport.DataFields = []excel.DataField{
  17 + {EnName: "recordDate", CnName: "日期"},
  18 + {EnName: "workshopName", CnName: "车间"},
  19 + {EnName: "lineName", CnName: "线别"},
  20 + {EnName: "sectionName", CnName: "工段"},
  21 + {EnName: "workOn", CnName: "班别"},
  22 + {EnName: "workerName", CnName: "姓名"},
  23 + {EnName: "batchNumber", CnName: "批次号"},
  24 + {EnName: "weigh", CnName: "产量(kg)"},
  25 + }
  26 + excelData, err := converter.OpenImportFileFromIoReader(excelImport, importDataCommand.Reader, importDataCommand.FileExt) //excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
  27 + if err != nil {
  28 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  29 + }
  30 + items := make([]productRecordCommand.BatchAddProductCapacitiesCmd, 0, len(excelData))
  31 + item := productRecordCommand.BatchAddProductCapacitiesCmd{}
  32 + for _, v := range excelData {
  33 + item = productRecordCommand.BatchAddProductCapacitiesCmd{
  34 + RecordDate: v["recordDate"],
  35 + WorkshopName: v["workshopName"],
  36 + LineName: v["lineName"],
  37 + SectionName: v["sectionName"],
  38 + WorkerName: v["workerName"],
  39 + BatchNumber: v["batchNumber"],
  40 + WorkOn: v["workOn"],
  41 + Weigh: v["weigh"],
  42 + FailReason: "",
  43 + }
  44 + items = append(items, item)
  45 + }
  46 +
  47 + svr := productRecordService.NewProductRecordService(nil)
  48 + failRows, err := svr.BatchAddProductCapacities(importDataCommand.Operator, items)
  49 + if err != nil {
  50 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  51 + }
  52 + return srv.importResultWithHeader(excelImport.DataFields, failRows, len(items)), nil
  53 +}
  1 +package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "github.com/linmadan/egglib-go/utils/excel"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/ecelData/command"
  7 + productRecordCommand "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/command"
  8 + productRecordService "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/service"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils/converter"
  10 +)
  11 +
  12 +// ImportProductRecord 导入二级品生产记录
  13 +func (srv ExcelDataService) ImportProductRecord(importDataCommand *command.ImportDataCommand) (interface{}, error) {
  14 + excelImport := excel.NewExcelImport()
  15 + excelImport.RowBegin = 3 //第二行开始读取
  16 + excelImport.DataFields = []excel.DataField{
  17 + {EnName: "createdDate", CnName: "日期"},
  18 + {EnName: "workshopName", CnName: "车间"},
  19 + {EnName: "lineName", CnName: "线别"},
  20 + {EnName: "sectionName", CnName: "工段"},
  21 + {EnName: "workerName", CnName: "姓名"},
  22 + {EnName: "batchNumber", CnName: "批次号"},
  23 + {EnName: "weigh", CnName: "二级品重量"},
  24 + }
  25 + excelData, err := converter.OpenImportFileFromIoReader(excelImport, importDataCommand.Reader, importDataCommand.FileExt) //excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
  26 + if err != nil {
  27 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  28 + }
  29 + items := make([]productRecordCommand.BatchAddProductRecordCommand, 0, len(excelData))
  30 + item := productRecordCommand.BatchAddProductRecordCommand{}
  31 + for _, v := range excelData {
  32 + item = productRecordCommand.BatchAddProductRecordCommand{
  33 + CreatedDate: v["createdDate"],
  34 + WorkshopName: v["workshopName"],
  35 + LineName: v["lineName"],
  36 + SectionName: v["sectionName"],
  37 + WorkerName: v["workerName"],
  38 + BatchNumber: v["batchNumber"],
  39 + Weigh: v["weigh"],
  40 + FailReason: "",
  41 + }
  42 + items = append(items, item)
  43 + }
  44 +
  45 + svr := productRecordService.NewProductRecordService(nil)
  46 + failRows, err := svr.BatchAddProductRecord(importDataCommand.Operator, items)
  47 + if err != nil {
  48 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  49 + }
  50 + return srv.importResultWithHeader(excelImport.DataFields, failRows, len(items)), nil
  51 +}
  1 +package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "github.com/linmadan/egglib-go/utils/excel"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/ecelData/command"
  7 + productTroubleCommand "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productTrouble/command"
  8 + productTroubleService "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productTrouble/service"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils/converter"
  10 +)
  11 +
  12 +// ImportProductTrouble 导入事故记录
  13 +func (srv ExcelDataService) ImportProductTrouble(importDataCommand *command.ImportDataCommand) (interface{}, error) {
  14 + excelImport := excel.NewExcelImport()
  15 + excelImport.RowBegin = 3 //第二行开始读取
  16 + excelImport.DataFields = []excel.DataField{
  17 + {EnName: "recordDate", CnName: "日期"},
  18 + {EnName: "workshopName", CnName: "车间"},
  19 + {EnName: "lineName", CnName: "线别"},
  20 + {EnName: "sectionName", CnName: "工段"},
  21 + {EnName: "workerName", CnName: "姓名"},
  22 + {EnName: "typesName", CnName: "事故类型"},
  23 + {EnName: "amountLoss", CnName: "损失金额"},
  24 + }
  25 + excelData, err := converter.OpenImportFileFromIoReader(excelImport, importDataCommand.Reader, importDataCommand.FileExt) //excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
  26 + if err != nil {
  27 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  28 + }
  29 + items := make([]productTroubleCommand.BatchAddProductTroubleCommand, 0, len(excelData))
  30 + item := productTroubleCommand.BatchAddProductTroubleCommand{}
  31 + for _, v := range excelData {
  32 + item = productTroubleCommand.BatchAddProductTroubleCommand{
  33 + RecordDate: v["recordDate"],
  34 + WorkshopName: v["workshopName"],
  35 + LineName: v["lineName"],
  36 + SectionName: v["sectionName"],
  37 + WorkerName: v["workerName"],
  38 + AmountLoss: v["amountLoss"],
  39 + TypesName: v["typesName"],
  40 + FailReason: "",
  41 + }
  42 + items = append(items, item)
  43 + }
  44 + svr := productTroubleService.NewProductTroubleService(nil)
  45 + failRows, err := svr.BatchAddProductTrouble(importDataCommand.Operator, items)
  46 + if err != nil {
  47 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  48 + }
  49 + return srv.importResultWithHeader(excelImport.DataFields, failRows, len(items)), nil
  50 +}
@@ -157,3 +157,35 @@ func CreateProductMaterialRepository(options map[string]interface{}) (domain.Pro @@ -157,3 +157,35 @@ func CreateProductMaterialRepository(options map[string]interface{}) (domain.Pro
157 } 157 }
158 return repository.NewProductMaterialRepository(transactionContext) 158 return repository.NewProductMaterialRepository(transactionContext)
159 } 159 }
  160 +
  161 +func CreateRewardStandardRepository(options map[string]interface{}) (domain.RewardStandardRepository, error) {
  162 + var transactionContext *pg.TransactionContext
  163 + if value, ok := options["transactionContext"]; ok {
  164 + transactionContext = value.(*pg.TransactionContext)
  165 + }
  166 + return repository.NewRewardStandardRepository(transactionContext)
  167 +}
  168 +
  169 +func CreateRewardRuleRepository(options map[string]interface{}) (domain.RewardRuleRepository, error) {
  170 + var transactionContext *pg.TransactionContext
  171 + if value, ok := options["transactionContext"]; ok {
  172 + transactionContext = value.(*pg.TransactionContext)
  173 + }
  174 + return repository.NewRewardRuleRepository(transactionContext)
  175 +}
  176 +
  177 +func CreateProductTroubleRepository(options map[string]interface{}) (domain.ProductTroubleRepository, error) {
  178 + var transactionContext *pg.TransactionContext
  179 + if value, ok := options["transactionContext"]; ok {
  180 + transactionContext = value.(*pg.TransactionContext)
  181 + }
  182 + return repository.NewProductTroubleRepository(transactionContext)
  183 +}
  184 +
  185 +func CreateRewardSummaryRepository(options map[string]interface{}) (domain.RewardSummaryRepository, error) {
  186 + var transactionContext *pg.TransactionContext
  187 + if value, ok := options["transactionContext"]; ok {
  188 + transactionContext = value.(*pg.TransactionContext)
  189 + }
  190 + return repository.NewRewardSummaryRepository(transactionContext)
  191 +}
  1 +package command
  2 +
  3 +import "errors"
  4 +
  5 +type BatchAddProductCapacitiesCmd struct {
  6 + WorkshopName string `json:"workshopName"` //车间
  7 + LineName string `json:"lineName"` //生产线
  8 + SectionName string `json:"sectionName"` //工段
  9 + WorkerName string `json:"workerName"` //员工
  10 + Weigh string `json:"weigh"` //产量重量
  11 + BatchNumber string `json:"batchNumber"` //计划 批次号
  12 + RecordDate string `json:"recordDate"` //日期 2006-01-02
  13 + WorkOn string `json:"workOn"` //上班班次 1:全天 2:白班 4:中班 8:夜班
  14 + FailReason string `json:"failReason"`
  15 +}
  16 +
  17 +func (data *BatchAddProductCapacitiesCmd) ValidField() error {
  18 + if len(data.RecordDate) == 0 {
  19 + return errors.New("日期未填写")
  20 + }
  21 + if len(data.WorkshopName) == 0 {
  22 + return errors.New("车间未填写")
  23 + }
  24 + if len(data.LineName) == 0 {
  25 + return errors.New("生产线未填写")
  26 + }
  27 + if len(data.SectionName) == 0 {
  28 + return errors.New("工段未填写")
  29 + }
  30 + if len(data.WorkerName) == 0 {
  31 + return errors.New("姓名未填写")
  32 + }
  33 + if len(data.BatchNumber) == 0 {
  34 + return errors.New("批次未填写")
  35 + }
  36 + if len(data.Weigh) == 0 {
  37 + return errors.New("重量未填写")
  38 + }
  39 + if len(data.WorkOn) == 0 {
  40 + return errors.New("上班班次未填写")
  41 + }
  42 + return nil
  43 +}
  1 +package command
  2 +
  3 +import "errors"
  4 +
  5 +// 批量添加生产记录,二级品
  6 +type BatchAddProductRecordCommand struct {
  7 + CreatedDate string `json:"createdDate"` // 日期
  8 + WorkshopName string `json:"workshopName"` // 车间
  9 + LineName string `json:"lineName"` // 生产线
  10 + SectionName string `json:"sectionName"` // 工段
  11 + WorkerName string `json:"workerName"` // 工人名称
  12 + BatchNumber string `json:"batchNumber"` // 批次
  13 + Weigh string `json:"weigh"` // 重量
  14 + FailReason string `json:"failReason"` // 数据检查失败的原因
  15 +}
  16 +
  17 +func (cmd *BatchAddProductRecordCommand) ValidField() error {
  18 + if len(cmd.CreatedDate) == 0 {
  19 + return errors.New("日期未填写")
  20 + }
  21 + if len(cmd.WorkshopName) == 0 {
  22 + return errors.New("车间未填写")
  23 + }
  24 + if len(cmd.LineName) == 0 {
  25 + return errors.New("生产线未填写")
  26 + }
  27 + if len(cmd.SectionName) == 0 {
  28 + return errors.New("工段未填写")
  29 + }
  30 + if len(cmd.WorkerName) == 0 {
  31 + return errors.New("姓名未填写")
  32 + }
  33 + if len(cmd.BatchNumber) == 0 {
  34 + return errors.New("批次号未填写")
  35 + }
  36 + if len(cmd.Weigh) == 0 {
  37 + return errors.New("重量未填写")
  38 + }
  39 + return nil
  40 +}
  1 +package command
  2 +
  3 +type CreateProductCapacitiesCmd struct {
  4 + // 车间ID
  5 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  6 + // 生产线ID
  7 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  8 + // 工段ID
  9 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  10 + //员工
  11 + WorkerId []int `cname:"工人ID" json:"workerId" valid:"Required"`
  12 + //产量重量
  13 + Weigh float64 `cname:"重量" json:"weigh" valid:"Required" `
  14 + //计划id
  15 + ProductPlanId int `json:"productPlanId"`
  16 + //日期
  17 + RecordDate string `json:"recordDate"`
  18 + //上班班次 1:全天 2:白班 4:中班 8:夜班
  19 + WorkOn int `json:"workOn"`
  20 + //保存并审核
  21 + SaveAndApprove bool `json:"saveAndApprove"`
  22 +}
@@ -9,12 +9,28 @@ import ( @@ -9,12 +9,28 @@ import (
9 ) 9 )
10 10
11 type CreateProductRecordCommand struct { 11 type CreateProductRecordCommand struct {
12 - // 生产记录ID  
13 - ProductRecordId int `cname:"生产记录ID" json:"productRecordId" valid:"Required"` 12 +
  13 + // 车间ID
  14 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  15 + // 生产线ID
  16 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  17 + // 工段ID
  18 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  19 +
  20 + WorkerId []int `cname:"工人ID" json:"workerId" valid:"Required"`
  21 +
  22 + //生气计划id
  23 + ProductPlanId int `cname:"生气计划id" json:"productPlanId" valid:"Required"`
  24 +
  25 + CreatedDate string `cname:"日期" json:"createdDate" valid:"Required"`
  26 + //重量
  27 + Weigh float64 `cname:"重量" json:"weigh" valid:"Required" `
  28 + //保存并审核
  29 + SaveAndApprove bool `json:"saveAndApprove"`
14 } 30 }
15 31
16 func (createProductRecordCommand *CreateProductRecordCommand) Valid(validation *validation.Validation) { 32 func (createProductRecordCommand *CreateProductRecordCommand) Valid(validation *validation.Validation) {
17 - validation.SetError("CustomValid", "未实现的自定义认证") 33 +
18 } 34 }
19 35
20 func (createProductRecordCommand *CreateProductRecordCommand) ValidateCommand() error { 36 func (createProductRecordCommand *CreateProductRecordCommand) ValidateCommand() error {
  1 +package command
  2 +
  3 +type SaveProductCapacitiesCmd struct {
  4 + //id
  5 + ProductRecordId int `json:"productRecordId"`
  6 + // 车间ID
  7 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  8 + // 生产线ID
  9 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  10 + // 工段ID
  11 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  12 + //员工
  13 + WorkerId int `cname:"工人ID" json:"workerId" valid:"Required"`
  14 + //产量重量
  15 + Weigh float64 `cname:"重量" json:"weigh" valid:"Required" `
  16 + //计划id
  17 + ProductPlanId int `json:"productPlanId"`
  18 + //日期
  19 + RecordDate string `json:"recordDate"`
  20 + //上班班次 1:全天 2:白班 4:中班 8:夜班
  21 + WorkOn int `json:"workOn"`
  22 + //保存并审核
  23 + SaveAndApprove bool `json:"saveAndApprove"`
  24 +}
@@ -41,5 +41,8 @@ func (d *HistoryProductRecord) LoadDto(m *domain.ProductRecord) *HistoryProductR @@ -41,5 +41,8 @@ func (d *HistoryProductRecord) LoadDto(m *domain.ProductRecord) *HistoryProductR
41 //log.Logger.Debug("not equal", map[string]interface{}{"t1": xtime.BeginningOfDay(), "t2": xtime.New(m.CreatedAt.Local()).BeginningOfDay()}) 41 //log.Logger.Debug("not equal", map[string]interface{}{"t1": xtime.BeginningOfDay(), "t2": xtime.New(m.CreatedAt.Local()).BeginningOfDay()})
42 d.Status = domain.ProductRecordLogged 42 d.Status = domain.ProductRecordLogged
43 } 43 }
  44 + if m.ProductRecordType == domain.RecordTypeSecondLevelWeigh && m.ProductRecordInfo.ApproveStatus == domain.ProductRecordAutoApproved {
  45 + d.Status = domain.ProductRecordApproved
  46 + }
44 return d 47 return d
45 } 48 }
  1 +package dto
  2 +
  3 +//产能管理-列表
  4 +type ProductCapacitiesList struct {
  5 + ProductRecordId int `json:"productRecordId"`
  6 + WorkshopName string `json:"workshopName"` //车间名称
  7 + LineName string `json:"lineName"` //线别名称
  8 + SectionName string `json:"sectionName"` //工段
  9 + WorkerName string `json:"workerName"` // 用户姓名
  10 + EmployeeType int `json:"employeeType"` // 员工类型 1:固定 2:派遣 3.临时
  11 + ProductName string `json:"productName"` //品名
  12 + WorkerOn int `json:"workerOn"` //班别
  13 + ProductWeigh float64 `json:"productWeigh"` // 产能
  14 + CreatedAt string `json:"createdAt"` // 创建时间
  15 + ApproveStatus int `json:"approveStatus"` //0:未审核 1:已审核 2.自动审核
  16 +}
  17 +
  18 +//产能管理-列表-详情
  19 +type ProductCapacitiesInfo struct {
  20 + ProductRecordId int `json:"id"`
  21 + WorkshopId int `json:"workshopId" ` // 车间ID
  22 + WorkshopName string `json:"workshopName"` //
  23 + LineId int `json:"lineId"` // 生产线ID
  24 + LineName string `json:"lineName"` //
  25 + SectionId int `json:"sectionId" ` // 工段ID
  26 + SectionName string `json:"sectionName"` //
  27 + WorkerId int `json:"workerId" ` //员工
  28 + WorkerName string `json:"workerName"` //
  29 + Weigh float64 `json:"weigh"` //产量重量
  30 + ProductPlanId int `json:"productPlanId"` //
  31 + BatchNumber string `json:"batchNumber"` //批次号
  32 + ProductName string `json:"productName"` //产品名称
  33 + ParticipateType int `json:"participateType"` //参与类型 1:正常 2:支援
  34 + RecordDate string `json:"recordDate"` //日期
  35 + WorkOn int `json:"workOn"` //上班班次 1:全天 2:白班 4:中班 8:夜班
  36 +}
  1 +package query
  2 +
  3 +type GetProductCapacitiesQuery struct {
  4 + EmployeeProductRecordId int `json:"id"`
  5 +}
@@ -54,6 +54,8 @@ type HistoryProductRecordQuery struct { @@ -54,6 +54,8 @@ type HistoryProductRecordQuery struct {
54 ProductWorkerId int `cname:"生产员工ID" json:"productWorkerId"` 54 ProductWorkerId int `cname:"生产员工ID" json:"productWorkerId"`
55 // 状态 0:全部 1:未审核 2:已审核 3:已撤回 4:已记录 55 // 状态 0:全部 1:未审核 2:已审核 3:已撤回 4:已记录
56 Status int `cname:"状态" json:"status"` 56 Status int `cname:"状态" json:"status"`
  57 + // 状态 0:全部 1:未审核 2:已审核 3:已撤回 4:已记录
  58 + InStatus []int `cname:"匹配多个状态" json:"intStatus"`
57 59
58 // 开始时间 60 // 开始时间
59 ProductBeginTime time.Time `cname:"开始时间" json:"productBeginTime"` 61 ProductBeginTime time.Time `cname:"开始时间" json:"productBeginTime"`
@@ -108,6 +110,10 @@ func (cmd *HistoryProductRecordQuery) Valid(validation *validation.Validation) { @@ -108,6 +110,10 @@ func (cmd *HistoryProductRecordQuery) Valid(validation *validation.Validation) {
108 } 110 }
109 } 111 }
110 } 112 }
  113 + if cmd.ProductRecordType == domain.RecordTypeSecondLevelWeigh && cmd.Status == domain.ProductRecordApproved {
  114 + cmd.Status = 0
  115 + cmd.InStatus = []int{domain.ProductRecordApproved, domain.ProductRecordAutoApproved}
  116 + }
111 } 117 }
112 118
113 func (cmd *HistoryProductRecordQuery) ValidateQuery() error { 119 func (cmd *HistoryProductRecordQuery) ValidateQuery() error {
  1 +package query
  2 +
  3 +type ListProductCapacitiesQuery struct {
  4 + PageNumber int `json:"pageNumber"`
  5 + PageSize int `json:"pageSize"`
  6 + CompanyId int `json:"companyId"`
  7 + OrgId int `json:"orgId"`
  8 + WorkshopName string `json:"workshopName"`
  9 + LineName string `json:"lineName"`
  10 + SectionName string `json:"sectionName"`
  11 + ProductBeginTime string `json:"productBeginTime"`
  12 + ProductEndTime string `json:"productEndTime"`
  13 + WorkerName string `json:"workerName"`
  14 +}
  1 +package service
  2 +
  3 +import (
  4 + "strconv"
  5 + "strings"
  6 + "time"
  7 +
  8 + "github.com/linmadan/egglib-go/core/application"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/command"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/dto"
  12 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/query"
  13 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  14 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
  15 +)
  16 +
  17 +//产能管理
  18 +
  19 +// 产能管理 页面上手动创建员工生产记录
  20 +func (productRecordService *ProductRecordService) SaveProductCapacities(operateInfo *domain.OperateInfo, param *command.SaveProductCapacitiesCmd) (map[string]interface{}, error) {
  21 + transactionContext, err := factory.CreateTransactionContext(nil)
  22 + if err != nil {
  23 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  24 + }
  25 + if err := transactionContext.StartTransaction(); err != nil {
  26 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  27 + }
  28 + defer func() {
  29 + transactionContext.RollbackTransaction()
  30 + }()
  31 +
  32 + //日期
  33 + recordDate, err := time.Parse("2006-01-02", param.RecordDate)
  34 + if err != nil {
  35 + return nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
  36 + }
  37 + //员工数据
  38 + var worker *domain.User
  39 + userService := domainService.NewUserService()
  40 + worker, err = userService.User(param.WorkerId)
  41 + if err != nil {
  42 + return nil, application.ThrowError(application.ARG_ERROR, "获取员工错误,"+err.Error())
  43 + }
  44 + //操作人数据
  45 + var user *domain.User
  46 + user, err = userService.User(operateInfo.UserId)
  47 + if err != nil {
  48 + return nil, application.ThrowError(application.ARG_ERROR, "获取操作人错误,"+err.Error())
  49 + }
  50 + //组织数据
  51 + var org *domain.Org
  52 + org, err = userService.Organization(operateInfo.OrgId)
  53 + if err != nil {
  54 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  55 + }
  56 + //车间数据
  57 + workshopRepo, _ := factory.CreateWorkshopRepository(map[string]interface{}{
  58 + "transactionContext": transactionContext,
  59 + })
  60 + workshop, err := workshopRepo.FindOne(map[string]interface{}{"workshopId": param.WorkshopId})
  61 + if err != nil {
  62 + return nil, application.ThrowError(application.ARG_ERROR, "获取车间数据失败"+err.Error())
  63 + }
  64 + workstation, err := workshop.FindWorkStation(param.WorkshopId, param.LineId, param.SectionId)
  65 + if err != nil {
  66 + return nil, application.ThrowError(application.ARG_ERROR, "获取车间工段数据失败"+err.Error())
  67 + }
  68 +
  69 + //获取生产记录
  70 + productPlanRepo, _ := factory.CreateProductPlanRepository(map[string]interface{}{
  71 + "transactionContext": transactionContext,
  72 + })
  73 +
  74 + planData, err := productPlanRepo.FindOne(map[string]interface{}{
  75 + "productPlanId": param.ProductPlanId,
  76 + })
  77 +
  78 + if err != nil {
  79 + return nil, application.ThrowError(application.ARG_ERROR, "获取计划任务数据失败"+err.Error())
  80 + }
  81 +
  82 + //员工生产记录
  83 + productRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
  84 + "transactionContext": transactionContext,
  85 + })
  86 +
  87 + nowTime := time.Now()
  88 + if param.ProductRecordId > 0 {
  89 + productRecord, err := productRecordRepo.FindOne(map[string]interface{}{
  90 + "productRecordId": param.ProductRecordId,
  91 + })
  92 + if err != nil {
  93 + return nil, application.ThrowError(application.ARG_ERROR, "获取生产记录数据失败"+err.Error())
  94 + }
  95 + if productRecord.ProductRecordInfo.ApproveStatus != domain.ProductRecordNotApprove {
  96 + return nil, application.ThrowError(application.ARG_ERROR, "生产记录不可再被编辑")
  97 + }
  98 + }
  99 + epRecord := &domain.ProductRecord{
  100 + ProductRecordId: param.ProductRecordId,
  101 + UpdatedAt: nowTime,
  102 + OrgId: operateInfo.OrgId,
  103 + CompanyId: operateInfo.CompanyId,
  104 + WorkStation: workstation,
  105 + ProductWorker: worker,
  106 + CreatedAt: recordDate,
  107 + Ext: &domain.Ext{
  108 + Operator: user,
  109 + OrgName: org.OrgName,
  110 + },
  111 + ProductRecordType: domain.RecordTypeReceiveMaterial,
  112 + ProductRecordInfo: &domain.ProductRecordInfo{
  113 + WorkOn: param.WorkOn,
  114 + ProductDate: param.RecordDate,
  115 + Weigh: param.Weigh,
  116 + WeighBefore: param.Weigh,
  117 + ApproveStatus: domain.ProductRecordNotApprove,
  118 + ApproveAt: 0,
  119 + ApproveUser: nil,
  120 + ProductPlanId: planData.ProductPlanId,
  121 + PlanProductName: planData.PlanProductName,
  122 + BatchNumber: planData.BatchNumber,
  123 + },
  124 + }
  125 + if param.SaveAndApprove {
  126 + epRecord.ProductRecordInfo.ApproveAt = nowTime.Unix()
  127 + epRecord.ProductRecordInfo.ApproveStatus = domain.ProductRecordApproved
  128 + epRecord.ProductRecordInfo.ApproveUser = user
  129 + }
  130 + _, err = productRecordRepo.Save(epRecord)
  131 + if err != nil {
  132 + return nil, application.ThrowError(application.ARG_ERROR, "保存员工生产记录失败"+err.Error())
  133 + }
  134 + if err := transactionContext.CommitTransaction(); err != nil {
  135 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  136 + }
  137 + return map[string]interface{}{
  138 + "productRecordId": epRecord.ProductRecordId,
  139 + }, nil
  140 +}
  141 +
  142 +// 产能管理 列表
  143 +func (productRecordService *ProductRecordService) ListProductCapacities(operateInfo *domain.OperateInfo, param *query.ListProductCapacitiesQuery) (int64, []dto.ProductCapacitiesList, error) {
  144 + transactionContext, err := factory.CreateTransactionContext(nil)
  145 + if err != nil {
  146 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  147 + }
  148 + if err := transactionContext.StartTransaction(); err != nil {
  149 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  150 + }
  151 + defer func() {
  152 + transactionContext.RollbackTransaction()
  153 + }()
  154 +
  155 + productRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
  156 + "transactionContext": transactionContext,
  157 + })
  158 +
  159 + productBeginTime, _ := time.ParseInLocation("2006-01-02", param.ProductBeginTime, time.Local)
  160 + productEndTime, _ := time.ParseInLocation("2006-01-02", param.ProductEndTime, time.Local)
  161 + if !productEndTime.IsZero() {
  162 + productEndTime.Add((86400 - 1) * time.Second)
  163 + }
  164 + condition := map[string]interface{}{
  165 + "companyId": param.CompanyId,
  166 + "orgId": param.OrgId,
  167 + "userName": param.WorkerName,
  168 + "workshopName": param.WorkshopName,
  169 + "lineName": param.LineName,
  170 + "sectionName": param.SectionName,
  171 + "productBeginTime": productBeginTime,
  172 + "productEndTime": productEndTime,
  173 + }
  174 +
  175 + limit := param.PageSize
  176 + offset := param.PageSize * (param.PageNumber - 1)
  177 + if limit >= 0 {
  178 + condition["limit"] = limit
  179 + }
  180 + if offset >= 0 {
  181 + condition["offset"] = offset
  182 + }
  183 + count, productRecords, err := productRecordRepo.Find(condition)
  184 + if err != nil {
  185 + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  186 + }
  187 + if err := transactionContext.CommitTransaction(); err != nil {
  188 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  189 + }
  190 +
  191 + var result = make([]dto.ProductCapacitiesList, 0)
  192 + for _, v := range productRecords {
  193 + item := dto.ProductCapacitiesList{
  194 + ProductRecordId: v.ProductRecordId,
  195 + WorkshopName: v.WorkStation.WorkshopName,
  196 + LineName: v.WorkStation.LineName,
  197 + SectionName: v.WorkStation.SectionName,
  198 + WorkerName: v.ProductWorker.UserName,
  199 + EmployeeType: v.ProductWorker.EmployeeType,
  200 + ProductName: v.ProductRecordInfo.PlanProductName,
  201 + WorkerOn: v.ProductRecordInfo.WorkOn,
  202 + ProductWeigh: v.ProductRecordInfo.Weigh,
  203 + CreatedAt: v.CreatedAt.Local().Format("2006-01-02"),
  204 + ApproveStatus: v.ProductRecordInfo.ApproveStatus,
  205 + }
  206 + result = append(result, item)
  207 + }
  208 + return count, result, nil
  209 +}
  210 +
  211 +// 产能管理 列表-详情
  212 +func (productRecordService *ProductRecordService) GetProductCapacities(operateInfo *domain.OperateInfo, id int) (*dto.ProductCapacitiesInfo, error) {
  213 + transactionContext, err := factory.CreateTransactionContext(nil)
  214 + if err != nil {
  215 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  216 + }
  217 + if err := transactionContext.StartTransaction(); err != nil {
  218 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  219 + }
  220 + defer func() {
  221 + transactionContext.RollbackTransaction()
  222 + }()
  223 +
  224 + productRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
  225 + "transactionContext": transactionContext,
  226 + })
  227 +
  228 + recordData, err := productRecordRepo.FindOne(map[string]interface{}{
  229 + "productRecordId": id,
  230 + })
  231 + if err != nil {
  232 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  233 + }
  234 +
  235 + if err := transactionContext.CommitTransaction(); err != nil {
  236 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  237 + }
  238 +
  239 + var result = dto.ProductCapacitiesInfo{
  240 + ProductRecordId: recordData.ProductRecordId,
  241 + WorkshopId: recordData.WorkStation.WorkshopId,
  242 + WorkshopName: recordData.WorkStation.WorkshopName,
  243 + LineId: recordData.WorkStation.LineId,
  244 + LineName: recordData.WorkStation.LineName,
  245 + SectionId: recordData.WorkStation.SectionId,
  246 + SectionName: recordData.WorkStation.SectionName,
  247 + WorkerId: recordData.ProductWorker.UserId,
  248 + WorkerName: recordData.ProductWorker.UserName,
  249 + Weigh: recordData.ProductRecordInfo.Weigh,
  250 + BatchNumber: recordData.ProductRecordInfo.BatchNumber,
  251 + ProductName: recordData.ProductRecordInfo.PlanProductName,
  252 + ProductPlanId: recordData.ProductRecordInfo.ProductPlanId,
  253 + RecordDate: recordData.CreatedAt.Format("2006-01-02"),
  254 + WorkOn: recordData.ProductRecordInfo.WorkOn,
  255 + }
  256 +
  257 + return &result, nil
  258 +}
  259 +
  260 +// 产能管理 列表-删除
  261 +func (productRecordService *ProductRecordService) DeleteProductCapacities(operateInfo *domain.OperateInfo, id int) (map[string]interface{}, error) {
  262 + transactionContext, err := factory.CreateTransactionContext(nil)
  263 + if err != nil {
  264 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  265 + }
  266 + if err := transactionContext.StartTransaction(); err != nil {
  267 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  268 + }
  269 + defer func() {
  270 + transactionContext.RollbackTransaction()
  271 + }()
  272 +
  273 + eProductRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
  274 + "transactionContext": transactionContext,
  275 + })
  276 +
  277 + recordData, err := eProductRecordRepo.FindOne(map[string]interface{}{
  278 + "productRecordId": id,
  279 + })
  280 + if err != nil {
  281 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  282 + }
  283 + _, err = eProductRecordRepo.Remove(recordData)
  284 + if err != nil {
  285 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  286 + }
  287 + if err := transactionContext.CommitTransaction(); err != nil {
  288 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  289 + }
  290 +
  291 + return map[string]interface{}{
  292 + "productRecordId": recordData.ProductRecordId,
  293 + }, nil
  294 +}
  295 +
  296 +// 产能管理 列表-审核
  297 +func (productRecordService *ProductRecordService) ApproveProductCapacities(operateInfo *domain.OperateInfo, id int) (map[string]interface{}, error) {
  298 + transactionContext, err := factory.CreateTransactionContext(nil)
  299 + if err != nil {
  300 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  301 + }
  302 + if err := transactionContext.StartTransaction(); err != nil {
  303 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  304 + }
  305 + defer func() {
  306 + transactionContext.RollbackTransaction()
  307 + }()
  308 +
  309 + productRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
  310 + "transactionContext": transactionContext,
  311 + })
  312 +
  313 + recordData, err := productRecordRepo.FindOne(map[string]interface{}{
  314 + "productRecordId": id,
  315 + })
  316 + if err != nil {
  317 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  318 + }
  319 +
  320 + userService := domainService.NewUserService()
  321 + //操作人数据
  322 + var user *domain.User
  323 + user, err = userService.User(operateInfo.UserId)
  324 + if err != nil {
  325 + return nil, application.ThrowError(application.ARG_ERROR, "获取操作人错误,"+err.Error())
  326 + }
  327 + err = recordData.Approve(user, recordData.ProductRecordInfo.Weigh, time.Now(), domain.ProductRecordApproved)
  328 + if err != nil {
  329 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  330 + }
  331 + _, err = productRecordRepo.Save(recordData)
  332 + if err != nil {
  333 + return nil, application.ThrowError(application.ARG_ERROR, "保存数据错误,"+err.Error())
  334 + }
  335 + if err := transactionContext.CommitTransaction(); err != nil {
  336 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  337 + }
  338 + return map[string]interface{}{
  339 + "productRecordId": recordData.ProductRecordId,
  340 + }, nil
  341 +}
  342 +
  343 +// 从excel导入 批量添加
  344 +func (srv *ProductRecordService) BatchAddProductCapacities(operate *domain.OperateInfo, dataList []command.BatchAddProductCapacitiesCmd) (
  345 + failRows []interface{}, err error) {
  346 + transactionContext, err := factory.CreateTransactionContext(nil)
  347 + if err != nil {
  348 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  349 + }
  350 + if err := transactionContext.StartTransaction(); err != nil {
  351 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  352 + }
  353 + defer func() {
  354 + transactionContext.RollbackTransaction()
  355 + }()
  356 +
  357 + //获取当前操作人
  358 + userSrv := domainService.NewUserService()
  359 + operateUser, err := userSrv.User(operate.UserId)
  360 + if err != nil {
  361 + return nil, application.ThrowError(application.TRANSACTION_ERROR, "查询操作人数据失败。"+err.Error())
  362 + }
  363 + //获取当前操作人的组织
  364 + var org *domain.Org
  365 + org, err = userSrv.Organization(operate.OrgId)
  366 + if err != nil {
  367 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  368 + }
  369 +
  370 + //生产班组 数据
  371 + productGroupRepo, _ := factory.CreateProductGroupRepository(map[string]interface{}{
  372 + "transactionContext": transactionContext,
  373 + })
  374 +
  375 + //生产计划数据
  376 + productPlanRepo, _ := factory.CreateProductPlanRepository(map[string]interface{}{
  377 + "transactionContext": transactionContext,
  378 + })
  379 +
  380 + _, productGroupList, err := productGroupRepo.Find(map[string]interface{}{
  381 + "companyId": operate.CompanyId,
  382 + "orgId": operate.OrgId,
  383 + })
  384 + if err != nil {
  385 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  386 + }
  387 + //车间数据
  388 + workshopRepo, _ := factory.CreateWorkshopRepository(map[string]interface{}{
  389 + "transactionContext": transactionContext,
  390 + })
  391 +
  392 + //获取车间列表
  393 + _, workshopList, err := workshopRepo.Find(map[string]interface{}{
  394 + "companyId": operate.CompanyId,
  395 + "orgId": operate.OrgId,
  396 + })
  397 + if err != nil {
  398 + return nil, application.ThrowError(application.BUSINESS_ERROR, "获取车间列表失败"+err.Error())
  399 + }
  400 +
  401 + //车间名称+/+工人名 作为键名
  402 + workerMap := map[string][]*domain.User{}
  403 + for _, v := range productGroupList {
  404 + for _, vv := range v.GroupMembers {
  405 + k := v.WorkStation.WorkshopName + "/" + vv.UserName
  406 + isIn := false
  407 + for _, vvv := range workerMap[k] {
  408 + if vvv.UserId == vv.UserId {
  409 + isIn = true
  410 + break
  411 + }
  412 + }
  413 + if !isIn {
  414 + workerMap[k] = append(workerMap[k], vv)
  415 + }
  416 + }
  417 + }
  418 + //车间名称+/+线别名称+/+工段名称 作为键名
  419 + workStationMap := map[string]*domain.WorkStation{}
  420 + for _, v := range workshopList {
  421 + for _, v2 := range v.ProductLines {
  422 + for _, v3 := range v2.ProductSections {
  423 + workStationName := strings.Join([]string{
  424 + v.WorkshopName, v2.LineName, v3.SectionName,
  425 + }, "/")
  426 + workStationMap[workStationName] = domain.NewWorkStation(v, v2, v3)
  427 + }
  428 + }
  429 + }
  430 + productRecordList := []*domain.ProductRecord{}
  431 +
  432 + nowTime := time.Now()
  433 + for i := range dataList {
  434 + //检查字段
  435 + err = dataList[i].ValidField()
  436 + if err != nil {
  437 + dataList[i].FailReason = err.Error()
  438 + failRows = append(failRows, dataList[i])
  439 + continue
  440 + }
  441 + //检查日期格式
  442 + productDate, err := time.ParseInLocation("2006-01-02", dataList[i].RecordDate, time.Local)
  443 + if err != nil {
  444 + dataList[i].FailReason = "日期格式错误,例 2006-01-02。"
  445 + failRows = append(failRows, dataList[i])
  446 + continue
  447 + }
  448 + //检查工位
  449 + var workStation *domain.WorkStation
  450 + workStationName := dataList[i].WorkshopName + "/" + dataList[i].LineName + "/" + dataList[i].SectionName
  451 + if v, ok := workStationMap[workStationName]; ok {
  452 + workStation = v
  453 + } else {
  454 + dataList[i].FailReason = "车间、线别、工段不存在"
  455 + failRows = append(failRows, dataList[i])
  456 + continue
  457 + }
  458 +
  459 + //检查员工姓名
  460 + var worker *domain.User
  461 + workKey := dataList[i].WorkshopName + "/" + dataList[i].WorkerName
  462 + if u, ok := workerMap[workKey]; ok {
  463 + if len(u) > 1 {
  464 + dataList[i].FailReason = "当前车间存在重复的用户名"
  465 + failRows = append(failRows, dataList[i])
  466 + continue
  467 + }
  468 + worker = u[0]
  469 + } else {
  470 + dataList[i].FailReason = "当前车间不存在用户" + dataList[i].WorkerName
  471 + failRows = append(failRows, dataList[i])
  472 + continue
  473 + }
  474 + //二级品重量
  475 + weigh, err := strconv.ParseFloat(dataList[i].Weigh, 64)
  476 + if err != nil {
  477 + dataList[i].FailReason = "重量填写错误"
  478 + failRows = append(failRows, dataList[i])
  479 + continue
  480 + }
  481 + //按批次获取生产计划
  482 + productPlanData, err := productPlanRepo.FindOne(map[string]interface{}{
  483 + "batchNumber": dataList[i].BatchNumber,
  484 + "companyId": operate.CompanyId,
  485 + })
  486 + if err != nil {
  487 + dataList[i].FailReason = "批次号不存在"
  488 + failRows = append(failRows, dataList[i])
  489 + continue
  490 + }
  491 + //检查上班班次 1:全天 2:白班 4:中班 8:夜班
  492 + workerOn := 0
  493 + switch dataList[i].WorkOn {
  494 + case "全天":
  495 + workerOn = 1
  496 + case "白班":
  497 + workerOn = 2
  498 + case "中班":
  499 + workerOn = 4
  500 + case "夜班":
  501 + workerOn = 8
  502 + default:
  503 + dataList[i].FailReason = "上班班次 填写错误"
  504 + failRows = append(failRows, dataList[i])
  505 + continue
  506 + }
  507 +
  508 + tempItem := &domain.ProductRecord{
  509 + ProductRecordId: 0,
  510 + CompanyId: operate.CompanyId,
  511 + OrgId: operate.OrgId,
  512 + ProductRecordType: domain.RecordTypeReceiveMaterial,
  513 + ProductWorker: worker,
  514 + WorkStation: workStation,
  515 + CreatedAt: productDate,
  516 + UpdatedAt: nowTime,
  517 + DeletedAt: time.Time{},
  518 + ProductRecordInfo: &domain.ProductRecordInfo{
  519 + ProductDate: productDate.Local().Format("2006-01-02"),
  520 + Original: weigh,
  521 + Weigh: weigh,
  522 + WeighBefore: weigh,
  523 + WeighAfter: weigh,
  524 + ApproveStatus: domain.ProductRecordAutoApproved,
  525 + ApproveAt: nowTime.Unix(),
  526 + ApproveUser: operateUser,
  527 + UnitConversionId: productPlanData.Ext.ProductPlanExt.ProductId,
  528 + ProductPlanId: productPlanData.ProductPlanId,
  529 + PlanProductName: productPlanData.PlanProductName,
  530 + BatchNumber: productPlanData.BatchNumber,
  531 + ProductGroupId: 0,
  532 + WorkOn: workerOn,
  533 + },
  534 + Ext: &domain.Ext{
  535 + Operator: operateUser,
  536 + OrgName: org.OrgName,
  537 + },
  538 + PreRecord: &domain.ProductRecord{},
  539 + }
  540 + productRecordList = append(productRecordList, tempItem)
  541 + }
  542 + if len(failRows) > 0 {
  543 + return failRows, nil
  544 + }
  545 + productRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
  546 + "transactionContext": transactionContext,
  547 + })
  548 + for i := range productRecordList {
  549 + _, err := productRecordRepo.Save(productRecordList[i])
  550 + if err != nil {
  551 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  552 + }
  553 + }
  554 + if err := transactionContext.CommitTransaction(); err != nil {
  555 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  556 + }
  557 + return failRows, nil
  558 +}
  559 +
  560 +// 产能管理 页面上手动创建员工生产记录
  561 +func (productRecordService *ProductRecordService) CreateProductCapacities(operateInfo *domain.OperateInfo, param *command.CreateProductCapacitiesCmd) (map[string]interface{}, error) {
  562 + transactionContext, err := factory.CreateTransactionContext(nil)
  563 + if err != nil {
  564 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  565 + }
  566 + if err := transactionContext.StartTransaction(); err != nil {
  567 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  568 + }
  569 + defer func() {
  570 + transactionContext.RollbackTransaction()
  571 + }()
  572 +
  573 + //日期
  574 + recordDate, err := time.Parse("2006-01-02", param.RecordDate)
  575 + if err != nil {
  576 + return nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
  577 + }
  578 + userService := domainService.NewUserService()
  579 + //操作人数据
  580 + var user *domain.User
  581 + user, err = userService.User(operateInfo.UserId)
  582 + if err != nil {
  583 + return nil, application.ThrowError(application.ARG_ERROR, "获取操作人错误,"+err.Error())
  584 + }
  585 + //组织数据
  586 + var org *domain.Org
  587 + org, err = userService.Organization(operateInfo.OrgId)
  588 + if err != nil {
  589 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  590 + }
  591 + //车间数据
  592 + workshopRepo, _ := factory.CreateWorkshopRepository(map[string]interface{}{
  593 + "transactionContext": transactionContext,
  594 + })
  595 + workshop, err := workshopRepo.FindOne(map[string]interface{}{"workshopId": param.WorkshopId})
  596 + if err != nil {
  597 + return nil, application.ThrowError(application.ARG_ERROR, "获取车间数据失败"+err.Error())
  598 + }
  599 + workstation, err := workshop.FindWorkStation(param.WorkshopId, param.LineId, param.SectionId)
  600 + if err != nil {
  601 + return nil, application.ThrowError(application.ARG_ERROR, "获取车间工段数据失败"+err.Error())
  602 + }
  603 +
  604 + //获取生产记录
  605 + productPlanRepo, _ := factory.CreateProductPlanRepository(map[string]interface{}{
  606 + "transactionContext": transactionContext,
  607 + })
  608 +
  609 + planData, err := productPlanRepo.FindOne(map[string]interface{}{
  610 + "productPlanId": param.ProductPlanId,
  611 + })
  612 +
  613 + if err != nil {
  614 + return nil, application.ThrowError(application.ARG_ERROR, "获取计划任务数据失败"+err.Error())
  615 + }
  616 +
  617 + //员工生产记录
  618 + productRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
  619 + "transactionContext": transactionContext,
  620 + })
  621 +
  622 + nowTime := time.Now()
  623 + productRecordIds := []int{}
  624 + for _, workerId := range param.WorkerId {
  625 + //员工数据
  626 + worker, err := userService.User(workerId)
  627 + if err != nil {
  628 + return nil, application.ThrowError(application.ARG_ERROR, "获取员工错误,"+err.Error())
  629 + }
  630 + epRecord := &domain.ProductRecord{
  631 + UpdatedAt: nowTime,
  632 + OrgId: operateInfo.OrgId,
  633 + CompanyId: operateInfo.CompanyId,
  634 + WorkStation: workstation,
  635 + ProductWorker: worker,
  636 + CreatedAt: recordDate,
  637 + Ext: &domain.Ext{
  638 + Operator: user,
  639 + OrgName: org.OrgName,
  640 + },
  641 + ProductRecordType: domain.RecordTypeReceiveMaterial,
  642 + ProductRecordInfo: &domain.ProductRecordInfo{
  643 + WorkOn: param.WorkOn,
  644 + ProductDate: param.RecordDate,
  645 + Weigh: param.Weigh,
  646 + WeighBefore: param.Weigh,
  647 + ApproveStatus: domain.ProductRecordNotApprove,
  648 + ApproveAt: 0,
  649 + ApproveUser: nil,
  650 + ProductPlanId: planData.ProductPlanId,
  651 + PlanProductName: planData.PlanProductName,
  652 + BatchNumber: planData.BatchNumber,
  653 + },
  654 + }
  655 + if param.SaveAndApprove {
  656 + epRecord.ProductRecordInfo.ApproveAt = nowTime.Unix()
  657 + epRecord.ProductRecordInfo.ApproveStatus = domain.ProductRecordApproved
  658 + epRecord.ProductRecordInfo.ApproveUser = user
  659 + }
  660 + _, err = productRecordRepo.Save(epRecord)
  661 + if err != nil {
  662 + return nil, application.ThrowError(application.ARG_ERROR, "保存员工生产记录失败"+err.Error())
  663 + }
  664 + productRecordIds = append(productRecordIds, epRecord.ProductRecordId)
  665 + }
  666 + if err := transactionContext.CommitTransaction(); err != nil {
  667 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  668 + }
  669 + return map[string]interface{}{
  670 + "productRecordIds": productRecordIds,
  671 + }, nil
  672 +}
@@ -2,6 +2,12 @@ package service @@ -2,6 +2,12 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "strconv"
  6 + "strings"
  7 + "time"
  8 +
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
  10 +
5 "github.com/linmadan/egglib-go/core/application" 11 "github.com/linmadan/egglib-go/core/application"
6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 12 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
7 "github.com/linmadan/egglib-go/utils/tool_funs" 13 "github.com/linmadan/egglib-go/utils/tool_funs"
@@ -12,13 +18,17 @@ import ( @@ -12,13 +18,17 @@ import (
12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 18 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" 19 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
14 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" 20 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
15 - "time"  
16 ) 21 )
17 22
18 // 生产记录服务 23 // 生产记录服务
19 type ProductRecordService struct { 24 type ProductRecordService struct {
20 } 25 }
21 26
  27 +func NewProductRecordService(options map[string]interface{}) *ProductRecordService {
  28 + newProductRecordService := &ProductRecordService{}
  29 + return newProductRecordService
  30 +}
  31 +
22 // 生产记录审核 32 // 生产记录审核
23 func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *command.ApproveProductRecordCommand) (interface{}, error) { 33 func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *command.ApproveProductRecordCommand) (interface{}, error) {
24 if err := cmd.ValidateCommand(); err != nil { 34 if err := cmd.ValidateCommand(); err != nil {
@@ -35,7 +45,7 @@ func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *comm @@ -35,7 +45,7 @@ func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *comm
35 transactionContext.RollbackTransaction() 45 transactionContext.RollbackTransaction()
36 }() 46 }()
37 47
38 - svr, err := domainService.NewPGProductRecordService(transactionContext.(*pgTransaction.TransactionContext)) 48 + svr, _ := domainService.NewPGProductRecordService(transactionContext.(*pgTransaction.TransactionContext))
39 if _, err = svr.Approve(cmd.ProductRecordId, cmd.ApproveUserId, cmd.WeighAfter, time.Now()); err != nil { 49 if _, err = svr.Approve(cmd.ProductRecordId, cmd.ApproveUserId, cmd.WeighAfter, time.Now()); err != nil {
40 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 50 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
41 } 51 }
@@ -46,9 +56,9 @@ func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *comm @@ -46,9 +56,9 @@ func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *comm
46 return struct{}{}, nil 56 return struct{}{}, nil
47 } 57 }
48 58
49 -// 创建生产记录服务  
50 -func (productRecordService *ProductRecordService) CreateProductRecord(createProductRecordCommand *command.CreateProductRecordCommand) (interface{}, error) {  
51 - if err := createProductRecordCommand.ValidateCommand(); err != nil { 59 +// 创建生产记录服务,二级品
  60 +func (productRecordService *ProductRecordService) CreateProductRecord(operateInfo *domain.OperateInfo, param *command.CreateProductRecordCommand) (interface{}, error) {
  61 + if err := param.ValidateCommand(); err != nil {
52 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 62 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
53 } 63 }
54 transactionContext, err := factory.CreateTransactionContext(nil) 64 transactionContext, err := factory.CreateTransactionContext(nil)
@@ -61,25 +71,100 @@ func (productRecordService *ProductRecordService) CreateProductRecord(createProd @@ -61,25 +71,100 @@ func (productRecordService *ProductRecordService) CreateProductRecord(createProd
61 defer func() { 71 defer func() {
62 transactionContext.RollbackTransaction() 72 transactionContext.RollbackTransaction()
63 }() 73 }()
64 - newProductRecord := &domain.ProductRecord{  
65 - ProductRecordId: createProductRecordCommand.ProductRecordId, 74 +
  75 + //日期
  76 + dataTime, err := time.ParseInLocation("2006-01-02", param.CreatedDate, time.Local)
  77 + if err != nil {
  78 + return nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
66 } 79 }
67 - var productRecordRepository domain.ProductRecordRepository  
68 - if value, err := factory.CreateProductRecordRepository(map[string]interface{}{ 80 + //生产记录存储
  81 + productRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
69 "transactionContext": transactionContext, 82 "transactionContext": transactionContext,
70 - }); err != nil {  
71 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
72 - } else {  
73 - productRecordRepository = value 83 + })
  84 +
  85 + //生产计划
  86 + productPlanRepo, _ := factory.CreateProductPlanRepository(map[string]interface{}{
  87 + "transactionContext": transactionContext,
  88 + })
  89 + //生产计划数据
  90 + productPlanData, err := productPlanRepo.FindOne(map[string]interface{}{
  91 + "product_plan_id": param.ProductPlanId,
  92 + "company_id": operateInfo.CompanyId,
  93 + })
  94 + if err != nil {
  95 + return nil, application.ThrowError(application.ARG_ERROR, "生产计划id错误,"+err.Error())
  96 + }
  97 + //用户数据
  98 + var user *domain.User
  99 + userService := domainService.NewUserService()
  100 + user, err = userService.User(operateInfo.UserId)
  101 + if err != nil {
  102 + return nil, application.ThrowError(application.ARG_ERROR, "获取用户错误,"+err.Error())
74 } 103 }
75 - if productRecord, err := productRecordRepository.Save(newProductRecord); err != nil { 104 + var org *domain.Org
  105 + org, err = userService.Organization(operateInfo.OrgId)
  106 + if err != nil {
76 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 107 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
77 - } else { 108 + }
  109 + workshopRepo, _ := factory.CreateWorkshopRepository(map[string]interface{}{
  110 + "transactionContext": transactionContext,
  111 + })
  112 + workshop, err := workshopRepo.FindOne(map[string]interface{}{"workshopId": param.WorkshopId})
  113 + if err != nil {
  114 + return nil, application.ThrowError(application.ARG_ERROR, "获取车间数据失败"+err.Error())
  115 + }
  116 + workstation, err := workshop.FindWorkStation(param.WorkshopId, param.LineId, param.SectionId)
  117 + if err != nil {
  118 + return nil, application.ThrowError(application.ARG_ERROR, "获取车间工段数据失败"+err.Error())
  119 + }
  120 + productRecordIds := []int{}
  121 + for _, workerId := range param.WorkerId {
  122 + workerData, err := userService.User(workerId)
  123 + if err != nil {
  124 + return nil, application.ThrowError(application.ARG_ERROR, "获取员工数据错误,"+err.Error())
  125 + }
  126 + productRecordData := &domain.ProductRecord{
  127 + CompanyId: operateInfo.CompanyId,
  128 + OrgId: operateInfo.OrgId,
  129 + ProductRecordType: domain.RecordTypeSecondLevelWeigh,
  130 + ProductWorker: workerData,
  131 + WorkStation: workstation,
  132 + CreatedAt: dataTime,
  133 + UpdatedAt: time.Now(),
  134 + ProductRecordInfo: &domain.ProductRecordInfo{
  135 + ProductDate: productPlanData.ProductDate.Local().Format("2006-01-02"),
  136 + Original: param.Weigh,
  137 + Weigh: utils.Round(param.Weigh, 1),
  138 + WeighBefore: utils.Round(param.Weigh, 1),
  139 + UnitConversionId: 0,
  140 + ApproveStatus: domain.ProductRecordNotApprove,
  141 + ProductPlanId: productPlanData.ProductPlanId,
  142 + BatchNumber: productPlanData.BatchNumber,
  143 + PlanProductName: productPlanData.PlanProductName,
  144 + ProductGroupId: 0,
  145 + WorkOn: productPlanData.WorkOn,
  146 + },
  147 + Ext: domain.NewExt(org.OrgName),
  148 + }
  149 + //保存并审核
  150 + if param.SaveAndApprove {
  151 + productRecordData.Approve(user, param.Weigh, time.Now(), domain.ProductRecordApproved)
  152 + }
  153 + _, err = productRecordRepo.Save(productRecordData)
  154 + if err != nil {
  155 + return nil, application.ThrowError(application.ARG_ERROR, "保存生产记录"+err.Error())
  156 + }
  157 + productRecordIds = append(productRecordIds, productRecordData.ProductRecordId)
  158 + if param.SaveAndApprove {
  159 + _ = domainService.SendProductRecordStaticsJob(productRecordData)
  160 + }
  161 + }
78 if err := transactionContext.CommitTransaction(); err != nil { 162 if err := transactionContext.CommitTransaction(); err != nil {
79 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 163 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
80 } 164 }
81 - return productRecord, nil  
82 - } 165 + return map[string]interface{}{
  166 + "productRecordId": productRecordIds,
  167 + }, nil
83 } 168 }
84 169
85 // 返回生产记录服务 170 // 返回生产记录服务
@@ -370,7 +455,219 @@ func (productRecordService *ProductRecordService) CancelProductRecord(cmd *comma @@ -370,7 +455,219 @@ func (productRecordService *ProductRecordService) CancelProductRecord(cmd *comma
370 return struct{}{}, nil 455 return struct{}{}, nil
371 } 456 }
372 457
373 -func NewProductRecordService(options map[string]interface{}) *ProductRecordService {  
374 - newProductRecordService := &ProductRecordService{}  
375 - return newProductRecordService 458 +// BatchAddProductRecord 从文件导入的数据,批量添加生产记录,二级品数据
  459 +func (productRecordService *ProductRecordService) BatchAddProductRecord(operate *domain.OperateInfo, param []command.BatchAddProductRecordCommand) (
  460 + failRows []interface{}, err error) {
  461 + transactionContext, err := factory.CreateTransactionContext(nil)
  462 + if err != nil {
  463 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  464 + }
  465 + if err := transactionContext.StartTransaction(); err != nil {
  466 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  467 + }
  468 + defer func() {
  469 + transactionContext.RollbackTransaction()
  470 + }()
  471 +
  472 + //获取当前操作人
  473 + userSrv := domainService.NewUserService()
  474 + operateUser, err := userSrv.User(operate.UserId)
  475 + if err != nil {
  476 + return nil, application.ThrowError(application.TRANSACTION_ERROR, "查询操作人数据失败。"+err.Error())
  477 + }
  478 + //获取当前操作人的组织
  479 + var org *domain.Org
  480 + org, err = userSrv.Organization(operate.OrgId)
  481 + if err != nil {
  482 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  483 + }
  484 +
  485 + //生产班组 数据
  486 + productGroupRepo, _ := factory.CreateProductGroupRepository(map[string]interface{}{
  487 + "transactionContext": transactionContext,
  488 + })
  489 +
  490 + //生产计划数据
  491 + productPlanRepo, _ := factory.CreateProductPlanRepository(map[string]interface{}{
  492 + "transactionContext": transactionContext,
  493 + })
  494 +
  495 + _, productGroupList, err := productGroupRepo.Find(map[string]interface{}{
  496 + "companyId": operate.CompanyId,
  497 + "orgId": operate.OrgId,
  498 + })
  499 + if err != nil {
  500 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  501 + }
  502 + //车间数据
  503 + workshopRepo, _ := factory.CreateWorkshopRepository(map[string]interface{}{
  504 + "transactionContext": transactionContext,
  505 + })
  506 +
  507 + //获取车间列表
  508 + _, workshopList, err := workshopRepo.Find(map[string]interface{}{
  509 + "companyId": operate.CompanyId,
  510 + "orgId": operate.OrgId,
  511 + })
  512 + if err != nil {
  513 + return nil, application.ThrowError(application.BUSINESS_ERROR, "获取车间列表失败"+err.Error())
  514 + }
  515 + //车间名称+/+工人名 作为键名
  516 + workerMap := map[string][]*domain.User{}
  517 + for _, v := range productGroupList {
  518 + for _, vv := range v.GroupMembers {
  519 + k := v.WorkStation.WorkshopName + "/" + vv.UserName
  520 + isIn := false
  521 + for _, vvv := range workerMap[k] {
  522 + if vvv.UserId == vv.UserId {
  523 + isIn = true
  524 + break
  525 + }
  526 + }
  527 + if !isIn {
  528 + workerMap[k] = append(workerMap[k], vv)
  529 + }
  530 + }
  531 + }
  532 +
  533 + //车间名称+/+线别名称+/+工段名称 作为键名
  534 + workStationMap := map[string]*domain.WorkStation{}
  535 + for _, v := range workshopList {
  536 + for _, v2 := range v.ProductLines {
  537 + for _, v3 := range v2.ProductSections {
  538 + workStationName := strings.Join([]string{
  539 + v.WorkshopName, v2.LineName, v3.SectionName,
  540 + }, "/")
  541 + workStationMap[workStationName] = domain.NewWorkStation(v, v2, v3)
  542 + }
  543 + }
  544 + }
  545 +
  546 + productRecordList := []*domain.ProductRecord{}
  547 + nowTime := time.Now()
  548 + for i := range param {
  549 + //检查字段
  550 + err = param[i].ValidField()
  551 + if err != nil {
  552 + param[i].FailReason = err.Error()
  553 + failRows = append(failRows, param[i])
  554 + continue
  555 + }
  556 + //检查日期格式
  557 + productDate, err := time.ParseInLocation("2006-01-02", param[i].CreatedDate, time.Local)
  558 + if err != nil {
  559 + param[i].FailReason = "日期格式错误,例 2006-01-02。"
  560 + failRows = append(failRows, param[i])
  561 + continue
  562 + }
  563 + //检查工位
  564 + var workStation *domain.WorkStation
  565 + workStationName := param[i].WorkshopName + "/" + param[i].LineName + "/" + param[i].SectionName
  566 + if v, ok := workStationMap[workStationName]; ok {
  567 + workStation = v
  568 + } else {
  569 + param[i].FailReason = "车间、线别、工段不存在"
  570 + failRows = append(failRows, param[i])
  571 + continue
  572 + }
  573 + // //获取生产班组
  574 + // var productGroup *domain.ProductGroup
  575 + // if v, ok := productGroupMap[param[i].ProductGroupName]; ok {
  576 + // productGroup = v
  577 + // } else {
  578 + // param[i].FailReason = "班组不存在"
  579 + // failRows = append(failRows, param[i])
  580 + // continue
  581 + // }
  582 + //检查员工姓名
  583 + var worker *domain.User
  584 + workKey := param[i].WorkshopName + "/" + param[i].WorkerName
  585 + if u, ok := workerMap[workKey]; ok {
  586 + if len(u) > 1 {
  587 + param[i].FailReason = "当前车间存在重复的用户名"
  588 + failRows = append(failRows, param[i])
  589 + continue
  590 + }
  591 + worker = u[0]
  592 + } else {
  593 + param[i].FailReason = "当前车间不存在用户" + param[i].WorkerName
  594 + failRows = append(failRows, param[i])
  595 + continue
  596 + }
  597 + //二级品重量
  598 + weigh, err := strconv.ParseFloat(param[i].Weigh, 64)
  599 + if err != nil {
  600 + param[i].FailReason = "二级品重量填写错误"
  601 + failRows = append(failRows, param[i])
  602 + continue
  603 + }
  604 + //按批次获取生产计划
  605 + productPlanData, err := productPlanRepo.FindOne(map[string]interface{}{
  606 + "batchNumber": param[i].BatchNumber,
  607 + "companyId": operate.CompanyId,
  608 + })
  609 + if err != nil {
  610 + param[i].FailReason = "批次号不存在"
  611 + failRows = append(failRows, param[i])
  612 + continue
  613 + }
  614 +
  615 + tempItem := &domain.ProductRecord{
  616 + ProductRecordId: 0,
  617 + CompanyId: operate.CompanyId,
  618 + OrgId: operate.OrgId,
  619 + ProductRecordType: domain.RecordTypeSecondLevelWeigh,
  620 + ProductWorker: worker,
  621 + WorkStation: workStation,
  622 + CreatedAt: productDate,
  623 + UpdatedAt: nowTime,
  624 + DeletedAt: time.Time{},
  625 + ProductRecordInfo: &domain.ProductRecordInfo{
  626 + ProductDate: productDate.Local().Format("2006-01-02"),
  627 + Original: weigh,
  628 + Weigh: weigh,
  629 + WeighBefore: weigh,
  630 + WeighAfter: weigh,
  631 + ApproveStatus: domain.ProductRecordAutoApproved,
  632 + ApproveAt: nowTime.Unix(),
  633 + ApproveUser: operateUser,
  634 + UnitConversionId: productPlanData.Ext.ProductPlanExt.ProductId,
  635 + ProductPlanId: productPlanData.ProductPlanId,
  636 + PlanProductName: productPlanData.PlanProductName,
  637 + BatchNumber: productPlanData.BatchNumber,
  638 + ProductGroupId: 0,
  639 + WorkOn: productPlanData.WorkOn,
  640 + },
  641 + Ext: &domain.Ext{
  642 + Operator: operateUser,
  643 + OrgName: org.OrgName,
  644 + },
  645 + PreRecord: &domain.ProductRecord{},
  646 + }
  647 + productRecordList = append(productRecordList, tempItem)
  648 + }
  649 + if len(failRows) > 0 {
  650 + return failRows, nil
  651 + }
  652 + productRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
  653 + "transactionContext": transactionContext,
  654 + })
  655 + for i := range productRecordList {
  656 + _, err := productRecordRepo.Save(productRecordList[i])
  657 + if err != nil {
  658 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  659 + }
  660 + }
  661 + if err := transactionContext.CommitTransaction(); err != nil {
  662 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  663 + }
  664 + for i := range productRecordList {
  665 + err = domainService.SendProductRecordStaticsJob(productRecordList[i])
  666 + if err != nil {
  667 + e := fmt.Sprintf("【发送产量统计任务失败】 ProductRecordId=%d, %s", productRecordList[i].ProductRecordId, err.Error())
  668 + log.Logger.Error(e)
  669 + return failRows, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  670 + }
  671 + }
  672 + return failRows, nil
376 } 673 }
  1 +package command
  2 +
  3 +import "errors"
  4 +
  5 +type BatchAddProductTroubleCommand struct {
  6 + RecordDate string `json:"recordDate"` //事故发生的日期 2006-01-02
  7 + WorkshopName string `json:"workshopId"` //车间
  8 + LineName string `json:"lineName"` //生产线
  9 + SectionName string `json:"sectionId" valid:"Required"` //工段
  10 + WorkerName string `json:"workerId"` //员工名字
  11 + AmountLoss string `json:"amountLoss"` // 损失的金额
  12 + TypesName string `json:"types"` // 事故类型 1 安全事故 ,2 质量事故, 3 金属事故 ,4 非金属事故
  13 + FailReason string `json:"failReason"` // 数据检查失败的原因
  14 +}
  15 +
  16 +func (c *BatchAddProductTroubleCommand) ValidField() error {
  17 + if len(c.RecordDate) == 0 {
  18 + return errors.New("日期 必填")
  19 + }
  20 + if len(c.WorkshopName) == 0 {
  21 + return errors.New("车间 必填")
  22 + }
  23 + if len(c.LineName) == 0 {
  24 + return errors.New("生产线 必填")
  25 + }
  26 + if len(c.SectionName) == 0 {
  27 + return errors.New("工段 必填")
  28 + }
  29 + if len(c.WorkerName) == 0 {
  30 + return errors.New("员工名字 必填")
  31 + }
  32 + if len(c.AmountLoss) == 0 {
  33 + return errors.New("损失金额 必填")
  34 + }
  35 + if len(c.TypesName) == 0 {
  36 + return errors.New("事故类型 必填")
  37 + }
  38 + return nil
  39 +}
  1 +package command
  2 +
  3 +//创建事故记录
  4 +type CreateProductTroubleCommand struct {
  5 + Id int `json:"id"` //id
  6 + WorkshopId int `json:"workshopId" valid:"Required"` //车间id
  7 + LineId int `json:"lineId" valid:"Required"` //生产线ID
  8 + SectionId int `json:"sectionId" valid:"Required"` //工段ID
  9 + WorkerId []int `json:"workerId"` //员工id //多选
  10 + Remark string `json:"remark"` //备注
  11 + AmountLoss float64 `json:"amountLoss"` // 损失的金额
  12 + Types string `json:"types"` // 事故类型 1 安全事故 ,2 质量事故, 3 金属事故 ,4 非金属事故
  13 + RecordDate string `json:"recordDate"` // 事故发生的日期
  14 + SaveAndApprove bool `json:"saveAndApprove"` //保存并审核
  15 +}
  1 +package command
  2 +
  3 +//保存事故记录
  4 +type SaveProductTroubleCommand struct {
  5 + Id int `json:"id"` //id
  6 + WorkshopId int `json:"workshopId" valid:"Required"` //车间id
  7 + LineId int `json:"lineId" valid:"Required"` //生产线ID
  8 + SectionId int `json:"sectionId" valid:"Required"` //工段ID
  9 + WorkerId int `json:"workerId"` //员工id
  10 + Remark string `json:"remark"` //备注
  11 + AmountLoss float64 `json:"amountLoss"` // 损失的金额
  12 + Types string `json:"types"` // 事故类型 1 安全事故 ,2 质量事故, 3 金属事故 ,4 非金属事故
  13 + RecordDate string `json:"recordDate"` // 事故发生的日期
  14 + SaveAndApprove bool `json:"saveAndApprove"` //保存并审核
  15 +}
  1 +package dto
  2 +
  3 +type ProductTroubleInfo struct {
  4 + Id int `json:"id"` //id
  5 + WorkshopId int `json:"workshopId"` //车间id
  6 + WorkshopName string `json:"workshopName"` //
  7 + LineId int `json:"lineId"` //生产线ID
  8 + LineName string `json:"lineName"` //
  9 + SectionId int `json:"sectionId"` //工段ID
  10 + SectionName string `json:"sectionName"` //
  11 + WorkerId int `json:"workerId"` //员工id
  12 + WorkerName string `json:"workerName"` //员工名称
  13 + Remark string `json:"remark"` //备注
  14 + ProductDate string `json:"productDate"` //日期
  15 + AmountLoss float64 `json:"amountLoss"` //损失的金额
  16 + Types string `json:"types"` //事故类型
  17 +}
  1 +package dto
  2 +
  3 +type ProductTroubleList struct {
  4 + Id int `json:"id"` //id
  5 + WorkshopId int `json:"workshopId"` //车间id
  6 + WorkshopName string `json:"workshopName"` //
  7 + LineId int `json:"lineId"` //生产线ID
  8 + LineName string `json:"lineName"` //
  9 + SectionId int `json:"sectionId"` //工段ID
  10 + SectionName string `json:"sectionName"` //
  11 + Remark string `json:"remark"` //备注
  12 + ProductDate string `json:"productDate"` //日期
  13 + AmountLoss float64 `json:"amountLoss"` //损失的金额
  14 + Types string `json:"types"` //事故类型
  15 + WorkerId int `json:"workerId"` //员工
  16 + WorkerName string `json:"workerName"` //员工名称
  17 + ApproveStatus int `json:"approveStatus"` //审核状态
  18 + ApproveStatusName string `json:"approveStatusName"` //审核状态
  19 +}
  1 +package dto
  2 +
  3 +type RewardSummaryList struct {
  4 + Id int `json:"id"`
  5 + RecordDate string `json:"recordDate"` //日期
  6 + WorkshopName string `json:"workshopName"` //车间名称
  7 + LineName string `json:"lineName"` //线别名称
  8 + SectionName string `json:"sectionName"` //工段
  9 + WorkerName string `json:"workerName"` //员工名字
  10 + Yield string `json:"yield"` //产效
  11 + UpToStandard string `json:"upToStandard"` //合格率
  12 + Accident1 string `json:"accident1"` //质量事故
  13 + Accident2 string `json:"accident2"` //安全事故
  14 + Accident3 string `json:"accident3"` //异物事故
  15 + SummaryResult string `json:"summaryResult"` //奖惩结果
  16 + ResultDesc string `json:"resultDesc"` //产效结果
  17 +}
  1 +package query
  2 +
  3 +type GetProductTroubleQuery struct {
  4 + // 生产记录ID
  5 + Id int `json:"id" valid:"Required"`
  6 +}
  1 +package query
  2 +
  3 +type ListProductTrouble struct {
  4 + // 当前公司
  5 + CompanyId int `cname:"当前公司" json:"companyId"`
  6 + // 当前登录的组织
  7 + OrgId int `cname:"当前登录的组织" json:"orgId"`
  8 + // 页码
  9 + PageNumber int `cname:"页码" json:"pageNumber"`
  10 + // 页数
  11 + PageSize int `cname:"页数" json:"pageSize"`
  12 + // 车间名称
  13 + WorkshopName string `cname:"车间名称" json:"workshopName"`
  14 + //员工名称
  15 + WorkerName string `cname:"员工名称" json:"workerName"`
  16 +}
  1 +package query
  2 +
  3 +type ListRewardSummaryQuery struct {
  4 + // 当前公司
  5 + CompanyId int `cname:"当前公司" json:"companyId"`
  6 + // 当前登录的组织
  7 + OrgId int `cname:"当前登录的组织" json:"orgId"`
  8 + // 页码
  9 + PageNumber int `cname:"页码" json:"pageNumber"`
  10 + // 页数
  11 + PageSize int `cname:"页数" json:"pageSize"`
  12 + // 车间名称
  13 + WorkshopName string `cname:"车间名称" json:"workshopName"`
  14 +
  15 + LineName string `cname:"线别名称" json:"lineName"`
  16 +
  17 + BeginDate string `cname:"开始的日期" json:"beginDate"`
  18 +
  19 + EndDate string `cname:"结束的日期" json:"endDate"`
  20 +}
  1 +package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
  8 +)
  9 +
  10 +//功过看板 展示(员工)
  11 +
  12 +// RewardSummaryPublicNoticeDay 功过看板 日榜
  13 +func (srv ProductTroubleService) RewardSummaryPublicNoticeDay() (map[string]interface{}, error) {
  14 + transactionContext, err := factory.CreateTransactionContext(nil)
  15 + if err != nil {
  16 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  17 + }
  18 + if err := transactionContext.StartTransaction(); err != nil {
  19 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  20 + }
  21 + defer func() {
  22 + transactionContext.RollbackTransaction()
  23 + }()
  24 + rewardSumaryDao, _ := dao.NewRewardSumaryDao(transactionContext.(*pgTransaction.TransactionContext))
  25 + sumaryData, err := rewardSumaryDao.SeachRewardSummaryDay(23, 487, "2022-10-29")
  26 + if err != nil {
  27 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  28 + }
  29 + if err := transactionContext.CommitTransaction(); err != nil {
  30 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  31 + }
  32 + result := map[string]interface{}{
  33 + "list": sumaryData,
  34 + "recordDay": "2022-10-29",
  35 + }
  36 +
  37 + return result, nil
  38 +}
  39 +
  40 +// RewardSummaryPublicNoticeYield 功过看板 产效
  41 +func (srv ProductTroubleService) RewardSummaryPublicNoticeYield() (map[string]interface{}, error) {
  42 +
  43 + transactionContext, err := factory.CreateTransactionContext(nil)
  44 + if err != nil {
  45 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  46 + }
  47 + if err := transactionContext.StartTransaction(); err != nil {
  48 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  49 + }
  50 + defer func() {
  51 + transactionContext.RollbackTransaction()
  52 + }()
  53 + rewardSumaryDao, _ := dao.NewRewardSumaryDao(transactionContext.(*pgTransaction.TransactionContext))
  54 + sumaryData, err := rewardSumaryDao.SeachRewardSummaryYield(23, 487, "2022-10-29")
  55 + if err != nil {
  56 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  57 + }
  58 + if err := transactionContext.CommitTransaction(); err != nil {
  59 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  60 + }
  61 + result := map[string]interface{}{
  62 + "list": sumaryData,
  63 + }
  64 +
  65 + return result, nil
  66 +
  67 +}
  68 +
  69 +// RewardSummaryPublicNoticeUpToStandard 功过看板 合格率
  70 +func (srv ProductTroubleService) RewardSummaryPublicNoticeUpToStandard() (map[string]interface{}, error) {
  71 +
  72 + transactionContext, err := factory.CreateTransactionContext(nil)
  73 + if err != nil {
  74 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  75 + }
  76 + if err := transactionContext.StartTransaction(); err != nil {
  77 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  78 + }
  79 + defer func() {
  80 + transactionContext.RollbackTransaction()
  81 + }()
  82 + rewardSumaryDao, _ := dao.NewRewardSumaryDao(transactionContext.(*pgTransaction.TransactionContext))
  83 + sumaryData, err := rewardSumaryDao.SeachRewardUpToStandard(23, 487, "2022-10-29")
  84 + if err != nil {
  85 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  86 + }
  87 + if err := transactionContext.CommitTransaction(); err != nil {
  88 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  89 + }
  90 + result := map[string]interface{}{
  91 + "list": sumaryData,
  92 + }
  93 +
  94 + return result, nil
  95 +}
  96 +
  97 +// RewardSummaryPublicNoticeDay 功过看板 异常
  98 +func (srv ProductTroubleService) RewardSummaryPublicNoticeAccident() (map[string]interface{}, error) {
  99 +
  100 + transactionContext, err := factory.CreateTransactionContext(nil)
  101 + if err != nil {
  102 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  103 + }
  104 + if err := transactionContext.StartTransaction(); err != nil {
  105 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  106 + }
  107 + defer func() {
  108 + transactionContext.RollbackTransaction()
  109 + }()
  110 + rewardSumaryDao, _ := dao.NewRewardSumaryDao(transactionContext.(*pgTransaction.TransactionContext))
  111 + sumaryData, err := rewardSumaryDao.SeachRewardAccident(23, 487, "2022-10-29")
  112 + if err != nil {
  113 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  114 + }
  115 + if err := transactionContext.CommitTransaction(); err != nil {
  116 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  117 + }
  118 + result := map[string]interface{}{
  119 + "list": sumaryData,
  120 + }
  121 + return result, nil
  122 +}
  123 +
  124 +// RewardSummaryPublicNoticeDay 功过看板 月榜
  125 +func (srv ProductTroubleService) RewardSummaryPublicNoticeMonth() (map[string]interface{}, error) {
  126 +
  127 + transactionContext, err := factory.CreateTransactionContext(nil)
  128 + if err != nil {
  129 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  130 + }
  131 + if err := transactionContext.StartTransaction(); err != nil {
  132 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  133 + }
  134 + defer func() {
  135 + transactionContext.RollbackTransaction()
  136 + }()
  137 + rewardSumaryDao, _ := dao.NewRewardSumaryDao(transactionContext.(*pgTransaction.TransactionContext))
  138 + sumaryData, err := rewardSumaryDao.SeachRewardSummaryMonth(23, 487, "2022-10")
  139 + if err != nil {
  140 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  141 + }
  142 + if err := transactionContext.CommitTransaction(); err != nil {
  143 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  144 + }
  145 + result := map[string]interface{}{
  146 + "list": sumaryData,
  147 + }
  148 + return result, nil
  149 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "strconv"
  6 + "strings"
  7 + "time"
  8 +
  9 + "github.com/linmadan/egglib-go/core/application"
  10 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  12 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productTrouble/command"
  13 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productTrouble/dto"
  14 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productTrouble/query"
  15 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  16 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
  17 +)
  18 +
  19 +// 事故管理
  20 +type ProductTroubleService struct{}
  21 +
  22 +func NewProductTroubleService(options map[string]interface{}) *ProductTroubleService {
  23 + newService := &ProductTroubleService{}
  24 + return newService
  25 +}
  26 +
  27 +func (srv ProductTroubleService) SaveProductTrouble(operateInfo *domain.OperateInfo, param *command.SaveProductTroubleCommand) (map[string]interface{}, error) {
  28 + transactionContext, err := factory.CreateTransactionContext(nil)
  29 + if err != nil {
  30 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  31 + }
  32 + if err := transactionContext.StartTransaction(); err != nil {
  33 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  34 + }
  35 + defer func() {
  36 + transactionContext.RollbackTransaction()
  37 + }()
  38 +
  39 + productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
  40 + "transactionContext": transactionContext,
  41 + })
  42 + workShopRepo, _ := factory.CreateWorkshopRepository(map[string]interface{}{
  43 + "transactionContext": transactionContext,
  44 + })
  45 + //获取车间数据
  46 + workShopData, err := workShopRepo.FindOne(map[string]interface{}{
  47 + "workshopId": param.WorkshopId,
  48 + })
  49 + if err != nil {
  50 + return nil, application.ThrowError(application.ARG_ERROR, "车间数据不能存在"+err.Error())
  51 + }
  52 + if workShopData.CompanyId != operateInfo.CompanyId {
  53 + return nil, application.ThrowError(application.ARG_ERROR, "车间数据填写错误")
  54 + }
  55 + workStation, err := workShopData.FindWorkStation(param.WorkshopId, param.LineId, param.SectionId)
  56 + if err != nil {
  57 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  58 + }
  59 +
  60 + recordDate, err := time.ParseInLocation("2006-01-02", param.RecordDate, time.Local)
  61 + if err != nil {
  62 + return nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
  63 + }
  64 + var workerUser *domain.User
  65 + userService := domainService.NewUserService()
  66 + workerUser, err = userService.User(param.WorkerId)
  67 + if err != nil {
  68 + return nil, application.ThrowError(application.ARG_ERROR, "获取员工信息失败,"+err.Error())
  69 + }
  70 + var troubleData *domain.ProductTrouble
  71 + if param.Id > 0 {
  72 + troubleData, err = productTroubleRepo.FindOne(map[string]interface{}{
  73 + "id": param.Id,
  74 + })
  75 + if err != nil {
  76 + return nil, application.ThrowError(application.ARG_ERROR, "事故数据填写错误")
  77 + }
  78 + } else {
  79 + troubleData = &domain.ProductTrouble{
  80 + CompanyId: operateInfo.CompanyId,
  81 + OrgId: operateInfo.OrgId,
  82 + CreatedAt: time.Now(),
  83 + ApproveStatus: domain.TroubleWaitApprove,
  84 + }
  85 + }
  86 +
  87 + troubleData.AmountLoss = param.AmountLoss
  88 + troubleData.ProductWorker = *workerUser
  89 + troubleData.RecordDate = recordDate
  90 + troubleData.Remark = param.Remark
  91 + troubleData.UpdatedAt = time.Now()
  92 + troubleData.WorkStation = *workStation
  93 + err = troubleData.SetTypes(param.Types)
  94 + if err != nil {
  95 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  96 + }
  97 + if param.SaveAndApprove {
  98 + var approveUser *domain.User
  99 + userService := domainService.NewUserService()
  100 + approveUser, err = userService.User(operateInfo.UserId)
  101 + if err != nil {
  102 + return nil, application.ThrowError(application.ARG_ERROR, "获取审核人信息失败,"+err.Error())
  103 + }
  104 + err = troubleData.Approve(approveUser)
  105 + if err != nil {
  106 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  107 + }
  108 + }
  109 + _, err = productTroubleRepo.Save(troubleData)
  110 + if err != nil {
  111 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  112 + }
  113 + if param.SaveAndApprove {
  114 + summaryServe, _ := domainService.NewPGRewardSummaryStaticService(transactionContext.(*pgTransaction.TransactionContext))
  115 + err = summaryServe.CreateRewardSummaryByProductTrouble(troubleData)
  116 + if err != nil {
  117 + return nil, application.ThrowError(application.ARG_ERROR, "计算功过奖惩明细失败,"+err.Error())
  118 + }
  119 + }
  120 + if err := transactionContext.CommitTransaction(); err != nil {
  121 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  122 + }
  123 + return map[string]interface{}{
  124 + "id": troubleData.Id,
  125 + }, nil
  126 +}
  127 +
  128 +func (srv ProductTroubleService) GetProductTrouble(id int) (*dto.ProductTroubleInfo, error) {
  129 + transactionContext, err := factory.CreateTransactionContext(nil)
  130 + if err != nil {
  131 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  132 + }
  133 + if err := transactionContext.StartTransaction(); err != nil {
  134 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  135 + }
  136 + defer func() {
  137 + transactionContext.RollbackTransaction()
  138 + }()
  139 +
  140 + productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
  141 + "transactionContext": transactionContext,
  142 + })
  143 + troubleData, err := productTroubleRepo.FindOne(map[string]interface{}{
  144 + "id": id,
  145 + })
  146 + if err != nil {
  147 + return nil, application.ThrowError(application.ARG_ERROR, "事故数据不存在,"+err.Error())
  148 + }
  149 + if err := transactionContext.CommitTransaction(); err != nil {
  150 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  151 + }
  152 +
  153 + result := dto.ProductTroubleInfo{
  154 + Id: troubleData.Id,
  155 + WorkshopId: troubleData.WorkStation.WorkshopId,
  156 + WorkshopName: troubleData.WorkStation.WorkshopName,
  157 + LineId: troubleData.WorkStation.LineId,
  158 + LineName: troubleData.WorkStation.LineName,
  159 + SectionId: troubleData.WorkStation.SectionId,
  160 + SectionName: troubleData.WorkStation.SectionName,
  161 + Remark: troubleData.Remark,
  162 + ProductDate: troubleData.RecordDate.Format("2006-01-02"),
  163 + AmountLoss: troubleData.AmountLoss,
  164 + Types: string(troubleData.Types),
  165 + WorkerId: troubleData.ProductWorker.UserId,
  166 + WorkerName: troubleData.ProductWorker.UserName,
  167 + }
  168 + return &result, nil
  169 +}
  170 +
  171 +func (srv ProductTroubleService) DeleteProductTrouble(id int64) error {
  172 + transactionContext, err := factory.CreateTransactionContext(nil)
  173 + if err != nil {
  174 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  175 + }
  176 + if err := transactionContext.StartTransaction(); err != nil {
  177 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  178 + }
  179 + defer func() {
  180 + transactionContext.RollbackTransaction()
  181 + }()
  182 + productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
  183 + "transactionContext": transactionContext,
  184 + })
  185 + troubleData, err := productTroubleRepo.FindOne(map[string]interface{}{
  186 + "id": id,
  187 + })
  188 + if err != nil {
  189 + return application.ThrowError(application.ARG_ERROR, "事故数据不存在,"+err.Error())
  190 + }
  191 + _, err = productTroubleRepo.Remove(troubleData)
  192 + if err != nil {
  193 + return application.ThrowError(application.ARG_ERROR, err.Error())
  194 + }
  195 + if err := transactionContext.CommitTransaction(); err != nil {
  196 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  197 + }
  198 + return nil
  199 +}
  200 +
  201 +// 审核事故
  202 +func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.OperateInfo, id int64) error {
  203 + transactionContext, err := factory.CreateTransactionContext(nil)
  204 + if err != nil {
  205 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  206 + }
  207 + if err := transactionContext.StartTransaction(); err != nil {
  208 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  209 + }
  210 + defer func() {
  211 + transactionContext.RollbackTransaction()
  212 + }()
  213 + productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
  214 + "transactionContext": transactionContext,
  215 + })
  216 + troubleData, err := productTroubleRepo.FindOne(map[string]interface{}{
  217 + "id": id,
  218 + })
  219 + if err != nil {
  220 + return application.ThrowError(application.ARG_ERROR, "事故数据不存在,"+err.Error())
  221 + }
  222 + var approveUser *domain.User
  223 + userService := domainService.NewUserService()
  224 + approveUser, err = userService.User(operateInfo.UserId)
  225 + if err != nil {
  226 + return application.ThrowError(application.ARG_ERROR, "获取审核人信息失败,"+err.Error())
  227 + }
  228 + err = troubleData.Approve(approveUser)
  229 + if err != nil {
  230 + return application.ThrowError(application.ARG_ERROR, err.Error())
  231 + }
  232 +
  233 + troubleData.UpdatedAt = time.Now()
  234 + _, err = productTroubleRepo.Save(troubleData)
  235 + if err != nil {
  236 + return application.ThrowError(application.ARG_ERROR, err.Error())
  237 + }
  238 +
  239 + //汇总奖惩明细
  240 + summaryServe, _ := domainService.NewPGRewardSummaryStaticService(transactionContext.(*pgTransaction.TransactionContext))
  241 + err = summaryServe.CreateRewardSummaryByProductTrouble(troubleData)
  242 + if err != nil {
  243 + return application.ThrowError(application.ARG_ERROR, "计算功过奖惩明细失败,"+err.Error())
  244 + }
  245 + if err := transactionContext.CommitTransaction(); err != nil {
  246 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  247 + }
  248 + return nil
  249 +}
  250 +
  251 +// ListProductTrouble 事故管理列表
  252 +func (srv ProductTroubleService) ListProductTrouble(param *query.ListProductTrouble) (int64, []dto.ProductTroubleList, error) {
  253 + transactionContext, err := factory.CreateTransactionContext(nil)
  254 + if err != nil {
  255 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  256 + }
  257 + if err := transactionContext.StartTransaction(); err != nil {
  258 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  259 + }
  260 + defer func() {
  261 + transactionContext.RollbackTransaction()
  262 + }()
  263 +
  264 + productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
  265 + "transactionContext": transactionContext,
  266 + })
  267 + limit := param.PageSize
  268 + offset := param.PageSize * (param.PageNumber - 1)
  269 + condition := map[string]interface{}{
  270 + "limit": limit,
  271 + "offset": offset,
  272 + "companyId": param.CompanyId,
  273 + "orgId": param.OrgId,
  274 + }
  275 +
  276 + if len(param.WorkerName) > 0 {
  277 + condition["productWorkerName"] = param.WorkerName
  278 + }
  279 +
  280 + if len(param.WorkshopName) > 0 {
  281 + condition["workshopName"] = param.WorkshopName
  282 + }
  283 + cnt, troubleDataList, err := productTroubleRepo.Find(condition)
  284 + if err != nil {
  285 + return 0, nil, application.ThrowError(application.ARG_ERROR, "事故数据不存在,"+err.Error())
  286 + }
  287 + if err := transactionContext.CommitTransaction(); err != nil {
  288 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  289 + }
  290 +
  291 + result := []dto.ProductTroubleList{}
  292 + var item dto.ProductTroubleList
  293 + for _, v := range troubleDataList {
  294 + item = dto.ProductTroubleList{
  295 + Id: v.Id,
  296 + WorkshopId: v.WorkStation.WorkshopId,
  297 + WorkshopName: v.WorkStation.WorkshopName,
  298 + LineId: v.WorkStation.LineId,
  299 + LineName: v.WorkStation.LineName,
  300 + SectionId: v.WorkStation.SectionId,
  301 + SectionName: v.WorkStation.SectionName,
  302 + Remark: v.Remark,
  303 + ProductDate: v.RecordDate.Local().Format("2006-01-02"),
  304 + AmountLoss: v.AmountLoss,
  305 + Types: v.GetTypesName(),
  306 + WorkerId: v.ProductWorker.UserId,
  307 + WorkerName: v.ProductWorker.UserName,
  308 + ApproveStatus: int(v.ApproveStatus),
  309 + ApproveStatusName: v.GetApproveStatusName(),
  310 + }
  311 + result = append(result, item)
  312 + }
  313 +
  314 + return cnt, result, nil
  315 +}
  316 +
  317 +// 批量添加事故数据
  318 +func (srv ProductTroubleService) BatchAddProductTrouble(operateInfo *domain.OperateInfo, param []command.BatchAddProductTroubleCommand) (failRows []interface{}, err error) {
  319 + transactionContext, err := factory.CreateTransactionContext(nil)
  320 + if err != nil {
  321 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  322 + }
  323 + if err := transactionContext.StartTransaction(); err != nil {
  324 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  325 + }
  326 + defer func() {
  327 + transactionContext.RollbackTransaction()
  328 + }()
  329 +
  330 + //获取当前操作人
  331 + userSrv := domainService.NewUserService()
  332 + operateUser, err := userSrv.User(operateInfo.UserId)
  333 + if err != nil {
  334 + return nil, application.ThrowError(application.TRANSACTION_ERROR, "查询操作人数据失败。"+err.Error())
  335 + }
  336 + //车间数据
  337 + workshopRepo, _ := factory.CreateWorkshopRepository(map[string]interface{}{
  338 + "transactionContext": transactionContext,
  339 + })
  340 +
  341 + //获取车间列表
  342 + _, workshopList, err := workshopRepo.Find(map[string]interface{}{
  343 + "companyId": operateInfo.CompanyId,
  344 + "orgId": operateInfo.OrgId,
  345 + })
  346 + if err != nil {
  347 + return nil, application.ThrowError(application.BUSINESS_ERROR, "获取车间列表失败"+err.Error())
  348 + }
  349 + //生产班组 数据
  350 + productGroupRepo, _ := factory.CreateProductGroupRepository(map[string]interface{}{
  351 + "transactionContext": transactionContext,
  352 + })
  353 + _, productGroupList, err := productGroupRepo.Find(map[string]interface{}{
  354 + "companyId": operateInfo.CompanyId,
  355 + "orgId": operateInfo.OrgId,
  356 + })
  357 + if err != nil {
  358 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  359 + }
  360 +
  361 + //车间名称+/+工人名 作为键名
  362 + workerMap := map[string][]*domain.User{}
  363 + //班组名称 作为键名
  364 + // productGroupMap := map[string]*domain.ProductGroup{}
  365 + for _, v := range productGroupList {
  366 + // productGroupMap[v.GroupName] = v
  367 + for _, vv := range v.GroupMembers {
  368 + k := v.WorkStation.WorkshopName + "/" + vv.UserName
  369 + isIn := false
  370 + for _, vvv := range workerMap[k] {
  371 + if vvv.UserId == vv.UserId {
  372 + isIn = true
  373 + break
  374 + }
  375 + }
  376 + if !isIn {
  377 + workerMap[k] = append(workerMap[k], vv)
  378 + }
  379 + }
  380 + }
  381 + //车间名称+/+线别名称+/+工段名称 作为键名
  382 + workStationMap := map[string]*domain.WorkStation{}
  383 + for _, v := range workshopList {
  384 + for _, v2 := range v.ProductLines {
  385 + for _, v3 := range v2.ProductSections {
  386 + workStationName := strings.Join([]string{
  387 + v.WorkshopName, v2.LineName, v3.SectionName,
  388 + }, "/")
  389 + workStationMap[workStationName] = domain.NewWorkStation(v, v2, v3)
  390 + }
  391 + }
  392 + }
  393 +
  394 + troubleDataList := make([]*domain.ProductTrouble, 0, len(param))
  395 + nowTime := time.Now()
  396 + for i := range param {
  397 + //检查字段
  398 + err = param[i].ValidField()
  399 + if err != nil {
  400 + param[i].FailReason = err.Error()
  401 + failRows = append(failRows, param[i])
  402 + continue
  403 + }
  404 + //检查日期格式
  405 + recordDate, err := time.ParseInLocation("2006-01-02", param[i].RecordDate, time.Local)
  406 + if err != nil {
  407 + param[i].FailReason = "日期格式错误,例 2006-01-02。"
  408 + failRows = append(failRows, param[i])
  409 + continue
  410 + }
  411 + //检查工位
  412 + var workStation *domain.WorkStation
  413 + workStationName := param[i].WorkshopName + "/" + param[i].LineName + "/" + param[i].SectionName
  414 + if v, ok := workStationMap[workStationName]; ok {
  415 + workStation = v
  416 + } else {
  417 + param[i].FailReason = "车间、线别、工段不存在"
  418 + failRows = append(failRows, param[i])
  419 + continue
  420 + }
  421 + //检查员工姓名
  422 + var worker *domain.User
  423 + workKey := param[i].WorkshopName + "/" + param[i].WorkerName
  424 + if u, ok := workerMap[workKey]; ok {
  425 + if len(u) > 1 {
  426 + param[i].FailReason = "当前车间存在重复的用户名"
  427 + failRows = append(failRows, param[i])
  428 + continue
  429 + }
  430 + worker = u[0]
  431 + } else {
  432 + param[i].FailReason = "当前车间不存在用户" + param[i].WorkerName
  433 + failRows = append(failRows, param[i])
  434 + continue
  435 + }
  436 + //损失金额
  437 + amountLoss, err := strconv.ParseFloat(param[i].AmountLoss, 64)
  438 + if err != nil {
  439 + param[i].FailReason = "损失金额填写错误"
  440 + failRows = append(failRows, param[i])
  441 + continue
  442 + }
  443 + item := &domain.ProductTrouble{
  444 + Id: 0,
  445 + CompanyId: operateInfo.CompanyId,
  446 + OrgId: operateInfo.OrgId,
  447 + WorkStation: *workStation,
  448 + ProductWorker: *worker,
  449 + AmountLoss: amountLoss,
  450 + Types: "",
  451 + RecordDate: recordDate,
  452 + Remark: "",
  453 + ApproveStatus: domain.TroubleIsApprove,
  454 + ApproveAt: &nowTime,
  455 + ApproveUser: operateUser,
  456 + CreatedAt: nowTime,
  457 + UpdatedAt: nowTime,
  458 + DeletedAt: nil,
  459 + }
  460 + err = item.SetTypes(param[i].TypesName)
  461 + if err != nil {
  462 + param[i].FailReason = "事故类型填写错误"
  463 + failRows = append(failRows, param[i])
  464 + continue
  465 + }
  466 + troubleDataList = append(troubleDataList, item)
  467 + }
  468 +
  469 + if len(failRows) > 0 {
  470 + return failRows, nil
  471 + }
  472 + productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
  473 + "transactionContext": transactionContext,
  474 + })
  475 + summaryServe, _ := domainService.NewPGRewardSummaryStaticService(transactionContext.(*pgTransaction.TransactionContext))
  476 + for i := range troubleDataList {
  477 + //添加事故数据
  478 + _, err = productTroubleRepo.Save(troubleDataList[i])
  479 + if err != nil {
  480 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  481 + }
  482 + //汇总奖惩明细
  483 + err = summaryServe.CreateRewardSummaryByProductTrouble(troubleDataList[i])
  484 + if err != nil {
  485 + return nil, application.ThrowError(application.ARG_ERROR, "计算功过奖惩明细失败,"+err.Error())
  486 + }
  487 + }
  488 +
  489 + if err := transactionContext.CommitTransaction(); err != nil {
  490 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  491 + }
  492 + return nil, nil
  493 +}
  494 +
  495 +// 奖惩汇总数据列表
  496 +func (srv ProductTroubleService) ListRewardSummary(param *query.ListRewardSummaryQuery) (int64, []dto.RewardSummaryList, error) {
  497 +
  498 + transactionContext, err := factory.CreateTransactionContext(nil)
  499 + if err != nil {
  500 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  501 + }
  502 + if err := transactionContext.StartTransaction(); err != nil {
  503 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  504 + }
  505 + defer func() {
  506 + transactionContext.RollbackTransaction()
  507 + }()
  508 +
  509 + rewardSummaryRepo, _ := factory.CreateRewardSummaryRepository(map[string]interface{}{
  510 + "transactionContext": transactionContext,
  511 + })
  512 + limit := param.PageSize
  513 + offset := param.PageSize * (param.PageNumber - 1)
  514 + condition := map[string]interface{}{
  515 + "orgId": param.OrgId,
  516 + "companyId": param.CompanyId,
  517 + "offset": offset,
  518 + "limit": limit,
  519 + }
  520 + //搜索条件日期
  521 + if len(param.BeginDate) > 0 {
  522 + beginDate, err := time.ParseInLocation("2006-01-02", param.BeginDate, time.Local)
  523 + if err != nil {
  524 + return 0, nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
  525 + } else {
  526 + condition["beginDate"] = beginDate
  527 + }
  528 +
  529 + }
  530 + //搜索条件日期
  531 + if len(param.EndDate) > 0 {
  532 + endDate, err := time.ParseInLocation("2006-01-02", param.EndDate, time.Local)
  533 + if err != nil {
  534 + return 0, nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
  535 + } else {
  536 + endDate = endDate.Add((86400 - 1) * time.Second)
  537 + condition["endDate"] = endDate
  538 + }
  539 +
  540 + }
  541 + //搜索条件 车间名称
  542 + if len(param.WorkshopName) > 0 {
  543 + condition["workshopName"] = param.WorkshopName
  544 + }
  545 + //搜索条件 线别名称
  546 + if len(param.LineName) > 0 {
  547 + condition["lineName"] = param.LineName
  548 + }
  549 +
  550 + cnt, rewardSummaryList, err := rewardSummaryRepo.Find(condition)
  551 + if err != nil {
  552 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  553 + }
  554 + if err := transactionContext.CommitTransaction(); err != nil {
  555 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  556 + }
  557 +
  558 + result := []dto.RewardSummaryList{}
  559 + for _, v := range rewardSummaryList {
  560 + item := dto.RewardSummaryList{
  561 + Id: v.Id,
  562 + RecordDate: v.RecordDate.Local().Format("2006-01-02"),
  563 + WorkshopName: v.WorkStation.WorkshopName,
  564 + LineName: v.WorkStation.LineName,
  565 + SectionName: v.WorkStation.SectionName,
  566 + WorkerName: v.Worker.UserName,
  567 + Yield: fmt.Sprintf("%.2f", v.Yield),
  568 + UpToStandard: fmt.Sprintf("%.2f%%", v.UpToStandard),
  569 + Accident1: fmt.Sprintf("%d次%.2f元", v.AccidentNum1, v.AccidentAmount1),
  570 + Accident2: fmt.Sprintf("%d次%.2f元", v.AccidentNum2, v.AccidentAmount2),
  571 + Accident3: fmt.Sprintf("金属%d次,非金属%d次", v.AccidentNum3, v.AccidentNum4),
  572 + SummaryResult: fmt.Sprintf("%v", v.SummaryResult),
  573 + ResultDesc: "",
  574 + }
  575 + if v.SummaryResult == 0 {
  576 + item.ResultDesc = "不奖不惩"
  577 + } else if v.SummaryResult > 0 {
  578 + item.ResultDesc = "奖"
  579 + } else {
  580 + item.ResultDesc = "惩"
  581 + }
  582 + result = append(result, item)
  583 + }
  584 + return cnt, result, nil
  585 +}
  586 +
  587 +// 创建事故数据
  588 +func (srv ProductTroubleService) CreateProductTrouble(operateInfo *domain.OperateInfo, param *command.CreateProductTroubleCommand) (map[string]interface{}, error) {
  589 + transactionContext, err := factory.CreateTransactionContext(nil)
  590 + if err != nil {
  591 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  592 + }
  593 + if err := transactionContext.StartTransaction(); err != nil {
  594 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  595 + }
  596 + defer func() {
  597 + transactionContext.RollbackTransaction()
  598 + }()
  599 +
  600 + productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
  601 + "transactionContext": transactionContext,
  602 + })
  603 + workShopRepo, _ := factory.CreateWorkshopRepository(map[string]interface{}{
  604 + "transactionContext": transactionContext,
  605 + })
  606 + //获取车间数据
  607 + workShopData, err := workShopRepo.FindOne(map[string]interface{}{
  608 + "workshopId": param.WorkshopId,
  609 + })
  610 + if err != nil {
  611 + return nil, application.ThrowError(application.ARG_ERROR, "车间数据不能存在"+err.Error())
  612 + }
  613 + if workShopData.CompanyId != operateInfo.CompanyId {
  614 + return nil, application.ThrowError(application.ARG_ERROR, "车间数据填写错误")
  615 + }
  616 + workStation, err := workShopData.FindWorkStation(param.WorkshopId, param.LineId, param.SectionId)
  617 + if err != nil {
  618 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  619 + }
  620 +
  621 + recordDate, err := time.ParseInLocation("2006-01-02", param.RecordDate, time.Local)
  622 + if err != nil {
  623 + return nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
  624 + }
  625 +
  626 + var operaterUser *domain.User
  627 + userService := domainService.NewUserService()
  628 + operaterUser, err = userService.User(operateInfo.UserId)
  629 + if err != nil {
  630 + return nil, application.ThrowError(application.ARG_ERROR, "获取审核人信息失败,"+err.Error())
  631 + }
  632 + for _, workerId := range param.WorkerId {
  633 + var workerUser *domain.User
  634 + workerUser, err = userService.User(workerId)
  635 + if err != nil {
  636 + return nil, application.ThrowError(application.ARG_ERROR, "获取员工信息失败,"+err.Error())
  637 + }
  638 + var troubleData *domain.ProductTrouble
  639 + if param.Id > 0 {
  640 + troubleData, err = productTroubleRepo.FindOne(map[string]interface{}{
  641 + "id": param.Id,
  642 + })
  643 + if err != nil {
  644 + return nil, application.ThrowError(application.ARG_ERROR, "事故数据填写错误")
  645 + }
  646 + } else {
  647 + troubleData = &domain.ProductTrouble{
  648 + CompanyId: operateInfo.CompanyId,
  649 + OrgId: operateInfo.OrgId,
  650 + CreatedAt: time.Now(),
  651 + ApproveStatus: domain.TroubleWaitApprove,
  652 + }
  653 + }
  654 +
  655 + troubleData.AmountLoss = param.AmountLoss
  656 + troubleData.ProductWorker = *workerUser
  657 + troubleData.RecordDate = recordDate
  658 + troubleData.Remark = param.Remark
  659 + troubleData.UpdatedAt = time.Now()
  660 + troubleData.WorkStation = *workStation
  661 + err = troubleData.SetTypes(param.Types)
  662 + if err != nil {
  663 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  664 + }
  665 + if param.SaveAndApprove {
  666 + err = troubleData.Approve(operaterUser)
  667 + if err != nil {
  668 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  669 + }
  670 + }
  671 + _, err = productTroubleRepo.Save(troubleData)
  672 + if err != nil {
  673 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  674 + }
  675 +
  676 + }
  677 + if err := transactionContext.CommitTransaction(); err != nil {
  678 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  679 + }
  680 + return map[string]interface{}{}, nil
  681 +}
  1 +package command
  2 +
  3 +type SaveRewardRuleCommand struct {
  4 + // RewardTag string `json:"rewardTag"`
  5 + RewardNum int `json:"rewardNum"`
  6 + RewardAmount string `json:"rewardAmount"`
  7 + // FaultTag string `json:"faultTag"`
  8 + FaultNum int `json:"faultNum"`
  9 + FaultAmount string `json:"faultAmount"`
  10 + Remark string `json:"remark"`
  11 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type SaveRewardStandardCommand struct {
  12 + Id int `json:"id"` //奖惩标准 id
  13 + WorkshopId int `json:"workshopId" valid:"Required"` //车间id
  14 + LineId int `json:"lineId" valid:"Required"` //生产线ID
  15 + SectionId int `json:"sectionId" valid:"Required"` //工段ID
  16 + Remark string `json:"remark"` //备注
  17 + TargetType int `json:"targetType" valid:"Required"` //指标类别 1:产效 2:合格率 3:安全事故 4:质量事故 5:异物次数
  18 + TargeVal1 string `json:"targeVal1"` //填写的指标值1
  19 + TargeVal2 string `json:"targeVal2"` //填写的指标值2
  20 + TargeVal3 string `json:"targeVal3"` //填写的指标值3
  21 + TargeVal4 string `json:"targeVal4"` //填写的指标值4
  22 +}
  23 +
  24 +func (removeProductCommand *SaveRewardStandardCommand) Valid(validation *validation.Validation) {
  25 +
  26 +}
  27 +
  28 +func (removeProductCommand *SaveRewardStandardCommand) ValidateCommand() error {
  29 + valid := validation.Validation{}
  30 + b, err := valid.Valid(removeProductCommand)
  31 + if err != nil {
  32 + return err
  33 + }
  34 + if !b {
  35 + elem := reflect.TypeOf(removeProductCommand).Elem()
  36 + for _, validErr := range valid.Errors {
  37 + field, isExist := elem.FieldByName(validErr.Field)
  38 + if isExist {
  39 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  40 + } else {
  41 + return fmt.Errorf(validErr.Message)
  42 + }
  43 + }
  44 + }
  45 + return nil
  46 +}
  1 +package dto
  2 +
  3 +type RewardRuleInfo struct {
  4 + RewardNum int `json:"rewardNum"`
  5 + RewardAmount string `json:"rewardAmount"`
  6 + FaultNum int `json:"faultNum"`
  7 + FaultAmount string `json:"faultAmount"`
  8 + Remark string `json:"remark"`
  9 +}
  1 +package dto
  2 +
  3 +type RewardStandardInfo struct {
  4 + Id int `json:"id"` //奖惩标准id
  5 + WorkshopId int `json:"workshopId"` //车间id
  6 + WorkshopName string `json:"workshopName"` //
  7 + LineId int `json:"lineId"` //生产线ID
  8 + LineName string `json:"lineName"` //
  9 + SectionId int `json:"sectionId"` //工段ID
  10 + SectionName string `json:"sectionName"` //
  11 + Remark string `json:"remark"` //备注
  12 + TargetType int `json:"targetType"` //指标类别 1:产效 2:合格率 3:安全事故 4:质量事故 5:异物次数
  13 + TargeVal1 string `json:"targeVal1"` //填写的指标值1
  14 + TargeVal2 string `json:"targeVal2"` //填写的指标值2
  15 + TargeVal3 string `json:"targeVal3"` //填写的指标值3
  16 + TargeVal4 string `json:"targeVal4"` //填写的指标值4
  17 +
  18 +}
  1 +package dto
  2 +
  3 +type RewardStandardList struct {
  4 + Id int `json:"id"` //奖惩标准id
  5 + WorkshopId int `json:"workshopId"` //车间id
  6 + WorkshopName string `json:"workshopName"` //车间名称
  7 + LineId int `json:"lineId"` //生产线ID
  8 + LineName string `json:"lineName"` //生产线名称
  9 + SectionId int `json:"sectionId"` //工段ID
  10 + SectionName string `json:"sectionName"` //工段名称
  11 + Remark string `json:"remark"` //备注
  12 + TargetType int `json:"targetType"` //指标类别 1:产效 2:合格率 3:安全事故 4:质量事故 5:异物次数
  13 + TargetTypeName string `json:"targetTypeName"` //指标类别
  14 + TargeReward string `json:"targeReward"` //描述功劳指标
  15 + TargeFault string `json:"targeFault"` //描述过失指标
  16 +
  17 +}
  1 +package query
  2 +
  3 +type GetRewardStandard struct {
  4 + Id int `json:"id"`
  5 +}
  1 +package query
  2 +
  3 +type ListRewardStandard struct {
  4 + // 当前公司
  5 + CompanyId int `cname:"当前公司" json:"companyId"`
  6 + // 当前登录的组织
  7 + OrgId int `cname:"当前登录的组织" json:"orgId"`
  8 + // 页码
  9 + PageNumber int `cname:"页码" json:"pageNumber"`
  10 + // 页数
  11 + PageSize int `cname:"页数" json:"pageSize"`
  12 + // 车间名称
  13 + WorkshopName string `cname:"车间名称" json:"workshopName"`
  14 + // 线别名称
  15 + LineName string `cname:"线别名称" json:"lineName"`
  16 + // 工段名称
  17 + SectionName string `cname:"工段名称" json:"sectionName"`
  18 +}
  1 +package service
  2 +
  3 +import (
  4 + "time"
  5 +
  6 + "github.com/linmadan/egglib-go/core/application"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/rewardStandard/command"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/rewardStandard/dto"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/rewardStandard/query"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  12 +)
  13 +
  14 +type RewardStandardService struct{}
  15 +
  16 +func NewRewardStandardService(options map[string]interface{}) *RewardStandardService {
  17 + newService := &RewardStandardService{}
  18 + return newService
  19 +}
  20 +
  21 +// SaveRewardStandard 保存奖惩标准数据
  22 +func (srv RewardStandardService) SaveRewardStandard(operateInfo *domain.OperateInfo, param *command.SaveRewardStandardCommand) (*command.SaveRewardStandardCommand, error) {
  23 + if err := param.ValidateCommand(); err != nil {
  24 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  25 + }
  26 + transactionContext, err := factory.CreateTransactionContext(nil)
  27 + if err != nil {
  28 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  29 + }
  30 + if err := transactionContext.StartTransaction(); err != nil {
  31 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  32 + }
  33 + defer func() {
  34 + transactionContext.RollbackTransaction()
  35 + }()
  36 +
  37 + rewardStandardRepo, _ := factory.CreateRewardStandardRepository(map[string]interface{}{
  38 + "transactionContext": transactionContext,
  39 + })
  40 +
  41 + _, dataList, err := rewardStandardRepo.Find(map[string]interface{}{
  42 + "limit": 1,
  43 + "workshopId": param.WorkshopId,
  44 + "lineId": param.LineId,
  45 + "sectionId": param.SectionId,
  46 + "targetType": param.TargetType,
  47 + })
  48 + if err != nil {
  49 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  50 + }
  51 + if len(dataList) > 0 {
  52 + if dataList[0].Id != param.Id {
  53 + return nil, application.ThrowError(application.BUSINESS_ERROR, "当前指标已存在")
  54 + }
  55 + }
  56 + var rewardStandardData *domain.RewardStandard
  57 + if param.Id > 0 {
  58 + rewardStandardData, err = rewardStandardRepo.FindOne(map[string]interface{}{
  59 + "id": param.Id,
  60 + })
  61 + if err != nil {
  62 + return nil, application.ThrowError(application.BUSINESS_ERROR, "指标数据不存在"+err.Error())
  63 + }
  64 + if rewardStandardData.CompanyId != operateInfo.CompanyId {
  65 + return nil, application.ThrowError(application.BUSINESS_ERROR, "指标数据填写错误")
  66 + }
  67 +
  68 + } else {
  69 + rewardStandardData = &domain.RewardStandard{
  70 + CreatedAt: time.Now(),
  71 + }
  72 + }
  73 +
  74 + workShopRepo, _ := factory.CreateWorkshopRepository(map[string]interface{}{
  75 + "transactionContext": transactionContext,
  76 + })
  77 + //获取车间数据
  78 + workShopData, err := workShopRepo.FindOne(map[string]interface{}{
  79 + "workshopId": param.WorkshopId,
  80 + })
  81 + if err != nil {
  82 + return nil, application.ThrowError(application.ARG_ERROR, "车间数据不能存在"+err.Error())
  83 + }
  84 + if workShopData.CompanyId != operateInfo.CompanyId {
  85 + return nil, application.ThrowError(application.ARG_ERROR, "车间数据填写错误")
  86 + }
  87 +
  88 + productLineData, err := workShopData.FindLine(param.LineId)
  89 + if err != nil {
  90 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  91 + }
  92 + productSection, err := productLineData.FindSection(param.SectionId)
  93 + if err != nil {
  94 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  95 + }
  96 + rewardStandardData.UpdatedAt = time.Now()
  97 + rewardStandardData.ProductSection = *productSection
  98 + rewardStandardData.ProductLine = productLineData.SimpleProductLine()
  99 + rewardStandardData.Workshop = workShopData.SimpleWorkshop()
  100 + rewardStandardData.Remark = param.Remark
  101 + rewardStandardData.CompanyId = operateInfo.CompanyId
  102 + rewardStandardData.OrgId = operateInfo.OrgId
  103 + err = rewardStandardData.UpdateTarge(
  104 + param.TargetType,
  105 + param.TargeVal1,
  106 + param.TargeVal2,
  107 + param.TargeVal3,
  108 + param.TargeVal4)
  109 + if err != nil {
  110 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  111 + }
  112 + _, err = rewardStandardRepo.Save(rewardStandardData)
  113 + if err != nil {
  114 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  115 + }
  116 + if err := transactionContext.CommitTransaction(); err != nil {
  117 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  118 + }
  119 + param.Id = rewardStandardData.Id
  120 + return param, nil
  121 +}
  122 +
  123 +// GetRewardStandard 根据id获取奖惩标准数据
  124 +func (srv RewardStandardService) GetRewardStandard(operateInfo *domain.OperateInfo, param *query.GetRewardStandard) (*dto.RewardStandardInfo, error) {
  125 + transactionContext, err := factory.CreateTransactionContext(nil)
  126 + if err != nil {
  127 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  128 + }
  129 + if err := transactionContext.StartTransaction(); err != nil {
  130 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  131 + }
  132 + defer func() {
  133 + transactionContext.RollbackTransaction()
  134 + }()
  135 +
  136 + rewardStandardRepo, _ := factory.CreateRewardStandardRepository(map[string]interface{}{
  137 + "transactionContext": transactionContext,
  138 + })
  139 + rewardStandardData, err := rewardStandardRepo.FindOne(map[string]interface{}{
  140 + "id": param.Id,
  141 + })
  142 + if err != nil {
  143 + return nil, application.ThrowError(application.BUSINESS_ERROR, "指标数据不存在"+err.Error())
  144 + }
  145 + if err := transactionContext.CommitTransaction(); err != nil {
  146 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  147 + }
  148 + if operateInfo.CompanyId != rewardStandardData.CompanyId {
  149 + return nil, application.ThrowError(application.BUSINESS_ERROR, "指标数据不存在")
  150 + }
  151 +
  152 + result := dto.RewardStandardInfo{
  153 + Id: rewardStandardData.Id,
  154 + WorkshopId: rewardStandardData.Workshop.WorkshopId,
  155 + WorkshopName: rewardStandardData.Workshop.WorkshopName,
  156 + LineId: rewardStandardData.ProductLine.LineId,
  157 + LineName: rewardStandardData.ProductLine.LineName,
  158 + SectionId: rewardStandardData.ProductSection.SectionId,
  159 + SectionName: rewardStandardData.ProductSection.SectionName,
  160 + Remark: rewardStandardData.Remark,
  161 + TargetType: rewardStandardData.TargetType,
  162 + TargeVal1: rewardStandardData.TargeVal1,
  163 + TargeVal2: rewardStandardData.TargeVal2,
  164 + TargeVal3: rewardStandardData.TargeVal3,
  165 + TargeVal4: rewardStandardData.TargeVal4,
  166 + }
  167 + return &result, nil
  168 +}
  169 +
  170 +// DeleteRewardStandard 根据id删除奖惩标准
  171 +func (srv RewardStandardService) DeleteRewardStandard(operateInfo *domain.OperateInfo, param *query.GetRewardStandard) (*domain.RewardStandard, error) {
  172 + transactionContext, err := factory.CreateTransactionContext(nil)
  173 + if err != nil {
  174 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  175 + }
  176 + if err := transactionContext.StartTransaction(); err != nil {
  177 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  178 + }
  179 + defer func() {
  180 + transactionContext.RollbackTransaction()
  181 + }()
  182 +
  183 + rewardStandardRepo, _ := factory.CreateRewardStandardRepository(map[string]interface{}{
  184 + "transactionContext": transactionContext,
  185 + })
  186 + rewardStandardData, err := rewardStandardRepo.FindOne(map[string]interface{}{
  187 + "id": param.Id,
  188 + })
  189 + if err != nil {
  190 + return nil, application.ThrowError(application.BUSINESS_ERROR, "指标数据不存在:"+err.Error())
  191 + }
  192 +
  193 + if operateInfo.CompanyId != rewardStandardData.CompanyId {
  194 + return nil, application.ThrowError(application.BUSINESS_ERROR, "指标数据不存在")
  195 + }
  196 + _, err = rewardStandardRepo.Remove(rewardStandardData)
  197 + if err != nil {
  198 + return nil, application.ThrowError(application.BUSINESS_ERROR, "操作指标数据失败"+err.Error())
  199 + }
  200 + if err := transactionContext.CommitTransaction(); err != nil {
  201 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  202 + }
  203 + return rewardStandardData, nil
  204 +}
  205 +
  206 +// ListRewardStandard 奖惩标准列表
  207 +func (srv RewardStandardService) ListRewardStandard(param *query.ListRewardStandard) (int64, []dto.RewardStandardList, error) {
  208 + transactionContext, err := factory.CreateTransactionContext(nil)
  209 + if err != nil {
  210 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  211 + }
  212 + if err := transactionContext.StartTransaction(); err != nil {
  213 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  214 + }
  215 + defer func() {
  216 + transactionContext.RollbackTransaction()
  217 + }()
  218 +
  219 + rewardStandardRepo, _ := factory.CreateRewardStandardRepository(map[string]interface{}{
  220 + "transactionContext": transactionContext,
  221 + })
  222 +
  223 + condition := map[string]interface{}{
  224 + "limit": 20,
  225 + "offset": 0,
  226 + "companyId": param.CompanyId,
  227 + }
  228 + if param.PageSize > 0 {
  229 + condition["limit"] = param.PageSize
  230 + }
  231 + offset := param.PageSize * (param.PageNumber - 1)
  232 + if offset > 0 {
  233 + condition["offset"] = offset
  234 + }
  235 + if len(param.WorkshopName) > 0 {
  236 + condition["workshopName"] = param.WorkshopName
  237 + }
  238 + if len(param.SectionName) > 0 {
  239 + condition["sectionName"] = param.SectionName
  240 + }
  241 + if len(param.LineName) > 0 {
  242 + condition["lineName"] = param.LineName
  243 + }
  244 + cnt, rewardStandardList, err := rewardStandardRepo.Find(condition)
  245 + if err != nil {
  246 + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  247 + }
  248 + if err := transactionContext.CommitTransaction(); err != nil {
  249 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  250 + }
  251 + listResult := make([]dto.RewardStandardList, 0)
  252 + var temp dto.RewardStandardList
  253 + for _, v := range rewardStandardList {
  254 + temp = dto.RewardStandardList{
  255 + Id: v.Id,
  256 + WorkshopId: v.Workshop.WorkshopId,
  257 + WorkshopName: v.Workshop.WorkshopName,
  258 + LineId: v.ProductLine.LineId,
  259 + LineName: v.ProductLine.LineName,
  260 + SectionId: v.ProductSection.SectionId,
  261 + SectionName: v.ProductSection.SectionName,
  262 + Remark: v.Remark,
  263 + TargetType: v.TargetType,
  264 + TargetTypeName: v.TargetTypeName(),
  265 + TargeReward: v.ShowTargeReward(),
  266 + TargeFault: v.ShowTargeFault(),
  267 + }
  268 + listResult = append(listResult, temp)
  269 + }
  270 + return cnt, listResult, nil
  271 +}
  272 +
  273 +// SaveRewardRule 保存奖惩规则
  274 +func (srv RewardStandardService) SaveRewardRule(operateInfo *domain.OperateInfo, param *command.SaveRewardRuleCommand) (*command.SaveRewardRuleCommand, error) {
  275 + transactionContext, err := factory.CreateTransactionContext(nil)
  276 + if err != nil {
  277 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  278 + }
  279 + if err := transactionContext.StartTransaction(); err != nil {
  280 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  281 + }
  282 + defer func() {
  283 + transactionContext.RollbackTransaction()
  284 + }()
  285 + rewardRuleRepo, _ := factory.CreateRewardRuleRepository(map[string]interface{}{
  286 + "transactionContext": transactionContext,
  287 + })
  288 + _, ruleList, err := rewardRuleRepo.Find(map[string]interface{}{
  289 + "companyId": operateInfo.CompanyId,
  290 + })
  291 + if err != nil {
  292 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  293 + }
  294 + var newRewardRule *domain.RewardRule
  295 + if len(ruleList) > 0 {
  296 + newRewardRule = ruleList[0]
  297 + } else {
  298 + newRewardRule = &domain.RewardRule{
  299 + CreatedAt: time.Now(),
  300 + CompanyId: operateInfo.CompanyId,
  301 + OrgId: operateInfo.OrgId,
  302 + FaultTag: ">",
  303 + RewardTag: ">",
  304 + }
  305 + }
  306 + newRewardRule.UpdatedAt = time.Now()
  307 + newRewardRule.FaultAmount = param.FaultAmount
  308 + newRewardRule.FaultNum = param.FaultNum
  309 + newRewardRule.RewardAmount = param.RewardAmount
  310 + newRewardRule.RewardNum = param.RewardNum
  311 + newRewardRule.Remark = param.Remark
  312 + _, err = rewardRuleRepo.Save(newRewardRule)
  313 + if err != nil {
  314 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  315 + }
  316 + if err := transactionContext.CommitTransaction(); err != nil {
  317 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  318 + }
  319 + return param, err
  320 +}
  321 +
  322 +// GetRewardRule 获取奖惩规则
  323 +func (srv RewardStandardService) GetRewardRule(operateInfo *domain.OperateInfo) (*dto.RewardRuleInfo, error) {
  324 + transactionContext, err := factory.CreateTransactionContext(nil)
  325 + if err != nil {
  326 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  327 + }
  328 + if err := transactionContext.StartTransaction(); err != nil {
  329 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  330 + }
  331 + defer func() {
  332 + transactionContext.RollbackTransaction()
  333 + }()
  334 + rewardRuleRepo, _ := factory.CreateRewardRuleRepository(map[string]interface{}{
  335 + "transactionContext": transactionContext,
  336 + })
  337 + _, ruleList, err := rewardRuleRepo.Find(map[string]interface{}{
  338 + "companyId": operateInfo.CompanyId,
  339 + })
  340 + if err != nil {
  341 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  342 + }
  343 + if err := transactionContext.CommitTransaction(); err != nil {
  344 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  345 + }
  346 + var newRewardRule *dto.RewardRuleInfo
  347 + if len(ruleList) > 0 {
  348 + newRewardRule = &dto.RewardRuleInfo{
  349 + RewardNum: ruleList[0].RewardNum,
  350 + RewardAmount: ruleList[0].RewardAmount,
  351 + FaultNum: ruleList[0].FaultNum,
  352 + FaultAmount: ruleList[0].RewardAmount,
  353 + Remark: ruleList[0].Remark,
  354 + }
  355 + } else {
  356 + newRewardRule = &dto.RewardRuleInfo{}
  357 + }
  358 + return newRewardRule, nil
  359 +}
  1 +package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
  9 +)
  10 +
  11 +//车间看板(生产)
  12 +
  13 +// 车间描述
  14 +func (svr *CommonStatisticsService) WorkshopDesc() (interface{}, error) {
  15 + transactionContext, err := factory.CreateTransactionContext(nil)
  16 + if err != nil {
  17 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  18 + }
  19 + if err := transactionContext.StartTransaction(); err != nil {
  20 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  21 + }
  22 + defer func() {
  23 + _ = transactionContext.RollbackTransaction()
  24 + }()
  25 + boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
  26 + workshopDesc, err := boardShowData.WorkshopDesc(
  27 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  28 + constant.MANUFACTURE_DEFAULT_ORGID,
  29 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  30 + )
  31 + if err != nil {
  32 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  33 + }
  34 + //在岗人数
  35 + onDuty, err := boardShowData.OnDutyCount(
  36 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  37 + constant.MANUFACTURE_DEFAULT_ORGID,
  38 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  39 + )
  40 + if err != nil {
  41 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  42 + }
  43 + if err := transactionContext.CommitTransaction(); err != nil {
  44 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  45 + }
  46 + result := map[string]interface{}{
  47 + "lines": workshopDesc.Lines,
  48 + "uname": workshopDesc.Uname,
  49 + "workon": workshopDesc.Workon,
  50 + "workshopName": workshopDesc.WorkshopName,
  51 + "onDuty": onDuty,
  52 + }
  53 + return result, nil
  54 +}
  55 +
  56 +// 员工效率排名
  57 +func (svr *CommonStatisticsService) EmployeeWorkpieceRatio() (interface{}, error) {
  58 + transactionContext, err := factory.CreateTransactionContext(nil)
  59 + if err != nil {
  60 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  61 + }
  62 + if err := transactionContext.StartTransaction(); err != nil {
  63 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  64 + }
  65 + defer func() {
  66 + _ = transactionContext.RollbackTransaction()
  67 + }()
  68 + boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
  69 + result, err := boardShowData.EmployeeWorkpieceRatio(
  70 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  71 + constant.MANUFACTURE_DEFAULT_ORGID,
  72 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  73 + )
  74 + if err != nil {
  75 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  76 + }
  77 + if err := transactionContext.CommitTransaction(); err != nil {
  78 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  79 + }
  80 + listData := map[string]interface{}{
  81 + "list": result,
  82 + }
  83 + return listData, nil
  84 +}
  85 +
  86 +// TimeSectionProductRecord 时段产能
  87 +func (svr *CommonStatisticsService) TimeSectionProductRecord() (interface{}, error) {
  88 + transactionContext, err := factory.CreateTransactionContext(nil)
  89 + if err != nil {
  90 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  91 + }
  92 + if err := transactionContext.StartTransaction(); err != nil {
  93 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  94 + }
  95 + defer func() {
  96 + _ = transactionContext.RollbackTransaction()
  97 + }()
  98 + boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
  99 + // todo
  100 + result, err := boardShowData.TimeSectionProductRecord(
  101 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  102 + constant.MANUFACTURE_DEFAULT_ORGID,
  103 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  104 + 7, 8,
  105 + )
  106 + if err != nil {
  107 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  108 + }
  109 + if err := transactionContext.CommitTransaction(); err != nil {
  110 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  111 + }
  112 + listData := map[string]interface{}{
  113 + "list": result,
  114 + }
  115 + return listData, nil
  116 +}
  117 +
  118 +// TopShow 今日昨日历史最佳
  119 +func (svr *CommonStatisticsService) TopShow() (interface{}, error) {
  120 + transactionContext, err := factory.CreateTransactionContext(nil)
  121 + if err != nil {
  122 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  123 + }
  124 + if err := transactionContext.StartTransaction(); err != nil {
  125 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  126 + }
  127 + defer func() {
  128 + _ = transactionContext.RollbackTransaction()
  129 + }()
  130 + boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
  131 + result, err := boardShowData.TopShow(
  132 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  133 + constant.MANUFACTURE_DEFAULT_ORGID,
  134 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  135 + )
  136 + if err != nil {
  137 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  138 + }
  139 + if err := transactionContext.CommitTransaction(); err != nil {
  140 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  141 + }
  142 + return result, nil
  143 +}
  144 +
  145 +// ProportionOfSecondLevel 二级品占比
  146 +func (svr *CommonStatisticsService) ProportionOfSecondLevel() (interface{}, error) {
  147 + transactionContext, err := factory.CreateTransactionContext(nil)
  148 + if err != nil {
  149 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  150 + }
  151 + if err := transactionContext.StartTransaction(); err != nil {
  152 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  153 + }
  154 + defer func() {
  155 + _ = transactionContext.RollbackTransaction()
  156 + }()
  157 + boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
  158 + result, err := boardShowData.ProportionOfSecondLevel(
  159 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  160 + constant.MANUFACTURE_DEFAULT_ORGID,
  161 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  162 + )
  163 + if err != nil {
  164 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  165 + }
  166 + if err := transactionContext.CommitTransaction(); err != nil {
  167 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  168 + }
  169 + listData := map[string]interface{}{
  170 + "list": result,
  171 + }
  172 + return listData, nil
  173 +}
  174 +
  175 +// SectionProductInfo 工段生产信息
  176 +func (svr *CommonStatisticsService) SectionProductInfo() (interface{}, error) {
  177 + transactionContext, err := factory.CreateTransactionContext(nil)
  178 + if err != nil {
  179 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  180 + }
  181 + if err := transactionContext.StartTransaction(); err != nil {
  182 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  183 + }
  184 + defer func() {
  185 + _ = transactionContext.RollbackTransaction()
  186 + }()
  187 + boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
  188 + result, err := boardShowData.SectionProductInfo(
  189 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  190 + constant.MANUFACTURE_DEFAULT_ORGID,
  191 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  192 + )
  193 + if err != nil {
  194 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  195 + }
  196 + if err := transactionContext.CommitTransaction(); err != nil {
  197 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  198 + }
  199 + listData := map[string]interface{}{
  200 + "list": result,
  201 + }
  202 + return listData, nil
  203 +}
  204 +
  205 +// WorkshopPlanCompletionCurrent 当前计划达成率
  206 +func (svr *CommonStatisticsService) WorkshopPlanCompletionCurrent() (interface{}, error) {
  207 + transactionContext, err := factory.CreateTransactionContext(nil)
  208 + if err != nil {
  209 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  210 + }
  211 + if err := transactionContext.StartTransaction(); err != nil {
  212 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  213 + }
  214 + defer func() {
  215 + _ = transactionContext.RollbackTransaction()
  216 + }()
  217 + boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
  218 + result, err := boardShowData.WorkshopPlanCompletionCurrent(
  219 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  220 + constant.MANUFACTURE_DEFAULT_ORGID,
  221 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  222 + )
  223 + if err != nil {
  224 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  225 + }
  226 + if err := transactionContext.CommitTransaction(); err != nil {
  227 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  228 + }
  229 + listData := map[string]interface{}{
  230 + "rate": result,
  231 + }
  232 + return listData, nil
  233 +}
  234 +
  235 +// WorkshopPlanCompletion5Day 近5天计划达成率
  236 +func (svr *CommonStatisticsService) WorkshopPlanCompletion5Day() (interface{}, error) {
  237 + transactionContext, err := factory.CreateTransactionContext(nil)
  238 + if err != nil {
  239 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  240 + }
  241 + if err := transactionContext.StartTransaction(); err != nil {
  242 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  243 + }
  244 + defer func() {
  245 + _ = transactionContext.RollbackTransaction()
  246 + }()
  247 + boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
  248 + result, err := boardShowData.WorkshopPlanCompletion5Day(
  249 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  250 + constant.MANUFACTURE_DEFAULT_ORGID,
  251 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  252 + )
  253 + if err != nil {
  254 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  255 + }
  256 + if err := transactionContext.CommitTransaction(); err != nil {
  257 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  258 + }
  259 + listData := map[string]interface{}{
  260 + "list": result,
  261 + }
  262 + return listData, nil
  263 +}
  264 +
  265 +// 批次产能
  266 +func (svr *CommonStatisticsService) ProductPlan() (interface{}, error) {
  267 + transactionContext, err := factory.CreateTransactionContext(nil)
  268 + if err != nil {
  269 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  270 + }
  271 + if err := transactionContext.StartTransaction(); err != nil {
  272 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  273 + }
  274 + defer func() {
  275 + _ = transactionContext.RollbackTransaction()
  276 + }()
  277 + boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
  278 + result, err := boardShowData.ProductPlan(
  279 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  280 + constant.MANUFACTURE_DEFAULT_ORGID,
  281 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  282 + )
  283 + if err != nil {
  284 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  285 + }
  286 + if err := transactionContext.CommitTransaction(); err != nil {
  287 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  288 + }
  289 + listData := map[string]interface{}{
  290 + "list": result,
  291 + }
  292 + return listData, nil
  293 +}
@@ -12,6 +12,11 @@ import ( @@ -12,6 +12,11 @@ import (
12 type CommonStatisticsService struct { 12 type CommonStatisticsService struct {
13 } 13 }
14 14
  15 +func NewCommonStatisticsService(options map[string]interface{}) *CommonStatisticsService {
  16 + newProductSectionService := &CommonStatisticsService{}
  17 + return newProductSectionService
  18 +}
  19 +
15 // CommonStatisticsService 通用的统计服务 20 // CommonStatisticsService 通用的统计服务
16 func (svr *CommonStatisticsService) CommonStatisticsService(cmd *query.CommonStatisticsQuery) (interface{}, error) { 21 func (svr *CommonStatisticsService) CommonStatisticsService(cmd *query.CommonStatisticsQuery) (interface{}, error) {
17 if err := cmd.ValidateQuery(); err != nil { 22 if err := cmd.ValidateQuery(); err != nil {
@@ -39,8 +44,3 @@ func (svr *CommonStatisticsService) CommonStatisticsService(cmd *query.CommonSta @@ -39,8 +44,3 @@ func (svr *CommonStatisticsService) CommonStatisticsService(cmd *query.CommonSta
39 } 44 }
40 return response, nil 45 return response, nil
41 } 46 }
42 -  
43 -func NewCommonStatisticsService(options map[string]interface{}) *CommonStatisticsService {  
44 - newProductSectionService := &CommonStatisticsService{}  
45 - return newProductSectionService  
46 -}  
@@ -2,10 +2,11 @@ package constant @@ -2,10 +2,11 @@ package constant
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 +
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" 6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
6 ) 7 )
7 8
8 -//var Configurator utils.Configurator = utils.NewConfig("ini","config/app_test.conf") 9 +// var Configurator utils.Configurator = utils.NewConfig("ini","config/app_test.conf")
9 var Configurator utils.Configurator = utils.EnvConfigurator{} 10 var Configurator utils.Configurator = utils.EnvConfigurator{}
10 11
11 var SERVICE_NAME = "allied-creation-manufacture" 12 var SERVICE_NAME = "allied-creation-manufacture"
@@ -16,13 +17,14 @@ var LOG_LEVEL = "debug" @@ -16,13 +17,14 @@ var LOG_LEVEL = "debug"
16 var LOG_FILE = "app.log" 17 var LOG_FILE = "app.log"
17 var PPROF_ON = true 18 var PPROF_ON = true
18 19
19 -//天联共创基础模块 20 +// 天联共创基础模块
20 var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080" //"http://allied-creation-basic-dev.fjmaimaimai.com" 21 var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080" //"http://allied-creation-basic-dev.fjmaimaimai.com"
21 22
22 -//天联共创用户模块  
23 -var ALLIED_CREATION_USER_HOST = "http://localhost:8081" //"http://allied-creation-user-dev.fjmaimaimai.com" 23 +// 天联共创用户模块
  24 +// svar ALLIED_CREATION_USER_HOST = "http://localhost:8081"
  25 +var ALLIED_CREATION_USER_HOST = "http://allied-creation-user-test.fjmaimaimai.com"
24 26
25 -//天联共创业务模块 27 +// 天联共创业务模块
26 var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082" // "http://allied-creation-cooperation-dev.fjmaimaimai.com" 28 var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082" // "http://allied-creation-cooperation-dev.fjmaimaimai.com"
27 29
28 var MMM_BYTE_BANK_HOST = "http://220.250.41.79:8301" 30 var MMM_BYTE_BANK_HOST = "http://220.250.41.79:8301"
@@ -28,7 +28,7 @@ var MQTT_HOST = "47.97.5.102" @@ -28,7 +28,7 @@ var MQTT_HOST = "47.97.5.102"
28 var MQTT_PORT = "6000" 28 var MQTT_PORT = "6000"
29 var MQTT_USER = "admin" 29 var MQTT_USER = "admin"
30 var MQTT_PASSWORD = "123456" 30 var MQTT_PASSWORD = "123456"
31 -var MQTT_UP = true 31 +var MQTT_UP = false
32 32
33 func init() { 33 func init() {
34 MQTT_HOST = Configurator.DefaultString("MQTT_HOST", MQTT_HOST) 34 MQTT_HOST = Configurator.DefaultString("MQTT_HOST", MQTT_HOST)
@@ -3,11 +3,11 @@ @@ -3,11 +3,11 @@
3 3
4 package constant 4 package constant
5 5
6 -var POSTGRESQL_DB_NAME = "terms" 6 +var POSTGRESQL_DB_NAME = "allied_creation_test"
7 var POSTGRESQL_USER = "postgres" 7 var POSTGRESQL_USER = "postgres"
8 -var POSTGRESQL_PASSWORD = "123456"  
9 -var POSTGRESQL_HOST = "127.0.0.1"  
10 -var POSTGRESQL_PORT = "5432" 8 +var POSTGRESQL_PASSWORD = "eagle1010"
  9 +var POSTGRESQL_HOST = "114.55.200.59"
  10 +var POSTGRESQL_PORT = "31543"
11 var DISABLE_CREATE_TABLE = false 11 var DISABLE_CREATE_TABLE = false
12 var DISABLE_SQL_GENERATE_PRINT = false 12 var DISABLE_SQL_GENERATE_PRINT = false
13 var DISABLE_SQL_GENERATE_COMMENT = true 13 var DISABLE_SQL_GENERATE_COMMENT = true
@@ -3,10 +3,11 @@ package domain @@ -3,10 +3,11 @@ package domain
3 import ( 3 import (
4 "errors" 4 "errors"
5 "fmt" 5 "fmt"
  6 + "time"
  7 +
6 "github.com/linmadan/egglib-go/utils/xtime" 8 "github.com/linmadan/egglib-go/utils/xtime"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
9 - "time"  
10 ) 11 )
11 12
12 const ( 13 const (
@@ -159,6 +160,9 @@ func (productAttendanceRecord *ProductAttendanceRecord) Approve(approveUser *Use @@ -159,6 +160,9 @@ func (productAttendanceRecord *ProductAttendanceRecord) Approve(approveUser *Use
159 } 160 }
160 161
161 func (productAttendanceRecord *ProductAttendanceRecord) ProductTime() time.Time { 162 func (productAttendanceRecord *ProductAttendanceRecord) ProductTime() time.Time {
  163 + if productAttendanceRecord.Ext == nil {
  164 + return time.Time{}
  165 + }
162 attendanceExt := productAttendanceRecord.Ext.AttendanceExt 166 attendanceExt := productAttendanceRecord.Ext.AttendanceExt
163 if attendanceExt != nil && !xtime.IsZero(productAttendanceRecord.ProductDate) { 167 if attendanceExt != nil && !xtime.IsZero(productAttendanceRecord.ProductDate) {
164 return productAttendanceRecord.ProductDate 168 return productAttendanceRecord.ProductDate
@@ -230,3 +234,12 @@ func (productAttendanceRecord *ProductAttendanceRecord) AttendanceBreakTime(prod @@ -230,3 +234,12 @@ func (productAttendanceRecord *ProductAttendanceRecord) AttendanceBreakTime(prod
230 } 234 }
231 return bt 235 return bt
232 } 236 }
  237 +
  238 +// 计算上岗到 离岗之间的工作时间,
  239 +// breakTime 休息时间(小时)
  240 +func (productAttendanceRecord *ProductAttendanceRecord) ComputeWorkTime(breakTime float64) float64 {
  241 + signIn := roundTime(productAttendanceRecord.SignIn)
  242 + signOut := roundTime(productAttendanceRecord.SignOut)
  243 + wt := utils.Round(signOut.Sub(signIn).Hours()-breakTime, 2)
  244 + return roundWorkTime(wt)
  245 +}
@@ -14,6 +14,12 @@ type ProductLine struct { @@ -14,6 +14,12 @@ type ProductLine struct {
14 Removed int `json:"removed,omitempty"` 14 Removed int `json:"removed,omitempty"`
15 } 15 }
16 16
  17 +//输出简化的模型
  18 +type SimpleProductLine struct {
  19 + LineId int `json:"lineId"` // 生产线ID
  20 + LineName string `json:"lineName"` // 生产线名称
  21 +}
  22 +
17 // 查询生产线 23 // 查询生产线
18 func (productLine *ProductLine) FindSection(sectionId int) (*ProductSection, error) { 24 func (productLine *ProductLine) FindSection(sectionId int) (*ProductSection, error) {
19 for i := range productLine.ProductSections { 25 for i := range productLine.ProductSections {
@@ -37,3 +43,11 @@ func (productLine *ProductLine) GetProductSections(removed int) []*ProductSectio @@ -37,3 +43,11 @@ func (productLine *ProductLine) GetProductSections(removed int) []*ProductSectio
37 } 43 }
38 return result 44 return result
39 } 45 }
  46 +
  47 +//SimpleProductLine 输出简化的模型
  48 +func (productLine *ProductLine) SimpleProductLine() SimpleProductLine {
  49 + return SimpleProductLine{
  50 + LineId: productLine.LineId,
  51 + LineName: productLine.LineName,
  52 + }
  53 +}
1 package domain 1 package domain
2 2
3 import ( 3 import (
4 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"  
5 "time" 4 "time"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
6 ) 7 )
7 8
8 const ( 9 const (
@@ -7,6 +7,8 @@ type ProductRecordStaticInfo struct { @@ -7,6 +7,8 @@ type ProductRecordStaticInfo struct {
7 ProductDate string `json:"productDate"` 7 ProductDate string `json:"productDate"`
8 // 生产计划ID 8 // 生产计划ID
9 ProductPlanId int `json:"productPlanId,omitempty"` 9 ProductPlanId int `json:"productPlanId,omitempty"`
  10 +
  11 + PlanProductCode string `json:"planProductCode"`
10 // 计划的产品名称 12 // 计划的产品名称
11 PlanProductName string `json:"planProductName,omitempty"` 13 PlanProductName string `json:"planProductName,omitempty"`
12 // 批号 14 // 批号
  1 +package domain
  2 +
  3 +import (
  4 + "errors"
  5 + "time"
  6 +)
  7 +
  8 +// 事故管理数据结构
  9 +type ProductTrouble struct {
  10 + Id int `json:"id"` // id
  11 + CompanyId int `json:"companyId"` // 企业id
  12 + OrgId int `json:"orgId"` // 组织ID
  13 + WorkStation WorkStation `json:"workStation"` // 工作位置
  14 + ProductWorker User `json:"productWorker,omitempty"` // 生产工人
  15 + AmountLoss float64 `json:"amountLoss"` // 损失的金额
  16 + Types TroubleType `json:"types"` // 事故类型 1 安全事故 ,2 质量事故, 3 金属事故 ,4 非金属事故
  17 + RecordDate time.Time `json:"recordDate"` // 事故发生的日期
  18 + Remark string `json:"remakr"` // 备注
  19 + ApproveStatus ProductTroubleApprove `json:"approveStatus"` // 审核状态 1:未审核 2:已审核 3.自动审核
  20 + ApproveAt *time.Time `json:"approveAt"` // 审核时间
  21 + ApproveUser *User `json:"approveUser"` // 审核人
  22 + CreatedAt time.Time `json:"createdAt,omitempty"` // 创建时间
  23 + UpdatedAt time.Time `json:"updatedAt,omitempty"` // 更新时间
  24 + DeletedAt *time.Time `json:"deletedAt,omitempty"` // 删除时间
  25 +}
  26 +
  27 +// 事故类型
  28 +type TroubleType string
  29 +
  30 +// 事故类型 1 安全事故 ,2 质量事故, 3 金属事故 ,4 非金属事故
  31 +const (
  32 + TroubleType1 TroubleType = "安全事故"
  33 + TroubleType2 TroubleType = "质量事故"
  34 + TroubleType3 TroubleType = "金属事故"
  35 + TroubleType4 TroubleType = "非金属事故"
  36 +)
  37 +
  38 +// 事故管理 审核状态
  39 +type ProductTroubleApprove int
  40 +
  41 +// 审核状态 1:未审核 2:已审核
  42 +const (
  43 + TroubleWaitApprove ProductTroubleApprove = 1
  44 + TroubleIsApprove ProductTroubleApprove = 2
  45 +)
  46 +
  47 +type ProductTroubleRepository interface {
  48 + Save(param *ProductTrouble) (*ProductTrouble, error)
  49 + Remove(param *ProductTrouble) (*ProductTrouble, error)
  50 + FindOne(queryOptions map[string]interface{}) (*ProductTrouble, error)
  51 + Find(queryOptions map[string]interface{}) (int64, []*ProductTrouble, error)
  52 +}
  53 +
  54 +func (m *ProductTrouble) SetTypes(v string) error {
  55 + troubleType := TroubleType(v)
  56 + switch troubleType {
  57 + case TroubleType1, TroubleType2, TroubleType3, TroubleType4:
  58 + m.Types = troubleType
  59 + default:
  60 + return errors.New("ProductTrouble.Types 值错误")
  61 + }
  62 + return nil
  63 +}
  64 +
  65 +// 审核事故数据
  66 +func (m *ProductTrouble) Approve(approveUser *User) error {
  67 + nowTime := time.Now()
  68 + switch m.ApproveStatus {
  69 + case TroubleIsApprove:
  70 + return errors.New("事故不需要重复审核")
  71 + default:
  72 + m.ApproveAt = &nowTime
  73 + m.ApproveStatus = TroubleIsApprove
  74 + m.ApproveUser = approveUser
  75 + }
  76 + return nil
  77 +}
  78 +
  79 +func (m *ProductTrouble) GetApproveStatusName() string {
  80 + switch m.ApproveStatus {
  81 + case TroubleWaitApprove:
  82 + return "未审核"
  83 + case TroubleIsApprove:
  84 + return "已审核"
  85 + }
  86 + return ""
  87 +}
  88 +
  89 +func (m *ProductTrouble) GetTypesName() string {
  90 + switch m.Types {
  91 + case TroubleType1:
  92 + return "安全事故"
  93 + case TroubleType2:
  94 + return "质量事故"
  95 + case TroubleType3:
  96 + return "金属事故"
  97 + case TroubleType4:
  98 + return "非金属事故"
  99 + }
  100 + return ""
  101 +}
  1 +package domain
  2 +
  3 +import (
  4 + "strconv"
  5 + "time"
  6 +)
  7 +
  8 +// RewardStandard 奖惩规则
  9 +type RewardRule struct {
  10 + Id int `json:"id"` //奖惩规则id
  11 + CompanyId int `json:"companyId"` //企业id
  12 + OrgId int `json:"orgId"` //组织ID
  13 + RewardTag string `json:"rewardTag"`
  14 + RewardNum int `json:"rewardNum"`
  15 + RewardAmount string `json:"rewardAmount"`
  16 + FaultTag string `json:"faultTag"`
  17 + FaultNum int `json:"faultNum"`
  18 + FaultAmount string `json:"faultAmount"`
  19 + Remark string `json:"remark"`
  20 + CreatedAt time.Time
  21 + UpdatedAt time.Time
  22 +}
  23 +
  24 +type RewardRuleRepository interface {
  25 + Save(param *RewardRule) (*RewardRule, error)
  26 + FindOne(queryOptions map[string]interface{}) (*RewardRule, error)
  27 + Find(queryOptions map[string]interface{}) (int64, []*RewardRule, error)
  28 +}
  29 +
  30 +func (m *RewardRule) ValidRewardTag() bool {
  31 + switch m.RewardTag {
  32 + case ">":
  33 + default:
  34 + return false
  35 + }
  36 + return true
  37 +}
  38 +
  39 +func (m *RewardRule) ValidFaultTag() bool {
  40 + switch m.FaultTag {
  41 + case ">":
  42 + default:
  43 + return false
  44 + }
  45 + return true
  46 +}
  47 +
  48 +// 计算奖惩 的金额
  49 +func (m *RewardRule) SumRewardAmount(rewardNum int, faultNum int) float64 {
  50 + result := float64(0)
  51 + rewardAmount, _ := strconv.ParseFloat(m.RewardAmount, 64)
  52 + faultAmount, _ := strconv.ParseFloat(m.FaultAmount, 64)
  53 + if rewardNum > m.RewardNum {
  54 + result += rewardAmount
  55 + }
  56 + if faultNum > m.FaultNum {
  57 + result -= faultAmount
  58 + }
  59 + return result
  60 +}
  1 +package domain
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "strconv"
  7 + "time"
  8 +)
  9 +
  10 +// RewardStandard 奖惩标准
  11 +type RewardStandard struct {
  12 + Id int `json:"id"` //奖惩标准id
  13 + CompanyId int `json:"companyId"` //企业id
  14 + OrgId int `json:"orgId"` //组织ID
  15 + Workshop SimpleWorkshop `json:"workshop"` //车间id
  16 + ProductLine SimpleProductLine `json:"productLine"` //生产线
  17 + ProductSection ProductSection `json:"ProductSection"` //工段
  18 + Remark string `json:"remark"` //备注
  19 + TargetType int `json:"targetType"` //指标类别 1:产效 2:合格率 3:安全事故 4:质量事故 5:异物次数
  20 + TargeVal1 string `json:"targeVal1"` //填写的指标值1
  21 + TargeVal2 string `json:"targeVal2"` //填写的指标值2
  22 + TargeVal3 string `json:"targeVal3"` //填写的指标值3
  23 + TargeVal4 string `json:"targeVal4"` //填写的指标值4
  24 + CreatedAt time.Time `json:"createdAt"` //创建时间
  25 + UpdatedAt time.Time `json:"updatedAt"` //更新时间
  26 + DeletedAt *time.Time `json:"-"` //删除时间
  27 +}
  28 +
  29 +/*
  30 +填写的指标值描述
  31 +产效=> 功: 大于等于 x kg/小时;过:小于 x kg/小时
  32 +合格率=> 功:大于等于 x% ;过:小于 x%
  33 +安全事故 => 功:小于等于 x 次 或者 损失小于等于 x 元;过:大于 x 次 或 损失大于 x 元
  34 +质量事故 => 功:小于等于 x 次 或者 损失 小于等于 x 元;过:大于 x 次 或者 损失大于 x 元
  35 +异物次数 => 功:发现金属小于等于 x 次 或者 发现非金属小于等于 x 次
  36 + 过:发现金属大于 x 次 或 发现非金数大于 x 次
  37 +
  38 +*/
  39 +
  40 +type RewardStandardRepository interface {
  41 + Save(param *RewardStandard) (*RewardStandard, error)
  42 + Remove(param *RewardStandard) (*RewardStandard, error)
  43 + FindOne(queryOptions map[string]interface{}) (*RewardStandard, error)
  44 + Find(queryOptions map[string]interface{}) (int64, []*RewardStandard, error)
  45 +}
  46 +
  47 +// 指标类别 1:产效 2:合格率 3:安全事故 4:质量事故 5:异物次数
  48 +const (
  49 + TargetType1 int = 1
  50 + TargetType2 int = 2
  51 + TargetType3 int = 3
  52 + TargetType4 int = 4
  53 + TargetType5 int = 5
  54 +)
  55 +
  56 +// UpdateTarge 更新指标内容
  57 +func (m *RewardStandard) UpdateTarge(targetType int, targeVal1 string, targeVal2 string, targeVal3 string, targeVal4 string) error {
  58 + switch targetType {
  59 + case TargetType1, TargetType2:
  60 + if len(targeVal1) == 0 || len(targeVal2) == 0 {
  61 + return errors.New("功过指标内容不能为空")
  62 + }
  63 + _, err := strconv.Atoi(targeVal1)
  64 + if err != nil {
  65 + return errors.New("功过指标内容需要为整数")
  66 + }
  67 + _, err = strconv.Atoi(targeVal2)
  68 + if err != nil {
  69 + return errors.New("功过指标内容需要为整数")
  70 + }
  71 + m.TargetType = targetType
  72 + m.TargeVal1 = targeVal1
  73 + m.TargeVal2 = targeVal2
  74 + m.TargeVal3 = ""
  75 + m.TargeVal4 = ""
  76 + case TargetType3, TargetType4, TargetType5:
  77 + if len(targeVal1) == 0 || len(targeVal2) == 0 || len(targeVal3) == 0 || len(targeVal4) == 0 {
  78 + return errors.New("功过指标内容不能为空")
  79 + }
  80 + _, err := strconv.Atoi(targeVal1)
  81 + if err != nil {
  82 + return errors.New("功过指标内容需要为整数")
  83 + }
  84 + _, err = strconv.Atoi(targeVal2)
  85 + if err != nil {
  86 + return errors.New("功过指标内容需要为整数")
  87 + }
  88 + _, err = strconv.Atoi(targeVal3)
  89 + if err != nil {
  90 + return errors.New("功过指标内容需要为整数")
  91 + }
  92 + _, err = strconv.Atoi(targeVal4)
  93 + if err != nil {
  94 + return errors.New("功过指标内容需要为整数")
  95 + }
  96 + m.TargetType = targetType
  97 + m.TargeVal1 = targeVal1
  98 + m.TargeVal2 = targeVal2
  99 + m.TargeVal3 = targeVal3
  100 + m.TargeVal4 = targeVal4
  101 + default:
  102 + return errors.New("指标类型填写错误")
  103 +
  104 + }
  105 + return nil
  106 +}
  107 +
  108 +// TargetTypeName
  109 +func (m *RewardStandard) TargetTypeName() string {
  110 + switch m.TargetType {
  111 + case TargetType1:
  112 + return "产效"
  113 + case TargetType2:
  114 + return "合格率"
  115 + case TargetType3:
  116 + return "安全事故"
  117 + case TargetType4:
  118 + return "质量事故"
  119 + case TargetType5:
  120 + return "异物次数"
  121 + }
  122 + return ""
  123 +}
  124 +
  125 +// ShowTargeReward 功过指标描述,功劳
  126 +func (m *RewardStandard) ShowTargeReward() string {
  127 + show := ""
  128 + switch m.TargetType {
  129 + case TargetType1:
  130 + show = fmt.Sprintf(">=%skg/小时", m.TargeVal1)
  131 + case TargetType2:
  132 + show = fmt.Sprintf(">=%s%%", m.TargeVal1)
  133 + case TargetType3:
  134 + show = fmt.Sprintf("<=%s次或损失<=%s元", m.TargeVal1, m.TargeVal2)
  135 + case TargetType4:
  136 + show = fmt.Sprintf("<=%s次或损失<=%s元", m.TargeVal1, m.TargeVal2)
  137 + case TargetType5:
  138 + show = fmt.Sprintf("金属<=%s次或非金属<=%s", m.TargeVal1, m.TargeVal2)
  139 + }
  140 + return show
  141 +}
  142 +
  143 +// ShowTargeFault 功过指标描述,过失
  144 +func (m *RewardStandard) ShowTargeFault() string {
  145 + show := ""
  146 + switch m.TargetType {
  147 + case TargetType1:
  148 + show = fmt.Sprintf("<%skg/小时", m.TargeVal2)
  149 + case TargetType2:
  150 + show = fmt.Sprintf("<%s%%", m.TargeVal2)
  151 + case TargetType3:
  152 + show = fmt.Sprintf(">%s次或损失>%s元", m.TargeVal3, m.TargeVal4)
  153 + case TargetType4:
  154 + show = fmt.Sprintf("<=%s次或损失>%s元", m.TargeVal3, m.TargeVal4)
  155 + case TargetType5:
  156 + show = fmt.Sprintf("金属>%s次或非金属>%s", m.TargeVal3, m.TargeVal4)
  157 + }
  158 + return show
  159 +}
  160 +
  161 +// 判定功过, 指标类别 1:产效
  162 +// param1 产效值
  163 +// 功过结果 0 无,1 功 ,-1 过;
  164 +func (m *RewardStandard) VerdictTargetType1(param1 float64) int {
  165 + val1, _ := strconv.ParseFloat(m.TargeVal1, 64)
  166 + val2, _ := strconv.ParseFloat(m.TargeVal2, 64)
  167 + result := 0
  168 + if param1 > val1 {
  169 + result = 1
  170 + } else if param1 < val2 {
  171 + result = -1
  172 + }
  173 + return result
  174 +}
  175 +
  176 +// 判定功过, 指标类别 2:合格率
  177 +// param1 合格率
  178 +// 功过结果 0 无,1 功 ,-1 过;
  179 +func (m *RewardStandard) VerdictTargetType2(param1 float64) int {
  180 + val1, _ := strconv.ParseFloat(m.TargeVal1, 64)
  181 + val2, _ := strconv.ParseFloat(m.TargeVal2, 64)
  182 + result := 0
  183 + if param1 > val1 {
  184 + result = 1
  185 + } else if param1 < val2 {
  186 + result = -1
  187 + }
  188 + return result
  189 +}
  190 +
  191 +// 判定功过, 指标类别 3:安全事故;
  192 +// param1 安全事故次数;
  193 +// param1 损失金额;
  194 +// 功过结果 0 无,1 功 ,-1 过;
  195 +func (m *RewardStandard) VerdictTargetType3(param1 int, param2 float64) int {
  196 + val1, _ := strconv.Atoi(m.TargeVal1)
  197 + val2, _ := strconv.ParseFloat(m.TargeVal2, 64)
  198 + result := 0
  199 + //判定功
  200 + if param1 <= val1 {
  201 + result = 1
  202 + }
  203 + if param2 <= val2 {
  204 + result = 1
  205 + }
  206 + //判定过
  207 + val3, _ := strconv.Atoi(m.TargeVal3)
  208 + val4, _ := strconv.ParseFloat(m.TargeVal4, 64)
  209 +
  210 + if param1 > val3 {
  211 + result = -1
  212 + }
  213 + if param2 > val4 {
  214 + result = -1
  215 + }
  216 + return result
  217 +}
  218 +
  219 +// 判定功过, 指标类别 4:质量事故;
  220 +// param1 质量事故 次数;
  221 +// param1 损失金额;
  222 +// 功过结果 0 无,1 功 ,-1 过;
  223 +func (m *RewardStandard) VerdictTargetType4(param1 int, param2 float64) int {
  224 + val1, _ := strconv.Atoi(m.TargeVal1)
  225 + val2, _ := strconv.ParseFloat(m.TargeVal2, 64)
  226 + result := 0
  227 + //判定功
  228 + if param1 <= val1 {
  229 + result = 1
  230 + }
  231 + if param2 <= val2 {
  232 + result = 1
  233 + }
  234 + //判定过
  235 + val3, _ := strconv.Atoi(m.TargeVal3)
  236 + val4, _ := strconv.ParseFloat(m.TargeVal4, 64)
  237 +
  238 + if param1 > val3 {
  239 + result = -1
  240 + }
  241 + if param2 > val4 {
  242 + result = -1
  243 + }
  244 + return result
  245 +}
  246 +
  247 +// 判定功过, 指标类别 5:异物次数;
  248 +// param1 金属异物 次数;
  249 +// param2 非金属 次数;
  250 +// 功过结果 0 无,1 功 ,-1 过;
  251 +func (m *RewardStandard) VerdictTargetType5(param1 int, param2 int) int {
  252 + val1, _ := strconv.Atoi(m.TargeVal1)
  253 + val2, _ := strconv.Atoi(m.TargeVal2)
  254 + result := 0
  255 + //判定功
  256 + if param1 <= val1 {
  257 + result = 1
  258 + }
  259 + if param2 <= val2 {
  260 + result = 1
  261 + }
  262 + //判定过
  263 + val3, _ := strconv.Atoi(m.TargeVal3)
  264 + val4, _ := strconv.Atoi(m.TargeVal4)
  265 +
  266 + if param1 > val3 {
  267 + result = -1
  268 + }
  269 + if param2 > val4 {
  270 + result = -1
  271 + }
  272 + return result
  273 +}
  1 +package domain
  2 +
  3 +import (
  4 + "time"
  5 +)
  6 +
  7 +// RewardSummary 功过奖惩明细
  8 +type RewardSummary struct {
  9 + Id int `json:"id"`
  10 + CompanyId int `json:"companyId"`
  11 + OrgId int `json:"orgId"`
  12 + RecordDate time.Time `json:"recordDate"` //日期
  13 + RecordDateStr string `json:"recordDateStr"` //
  14 + WorkStation WorkStation `json:"workStation"` //工作位置
  15 + Worker User `json:"user"` //员工
  16 + UpToStandard float64 `json:"upToStandard"` //合格率
  17 + UpToStandardResult int `json:"upToStandardResult"` //合格率 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
  18 + Yield float64 `json:"yield"` //产能
  19 + YieldResult int `json:"yieldResult"` //产能 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
  20 + AccidentNum1 int `json:"accidentNum1"` //质量事故 次数
  21 + AccidentAmount1 float64 `json:"accidentAmount1"` //质量事故 损失金额
  22 + AccidentResult1 int `json:"accidentResult1"` //质量事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
  23 + AccidentNum2 int `json:"accidentNum2"` //安全事故 次数
  24 + AccidentAmount2 float64 `json:"accidentAmount2"` //安全事故 损失金额
  25 + AccidentResult2 int `json:"accidentResult2"` //安全事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
  26 + AccidentNum3 int `json:"accidentNum3"` //异物金属事故 次数
  27 + AccidentResult3 int `json:"accidentResult3"` //异物事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
  28 + AccidentNum4 int `json:"accidentNum4"` //异物非金属事故次数
  29 + SummaryResult float64 `json:"summaryResult"` //奖惩金额计算结果(元)
  30 + CreatedAt time.Time `json:"createdAt"` //
  31 + UpdatedAt time.Time `json:"UpdatedAt"` //
  32 +}
  33 +
  34 +type RewardSummaryRepository interface {
  35 + Save(param *RewardSummary) (*RewardSummary, error)
  36 + FindOne(queryOptions map[string]interface{}) (*RewardSummary, error)
  37 + Find(queryOptions map[string]interface{}) (int64, []*RewardSummary, error)
  38 +}
  39 +
  40 +// SummaryAccident 汇总事故数据
  41 +func (c *RewardSummary) SummaryAccident(trouble *ProductTrouble, rewardStandard *RewardStandard) {
  42 + switch trouble.Types {
  43 + case TroubleType1:
  44 + c.AccidentNum2 = +1
  45 + c.AccidentAmount2 = +trouble.AmountLoss
  46 + if rewardStandard == nil {
  47 + c.AccidentResult2 = 0
  48 + } else {
  49 + r := rewardStandard.VerdictTargetType3(c.AccidentNum2, c.AccidentAmount2)
  50 + c.AccidentResult2 = r
  51 + }
  52 +
  53 + case TroubleType2:
  54 + c.AccidentNum1 = +1
  55 + c.AccidentAmount1 = +trouble.AmountLoss
  56 + if rewardStandard == nil {
  57 + c.AccidentResult1 = 0
  58 + } else {
  59 + r := rewardStandard.VerdictTargetType4(c.AccidentNum1, c.AccidentAmount1)
  60 + c.AccidentResult2 = r
  61 + }
  62 +
  63 + case TroubleType3:
  64 + c.AccidentNum3 = +1
  65 + if rewardStandard == nil {
  66 + c.AccidentResult3 = 0
  67 + } else {
  68 + r := rewardStandard.VerdictTargetType5(c.AccidentNum3, 0)
  69 + c.AccidentResult2 = r
  70 + }
  71 +
  72 + case TroubleType4:
  73 + c.AccidentNum4 = +1
  74 + if rewardStandard != nil {
  75 + r := rewardStandard.VerdictTargetType5(0, c.AccidentNum4)
  76 + c.AccidentResult2 = r
  77 + }
  78 + }
  79 +}
  80 +
  81 +func (c *RewardSummary) ApplySummaryResult(rule *RewardRule) {
  82 + rewardNum := 0
  83 + faultNum := 0
  84 + if c.AccidentResult1 < 0 {
  85 + faultNum = +1
  86 + } else if c.AccidentResult1 > 0 {
  87 + rewardNum = +1
  88 + }
  89 + if c.AccidentResult2 < 0 {
  90 + faultNum = +1
  91 + } else if c.AccidentResult2 > 0 {
  92 + rewardNum = +1
  93 + }
  94 + if c.AccidentResult3 < 0 {
  95 + faultNum = +1
  96 + } else if c.AccidentResult3 > 0 {
  97 + rewardNum = +1
  98 + }
  99 + if c.YieldResult < 0 {
  100 + faultNum = +1
  101 + } else if c.YieldResult > 0 {
  102 + rewardNum = +1
  103 + }
  104 + if c.UpToStandardResult < 0 {
  105 + faultNum = +1
  106 + } else if c.UpToStandardResult > 0 {
  107 + rewardNum = +1
  108 + }
  109 +
  110 + c.SummaryResult = rule.SumRewardAmount(rewardNum, faultNum)
  111 +
  112 +}
  113 +
  114 +// SummaryYield 汇总产效数据
  115 +func (c *RewardSummary) SummaryYield(yield float64, rewardStandard *RewardStandard) {
  116 + c.Yield = yield
  117 + if rewardStandard == nil {
  118 + c.YieldResult = 0
  119 + } else {
  120 + r := rewardStandard.VerdictTargetType1(c.Yield)
  121 + c.YieldResult = r
  122 + }
  123 +}
  124 +
  125 +// SummaryUpToStandard 汇总合格率数据
  126 +func (c *RewardSummary) SummaryUpToStandard(param float64, rewardStandard *RewardStandard) {
  127 + c.UpToStandard = param
  128 + if rewardStandard == nil {
  129 + c.UpToStandard = 0
  130 + } else {
  131 + r := rewardStandard.VerdictTargetType2(c.Yield)
  132 + c.UpToStandardResult = r
  133 + }
  134 +}
@@ -39,6 +39,13 @@ type Workshop struct { @@ -39,6 +39,13 @@ type Workshop struct {
39 Ext *Ext `json:"ext,omitempty"` 39 Ext *Ext `json:"ext,omitempty"`
40 } 40 }
41 41
  42 +type SimpleWorkshop struct {
  43 + // 车间ID
  44 + WorkshopId int `json:"workshopId"`
  45 + // 车间名称
  46 + WorkshopName string `json:"workshopName"`
  47 +}
  48 +
42 type WorkshopRepository interface { 49 type WorkshopRepository interface {
43 Save(workshop *Workshop) (*Workshop, error) 50 Save(workshop *Workshop) (*Workshop, error)
44 Remove(workshop *Workshop) (*Workshop, error) 51 Remove(workshop *Workshop) (*Workshop, error)
@@ -301,3 +308,11 @@ func (workshop *Workshop) CloneSample() *Workshop { @@ -301,3 +308,11 @@ func (workshop *Workshop) CloneSample() *Workshop {
301 WorkshopName: workshop.WorkshopName, 308 WorkshopName: workshop.WorkshopName,
302 } 309 }
303 } 310 }
  311 +
  312 +//SimpleWorkshop 输出简化的模型
  313 +func (workShop *Workshop) SimpleWorkshop() SimpleWorkshop {
  314 + return SimpleWorkshop{
  315 + WorkshopId: workShop.WorkshopId,
  316 + WorkshopName: workShop.WorkshopName,
  317 + }
  318 +}