正在显示
12 个修改的文件
包含
298 行增加
和
31 行删除
@@ -5,9 +5,10 @@ | @@ -5,9 +5,10 @@ | ||
5 | 5 | ||
6 | - 前端调用的地址 http://allied-creation-gateway-dev.fjmaimaimai.com/v1/manufacture | 6 | - 前端调用的地址 http://allied-creation-gateway-dev.fjmaimaimai.com/v1/manufacture |
7 | - 前端调用的地址 http://allied-creation-gateway-test.fjmaimaimai.com/v1/manufacture | 7 | - 前端调用的地址 http://allied-creation-gateway-test.fjmaimaimai.com/v1/manufacture |
8 | + | ||
8 | ## 1.数据导入导出模块 | 9 | ## 1.数据导入导出模块 |
9 | 10 | ||
10 | -### 1.1.Excel导入流程 | 11 | +### 1.1.Excel 导入流程 |
11 | 12 | ||
12 | - 原型说明 | 13 | - 原型说明 |
13 | 14 | ||
@@ -19,7 +20,6 @@ | @@ -19,7 +20,6 @@ | ||
19 | 20 | ||
20 | - [导入接口文档地址](https://doc-press.fjmaimaimai.com/team/frontend/plugins/business/import.html) | 21 | - [导入接口文档地址](https://doc-press.fjmaimaimai.com/team/frontend/plugins/business/import.html) |
21 | 22 | ||
22 | - | ||
23 | ``` | 23 | ``` |
24 | POST/v1/web/file-import | 24 | POST/v1/web/file-import |
25 | 25 | ||
@@ -31,11 +31,10 @@ file 文件 | @@ -31,11 +31,10 @@ file 文件 | ||
31 | code 对应导入模块的编码 | 31 | code 对应导入模块的编码 |
32 | ``` | 32 | ``` |
33 | 33 | ||
34 | -- ``对接步骤``以导入公司用户模块为例 | 34 | +- `对接步骤`以导入公司用户模块为例 |
35 | + | ||
36 | + 1.定义接口导入的`code`为`ADMIN_SYSTEM-MANAGE_BASE_USER` 2.根据接口解析导入文件的数据 3.调用基础库解析数据并传到后台 | ||
35 | 37 | ||
36 | -1.定义接口导入的``code``为``ADMIN_SYSTEM-MANAGE_BASE_USER`` | ||
37 | -2.根据接口解析导入文件的数据 | ||
38 | -3.调用基础库解析数据并传到后台 | ||
39 | ```go | 38 | ```go |
40 | 39 | ||
41 | // 1.解析列 | 40 | // 1.解析列 |
@@ -85,21 +84,23 @@ result, err := userGateway.UserBatchAdd(allied_creation_user.ReqBatchAddUser{ | @@ -85,21 +84,23 @@ result, err := userGateway.UserBatchAdd(allied_creation_user.ReqBatchAddUser{ | ||
85 | ``` | 84 | ``` |
86 | 85 | ||
87 | ```go | 86 | ```go |
87 | + | ||
88 | ``` | 88 | ``` |
89 | 89 | ||
90 | -### 2.2 Excel导出流程 | 90 | +### 2.2 Excel 导出流程 |
91 | 91 | ||
92 | - 功能原型说明 | 92 | - 功能原型说明 |
93 | 93 | ||
94 | -实现可以自定义选择列进行导出,以及选择导出格式,导出格式有 ``xlsx``\\``csv``,功能如下图所示: | 94 | +实现可以自定义选择列进行导出,以及选择导出格式,导出格式有 `xlsx`\\`csv`,功能如下图所示: |
95 | 95 | ||
96 | ![](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) |
97 | 97 | ||
98 | - 前后端交互说明 | 98 | - 前后端交互说明 |
99 | 99 | ||
100 | -``接口定义`` | 100 | +`接口定义` |
101 | 101 | ||
102 | 导出接口 | 102 | 导出接口 |
103 | + | ||
103 | ```shell | 104 | ```shell |
104 | POST /v1/web/file-export | 105 | POST /v1/web/file-export |
105 | 106 | ||
@@ -135,9 +136,7 @@ GET/v1/web/file-export/fields/:code | @@ -135,9 +136,7 @@ GET/v1/web/file-export/fields/:code | ||
135 | 136 | ||
136 | - 交互流程 | 137 | - 交互流程 |
137 | 138 | ||
138 | -1.前台根据 ``导出列查询接口`` 获取可以导出的列; | ||
139 | -2.勾选需要导出的列、文件格式,调用 ``导出接口`` 向后台发起导出数据请求; | ||
140 | - | 139 | + 1.前台根据 `导出列查询接口` 获取可以导出的列; 2.勾选需要导出的列、文件格式,调用 `导出接口` 向后台发起导出数据请求; |
141 | 140 | ||
142 | #### 2.2.1 后端导出实现 | 141 | #### 2.2.1 后端导出实现 |
143 | 142 | ||
@@ -153,6 +152,7 @@ type ExcelMaker interface { | @@ -153,6 +152,7 @@ type ExcelMaker interface { | ||
153 | ``` | 152 | ``` |
154 | 153 | ||
155 | 如下所示 | 154 | 如下所示 |
155 | + | ||
156 | ```go | 156 | ```go |
157 | //ExportCooperationUserData 导出共创用户数据 | 157 | //ExportCooperationUserData 导出共创用户数据 |
158 | type ExportCooperationUserData struct { | 158 | type ExportCooperationUserData struct { |
@@ -256,5 +256,5 @@ func (controller *ExcelDataController) responseExcelByFile(ctx *context.Context, | @@ -256,5 +256,5 @@ func (controller *ExcelDataController) responseExcelByFile(ctx *context.Context, | ||
256 | //跳过保存文件,直接写入ctx.ResponseWriter | 256 | //跳过保存文件,直接写入ctx.ResponseWriter |
257 | excelExport.ExcelFile.Write(ctx.ResponseWriter) | 257 | excelExport.ExcelFile.Write(ctx.ResponseWriter) |
258 | return nil | 258 | return nil |
259 | -} | 259 | +} |
260 | ``` | 260 | ``` |
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 | +} |
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 | +} |
@@ -9,7 +9,7 @@ type SaveProductTroubleCommand struct { | @@ -9,7 +9,7 @@ type SaveProductTroubleCommand struct { | ||
9 | WorkerId int `json:"workerId"` //员工id | 9 | WorkerId int `json:"workerId"` //员工id |
10 | Remark string `json:"remark"` //备注 | 10 | Remark string `json:"remark"` //备注 |
11 | AmountLoss float64 `json:"amountLoss"` // 损失的金额 | 11 | AmountLoss float64 `json:"amountLoss"` // 损失的金额 |
12 | - Types int `json:"types"` // 事故类型 1 安全事故 ,2 质量事故, 3 金属事故 ,4 非金属事故 | 12 | + Types string `json:"types"` // 事故类型 1 安全事故 ,2 质量事故, 3 金属事故 ,4 非金属事故 |
13 | RecordDate string `json:"recordDate"` // 事故发生的日期 | 13 | RecordDate string `json:"recordDate"` // 事故发生的日期 |
14 | SaveAndApprove bool `json:"saveAndApprove"` //保存并审核 | 14 | SaveAndApprove bool `json:"saveAndApprove"` //保存并审核 |
15 | } | 15 | } |
@@ -13,5 +13,5 @@ type ProductTroubleInfo struct { | @@ -13,5 +13,5 @@ type ProductTroubleInfo struct { | ||
13 | Remark string `json:"remark"` //备注 | 13 | Remark string `json:"remark"` //备注 |
14 | ProductDate string `json:"productDate"` //日期 | 14 | ProductDate string `json:"productDate"` //日期 |
15 | AmountLoss float64 `json:"amountLoss"` //损失的金额 | 15 | AmountLoss float64 `json:"amountLoss"` //损失的金额 |
16 | - Types int `json:"types"` //事故类型 | 16 | + Types string `json:"types"` //事故类型 |
17 | } | 17 | } |
1 | package service | 1 | package service |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "strconv" | ||
5 | + "strings" | ||
4 | "time" | 6 | "time" |
5 | 7 | ||
6 | "github.com/linmadan/egglib-go/core/application" | 8 | "github.com/linmadan/egglib-go/core/application" |
@@ -149,7 +151,7 @@ func (srv ProductTroubleService) GetProductTrouble(id int) (*dto.ProductTroubleI | @@ -149,7 +151,7 @@ func (srv ProductTroubleService) GetProductTrouble(id int) (*dto.ProductTroubleI | ||
149 | Remark: troubleData.Remark, | 151 | Remark: troubleData.Remark, |
150 | ProductDate: troubleData.RecordData.Format("2006-01-02"), | 152 | ProductDate: troubleData.RecordData.Format("2006-01-02"), |
151 | AmountLoss: troubleData.AmountLoss, | 153 | AmountLoss: troubleData.AmountLoss, |
152 | - Types: int(troubleData.Types), | 154 | + Types: string(troubleData.Types), |
153 | WorkerId: troubleData.ProductWorker.UserId, | 155 | WorkerId: troubleData.ProductWorker.UserId, |
154 | WorkerName: troubleData.ProductWorker.UserName, | 156 | WorkerName: troubleData.ProductWorker.UserName, |
155 | } | 157 | } |
@@ -294,5 +296,158 @@ func (srv ProductTroubleService) ListProductTrouble(param *query.ListProductTrou | @@ -294,5 +296,158 @@ func (srv ProductTroubleService) ListProductTrouble(param *query.ListProductTrou | ||
294 | } | 296 | } |
295 | result = append(result, item) | 297 | result = append(result, item) |
296 | } | 298 | } |
299 | + | ||
297 | return cnt, result, nil | 300 | return cnt, result, nil |
298 | } | 301 | } |
302 | + | ||
303 | +// 批量添加事故数据 | ||
304 | +func (srv ProductTroubleService) BatchAddProductTrouble(operateInfo *domain.OperateInfo, param []command.BatchAddProductTroubleCommand) (failRows []interface{}, err error) { | ||
305 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
306 | + if err != nil { | ||
307 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
308 | + } | ||
309 | + if err := transactionContext.StartTransaction(); err != nil { | ||
310 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
311 | + } | ||
312 | + defer func() { | ||
313 | + transactionContext.RollbackTransaction() | ||
314 | + }() | ||
315 | + | ||
316 | + //获取当前操作人 | ||
317 | + userSrv := domainService.NewUserService() | ||
318 | + operateUser, err := userSrv.User(operateInfo.UserId) | ||
319 | + if err != nil { | ||
320 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, "查询操作人数据失败。"+err.Error()) | ||
321 | + } | ||
322 | + | ||
323 | + //生产班组 数据 | ||
324 | + productGroupRepo, _ := factory.CreateProductGroupRepository(map[string]interface{}{ | ||
325 | + "transactionContext": transactionContext, | ||
326 | + }) | ||
327 | + _, productGroupList, err := productGroupRepo.Find(map[string]interface{}{ | ||
328 | + "companyId": operateInfo.CompanyId, | ||
329 | + "orgId": operateInfo.OrgId, | ||
330 | + }) | ||
331 | + if err != nil { | ||
332 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
333 | + } | ||
334 | + //车间名称+/+线别名称+/+工段名称 作为键名 | ||
335 | + workStationMap := map[string]*domain.WorkStation{} | ||
336 | + //车间名称+/+工人名 作为键名 | ||
337 | + workerMap := map[string][]*domain.User{} | ||
338 | + //班组名称 作为键名 | ||
339 | + productGroupMap := map[string]*domain.ProductGroup{} | ||
340 | + for _, v := range productGroupList { | ||
341 | + workStationName := strings.Join([]string{ | ||
342 | + v.WorkStation.WorkshopName, v.WorkStation.LineName, v.WorkStation.SectionName, | ||
343 | + }, "/") | ||
344 | + workStationMap[workStationName] = v.WorkStation | ||
345 | + productGroupMap[v.GroupName] = v | ||
346 | + for _, vv := range v.GroupMembers { | ||
347 | + k := v.WorkStation.WorkshopName + "/" + vv.UserName | ||
348 | + isIn := false | ||
349 | + for _, vvv := range workerMap[k] { | ||
350 | + if vvv.UserId == vv.UserId { | ||
351 | + isIn = true | ||
352 | + break | ||
353 | + } | ||
354 | + } | ||
355 | + if !isIn { | ||
356 | + workerMap[k] = append(workerMap[k], vv) | ||
357 | + } | ||
358 | + } | ||
359 | + } | ||
360 | + | ||
361 | + troubleDataList := make([]*domain.ProductTrouble, 0, len(param)) | ||
362 | + nowTime := time.Now() | ||
363 | + for i := range param { | ||
364 | + //检查字段 | ||
365 | + err = param[i].ValidField() | ||
366 | + if err != nil { | ||
367 | + param[i].FailReason = err.Error() | ||
368 | + failRows = append(failRows, param[i]) | ||
369 | + continue | ||
370 | + } | ||
371 | + //检查日期格式 | ||
372 | + recordDate, err := time.ParseInLocation("2006-01-02", param[i].RecordDate, time.Local) | ||
373 | + if err != nil { | ||
374 | + param[i].FailReason = "日期格式错误,例 2006-01-02。" | ||
375 | + failRows = append(failRows, param[i]) | ||
376 | + continue | ||
377 | + } | ||
378 | + //检查工位 | ||
379 | + var workStation *domain.WorkStation | ||
380 | + workStationName := param[i].WorkerName + "/" + param[i].LineName + "/" + param[i].SectionName | ||
381 | + if v, ok := workStationMap[workStationName]; ok { | ||
382 | + workStation = v | ||
383 | + } else { | ||
384 | + param[i].FailReason = "车间、线别、工段不存在" | ||
385 | + failRows = append(failRows, param[i]) | ||
386 | + continue | ||
387 | + } | ||
388 | + //检查员工姓名 | ||
389 | + var worker *domain.User | ||
390 | + workKey := param[i].WorkshopName + "/" + param[i].WorkerName | ||
391 | + if u, ok := workerMap[workKey]; ok { | ||
392 | + if len(u) > 1 { | ||
393 | + param[i].FailReason = "当前车间存在重复的用户名" | ||
394 | + failRows = append(failRows, param[i]) | ||
395 | + continue | ||
396 | + } | ||
397 | + worker = u[0] | ||
398 | + } else { | ||
399 | + param[i].FailReason = "当前车间不存在用户" + param[i].WorkerName | ||
400 | + failRows = append(failRows, param[i]) | ||
401 | + continue | ||
402 | + } | ||
403 | + //损失金额 | ||
404 | + amountLoss, err := strconv.ParseFloat(param[i].AmountLoss, 64) | ||
405 | + if err != nil { | ||
406 | + param[i].FailReason = "损失金额填写错误" | ||
407 | + failRows = append(failRows, param[i]) | ||
408 | + continue | ||
409 | + } | ||
410 | + item := &domain.ProductTrouble{ | ||
411 | + Id: 0, | ||
412 | + CompanyId: 0, | ||
413 | + OrgId: 0, | ||
414 | + WorkStation: *workStation, | ||
415 | + ProductWorker: *worker, | ||
416 | + AmountLoss: amountLoss, | ||
417 | + Types: "", | ||
418 | + RecordData: recordDate, | ||
419 | + Remark: "", | ||
420 | + ApproveStatus: domain.TroubleIsApprove, | ||
421 | + ApproveAt: &nowTime, | ||
422 | + ApproveUser: operateUser, | ||
423 | + CreatedAt: nowTime, | ||
424 | + UpdatedAt: nowTime, | ||
425 | + DeletedAt: nil, | ||
426 | + } | ||
427 | + err = item.SetTypes(param[i].TypesName) | ||
428 | + if err != nil { | ||
429 | + param[i].FailReason = "事故类型填写错误" | ||
430 | + failRows = append(failRows, param[i]) | ||
431 | + continue | ||
432 | + } | ||
433 | + troubleDataList = append(troubleDataList, item) | ||
434 | + } | ||
435 | + | ||
436 | + if len(failRows) > 0 { | ||
437 | + return failRows, nil | ||
438 | + } | ||
439 | + productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{ | ||
440 | + "transactionContext": transactionContext, | ||
441 | + }) | ||
442 | + //添加事故数据 | ||
443 | + for i := range troubleDataList { | ||
444 | + _, err = productTroubleRepo.Save(troubleDataList[i]) | ||
445 | + if err != nil { | ||
446 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
447 | + } | ||
448 | + } | ||
449 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
450 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
451 | + } | ||
452 | + return nil, nil | ||
453 | +} |
@@ -25,14 +25,14 @@ type ProductTrouble struct { | @@ -25,14 +25,14 @@ type ProductTrouble struct { | ||
25 | } | 25 | } |
26 | 26 | ||
27 | // 事故类型 | 27 | // 事故类型 |
28 | -type TroubleType int | 28 | +type TroubleType string |
29 | 29 | ||
30 | // 事故类型 1 安全事故 ,2 质量事故, 3 金属事故 ,4 非金属事故 | 30 | // 事故类型 1 安全事故 ,2 质量事故, 3 金属事故 ,4 非金属事故 |
31 | const ( | 31 | const ( |
32 | - TroubleType1 TroubleType = 1 | ||
33 | - TroubleType2 TroubleType = 2 | ||
34 | - TroubleType3 TroubleType = 3 | ||
35 | - TroubleType4 TroubleType = 4 | 32 | + TroubleType1 TroubleType = "安全事故" |
33 | + TroubleType2 TroubleType = "质量事故" | ||
34 | + TroubleType3 TroubleType = "金属事故" | ||
35 | + TroubleType4 TroubleType = "非金属事故" | ||
36 | ) | 36 | ) |
37 | 37 | ||
38 | // 事故管理 审核状态 | 38 | // 事故管理 审核状态 |
@@ -51,7 +51,7 @@ type ProductTroubleRepository interface { | @@ -51,7 +51,7 @@ type ProductTroubleRepository interface { | ||
51 | Find(queryOptions map[string]interface{}) (int64, []*ProductTrouble, error) | 51 | Find(queryOptions map[string]interface{}) (int64, []*ProductTrouble, error) |
52 | } | 52 | } |
53 | 53 | ||
54 | -func (m *ProductTrouble) SetTypes(v int) error { | 54 | +func (m *ProductTrouble) SetTypes(v string) error { |
55 | troubleType := TroubleType(v) | 55 | troubleType := TroubleType(v) |
56 | switch troubleType { | 56 | switch troubleType { |
57 | case TroubleType1, TroubleType2, TroubleType3, TroubleType4: | 57 | case TroubleType1, TroubleType2, TroubleType3, TroubleType4: |
@@ -2,7 +2,7 @@ package domain | @@ -2,7 +2,7 @@ package domain | ||
2 | 2 | ||
3 | import "time" | 3 | import "time" |
4 | 4 | ||
5 | -//RewardStandard 奖惩规则 | 5 | +// RewardStandard 奖惩规则 |
6 | type RewardRule struct { | 6 | type RewardRule struct { |
7 | Id int `json:"id"` //奖惩规则id | 7 | Id int `json:"id"` //奖惩规则id |
8 | CompanyId int `json:"companyId"` //企业id | 8 | CompanyId int `json:"companyId"` //企业id |
@@ -14,6 +14,7 @@ type RewardRule struct { | @@ -14,6 +14,7 @@ type RewardRule struct { | ||
14 | FaultNum int `json:"faultNum"` | 14 | FaultNum int `json:"faultNum"` |
15 | FaultAmount string `json:"faultAmount"` | 15 | FaultAmount string `json:"faultAmount"` |
16 | Remark string `json:"remark"` | 16 | Remark string `json:"remark"` |
17 | + IsBackup int `json:"IsBackup"` //是否作为备份遗留的 0 否 1 是 | ||
17 | CreatedAt time.Time | 18 | CreatedAt time.Time |
18 | UpdatedAt time.Time | 19 | UpdatedAt time.Time |
19 | } | 20 | } |
@@ -41,3 +42,12 @@ func (m *RewardRule) ValidFaultTag() bool { | @@ -41,3 +42,12 @@ func (m *RewardRule) ValidFaultTag() bool { | ||
41 | } | 42 | } |
42 | return true | 43 | return true |
43 | } | 44 | } |
45 | + | ||
46 | +// 编辑 奖惩标准时 ,是否需要将旧数据做备份处理 | ||
47 | +func (m *RewardRule) NeedMakeBackup() bool { | ||
48 | + // 当前时间与 数据最后更新的时间 不是同一天时 | ||
49 | + // 备份数据 | ||
50 | + updateAt := m.UpdatedAt.Local().Format("2006-01-02") | ||
51 | + nowDate := time.Now().Format("2006-01-02") | ||
52 | + return !(updateAt == nowDate) | ||
53 | +} |
@@ -7,7 +7,7 @@ import ( | @@ -7,7 +7,7 @@ import ( | ||
7 | "time" | 7 | "time" |
8 | ) | 8 | ) |
9 | 9 | ||
10 | -//RewardStandard 奖惩标准 | 10 | +// RewardStandard 奖惩标准 |
11 | type RewardStandard struct { | 11 | type RewardStandard struct { |
12 | Id int `json:"id"` //奖惩标准id | 12 | Id int `json:"id"` //奖惩标准id |
13 | CompanyId int `json:"companyId"` //企业id | 13 | CompanyId int `json:"companyId"` //企业id |
@@ -16,6 +16,7 @@ type RewardStandard struct { | @@ -16,6 +16,7 @@ type RewardStandard struct { | ||
16 | ProductLine SimpleProductLine `json:"productLine"` //生产线 | 16 | ProductLine SimpleProductLine `json:"productLine"` //生产线 |
17 | ProductSection ProductSection `json:"ProductSection"` //工段 | 17 | ProductSection ProductSection `json:"ProductSection"` //工段 |
18 | Remark string `json:"remark"` //备注 | 18 | Remark string `json:"remark"` //备注 |
19 | + IsBackup int `json:"IsBackup"` //是否作为备份遗留的 0 否 1是 | ||
19 | TargetType int `json:"targetType"` //指标类别 1:产效 2:合格率 3:安全事故 4:质量事故 5:异物次数 | 20 | TargetType int `json:"targetType"` //指标类别 1:产效 2:合格率 3:安全事故 4:质量事故 5:异物次数 |
20 | TargeVal1 string `json:"targeVal1"` //填写的指标值1 | 21 | TargeVal1 string `json:"targeVal1"` //填写的指标值1 |
21 | TargeVal2 string `json:"targeVal2"` //填写的指标值2 | 22 | TargeVal2 string `json:"targeVal2"` //填写的指标值2 |
@@ -44,7 +45,7 @@ type RewardStandardRepository interface { | @@ -44,7 +45,7 @@ type RewardStandardRepository interface { | ||
44 | Find(queryOptions map[string]interface{}) (int64, []*RewardStandard, error) | 45 | Find(queryOptions map[string]interface{}) (int64, []*RewardStandard, error) |
45 | } | 46 | } |
46 | 47 | ||
47 | -//指标类别 1:产效 2:合格率 3:安全事故 4:质量事故 5:异物次数 | 48 | +// 指标类别 1:产效 2:合格率 3:安全事故 4:质量事故 5:异物次数 |
48 | const ( | 49 | const ( |
49 | TargetType1 int = 1 | 50 | TargetType1 int = 1 |
50 | TargetType2 int = 2 | 51 | TargetType2 int = 2 |
@@ -53,7 +54,7 @@ const ( | @@ -53,7 +54,7 @@ const ( | ||
53 | TargetType5 int = 5 | 54 | TargetType5 int = 5 |
54 | ) | 55 | ) |
55 | 56 | ||
56 | -//UpdateTarge 更新指标内容 | 57 | +// UpdateTarge 更新指标内容 |
57 | func (m *RewardStandard) UpdateTarge(targetType int, targeVal1 string, targeVal2 string, targeVal3 string, targeVal4 string) error { | 58 | func (m *RewardStandard) UpdateTarge(targetType int, targeVal1 string, targeVal2 string, targeVal3 string, targeVal4 string) error { |
58 | switch targetType { | 59 | switch targetType { |
59 | case TargetType1, TargetType2: | 60 | case TargetType1, TargetType2: |
@@ -105,7 +106,7 @@ func (m *RewardStandard) UpdateTarge(targetType int, targeVal1 string, targeVal2 | @@ -105,7 +106,7 @@ func (m *RewardStandard) UpdateTarge(targetType int, targeVal1 string, targeVal2 | ||
105 | return nil | 106 | return nil |
106 | } | 107 | } |
107 | 108 | ||
108 | -//TargetTypeName | 109 | +// TargetTypeName |
109 | func (m *RewardStandard) TargetTypeName() string { | 110 | func (m *RewardStandard) TargetTypeName() string { |
110 | switch m.TargetType { | 111 | switch m.TargetType { |
111 | case TargetType1: | 112 | case TargetType1: |
@@ -122,7 +123,7 @@ func (m *RewardStandard) TargetTypeName() string { | @@ -122,7 +123,7 @@ func (m *RewardStandard) TargetTypeName() string { | ||
122 | return "" | 123 | return "" |
123 | } | 124 | } |
124 | 125 | ||
125 | -//ShowTargeReward 功过指标描述,功劳 | 126 | +// ShowTargeReward 功过指标描述,功劳 |
126 | func (m *RewardStandard) ShowTargeReward() string { | 127 | func (m *RewardStandard) ShowTargeReward() string { |
127 | show := "" | 128 | show := "" |
128 | switch m.TargetType { | 129 | switch m.TargetType { |
@@ -140,7 +141,7 @@ func (m *RewardStandard) ShowTargeReward() string { | @@ -140,7 +141,7 @@ func (m *RewardStandard) ShowTargeReward() string { | ||
140 | return show | 141 | return show |
141 | } | 142 | } |
142 | 143 | ||
143 | -//ShowTargeFault 功过指标描述,过失 | 144 | +// ShowTargeFault 功过指标描述,过失 |
144 | func (m *RewardStandard) ShowTargeFault() string { | 145 | func (m *RewardStandard) ShowTargeFault() string { |
145 | show := "" | 146 | show := "" |
146 | switch m.TargetType { | 147 | switch m.TargetType { |
@@ -157,3 +158,12 @@ func (m *RewardStandard) ShowTargeFault() string { | @@ -157,3 +158,12 @@ func (m *RewardStandard) ShowTargeFault() string { | ||
157 | } | 158 | } |
158 | return show | 159 | return show |
159 | } | 160 | } |
161 | + | ||
162 | +// 编辑 奖惩标准时 ,是否需要将旧数据做备份处理 | ||
163 | +func (m *RewardStandard) NeedMakeBackup() bool { | ||
164 | + // 当前时间与 数据最后更新的时间 不是同一天时 | ||
165 | + // 备份数据 | ||
166 | + updateAt := m.UpdatedAt.Local().Format("2006-01-02") | ||
167 | + nowDate := time.Now().Format("2006-01-02") | ||
168 | + return !(updateAt == nowDate) | ||
169 | +} |
@@ -15,7 +15,7 @@ type ProductTrouble struct { | @@ -15,7 +15,7 @@ type ProductTrouble struct { | ||
15 | WorkStation domain.WorkStation // 工作位置 | 15 | WorkStation domain.WorkStation // 工作位置 |
16 | ProductWorker domain.User // 生产工人 | 16 | ProductWorker domain.User // 生产工人 |
17 | AmountLoss float64 // 损失的金额 | 17 | AmountLoss float64 // 损失的金额 |
18 | - Types int // 事故类型 | 18 | + Types string // 事故类型 |
19 | RecordData time.Time // 事故发生的日期 | 19 | RecordData time.Time // 事故发生的日期 |
20 | Remark string // 备注 | 20 | Remark string // 备注 |
21 | ApproveStatus int // 审核状态 1:未审核 2:已审核 3.自动审核 | 21 | ApproveStatus int // 审核状态 1:未审核 2:已审核 3.自动审核 |
@@ -34,7 +34,7 @@ func (repo *ProductTroubleRepository) Save(param *domain.ProductTrouble) (*domai | @@ -34,7 +34,7 @@ func (repo *ProductTroubleRepository) Save(param *domain.ProductTrouble) (*domai | ||
34 | WorkStation: param.WorkStation, | 34 | WorkStation: param.WorkStation, |
35 | ProductWorker: param.ProductWorker, | 35 | ProductWorker: param.ProductWorker, |
36 | AmountLoss: param.AmountLoss, | 36 | AmountLoss: param.AmountLoss, |
37 | - Types: int(param.Types), | 37 | + Types: string(param.Types), |
38 | RecordData: param.RecordData, | 38 | RecordData: param.RecordData, |
39 | Remark: param.Remark, | 39 | Remark: param.Remark, |
40 | ApproveStatus: int(param.ApproveStatus), | 40 | ApproveStatus: int(param.ApproveStatus), |
@@ -30,6 +30,7 @@ func (controller *ExcelDataController) responseExcelByFile(ctx *context.Context, | @@ -30,6 +30,7 @@ func (controller *ExcelDataController) responseExcelByFile(ctx *context.Context, | ||
30 | return nil | 30 | return nil |
31 | } | 31 | } |
32 | 32 | ||
33 | +// FileImport 导入excel数据 | ||
33 | func (controller *ExcelDataController) FileImport() { | 34 | func (controller *ExcelDataController) FileImport() { |
34 | var ( | 35 | var ( |
35 | data interface{} | 36 | data interface{} |
@@ -55,6 +56,8 @@ func (controller *ExcelDataController) FileImport() { | @@ -55,6 +56,8 @@ func (controller *ExcelDataController) FileImport() { | ||
55 | // data, err = excelService.ImportCooperationUser(cmd) | 56 | // data, err = excelService.ImportCooperationUser(cmd) |
56 | //case domain.ImportOrganization: | 57 | //case domain.ImportOrganization: |
57 | // data, err = excelService.ImportOrganization(cmd) | 58 | // data, err = excelService.ImportOrganization(cmd) |
59 | + case "ImportProductTrouble": | ||
60 | + data, err = excelService.ImportProductTrouble(cmd) | ||
58 | case "ImportProductRecord": | 61 | case "ImportProductRecord": |
59 | data, err = excelService.ImportProductRecord(cmd) | 62 | data, err = excelService.ImportProductRecord(cmd) |
60 | case "ImportAttendance": | 63 | case "ImportAttendance": |
-
请 注册 或 登录 后发表评论