正在显示
9 个修改的文件
包含
98 行增加
和
18 行删除
deploy/db/db_device_data_bak_script.sql
0 → 100644
1 | +select count(*) from manufacture.device_running_record where device_running_record_id <=2000000 | ||
2 | +select count(*) from manufacture.device_collections where created_at <'2022-6-01 16:00:00' | ||
3 | + | ||
4 | +--1.备份设备运行数据-按数量 | ||
5 | +-- 备份数据 2000000 | ||
6 | +select * into table manufacture.device_running_record_0_2000 | ||
7 | +from manufacture.device_running_record | ||
8 | +where device_running_record_id <=2000000 | ||
9 | +-- 删除数据 | ||
10 | +delete from manufacture.device_running_record where device_running_record_id <=2000000; | ||
11 | +-- 重建索引 | ||
12 | +reindex table manufacture.device_running_record; | ||
13 | + | ||
14 | + | ||
15 | + | ||
16 | +--2.备份设备采集数据-按时间 | ||
17 | +-- 备份数据 2000000 | ||
18 | +select * into table manufacture.device_collections_history | ||
19 | +from manufacture.device_collections | ||
20 | +where created_at <'2022-6-01 16:00:00' | ||
21 | +-- 删除数据 | ||
22 | +delete from manufacture.device_collections where created_at <'2022-6-01 16:00:00'; | ||
23 | +-- 重建索引 | ||
24 | +reindex table manufacture.device_collections; | ||
25 | + | ||
26 | + | ||
27 | +--3.查看备份情况 | ||
28 | +select count(*) from manufacture.device_running_record_0_2000 | ||
29 | +select count(*) from manufacture.device_collections_history | ||
30 | +select count(*) from manufacture.device_collections where created_at <'2022-6-01 16:00:00' |
@@ -3,9 +3,12 @@ package main | @@ -3,9 +3,12 @@ package main | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | "github.com/beego/beego/v2/server/web" | 5 | "github.com/beego/beego/v2/server/web" |
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/crontab" | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" |
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" |
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" |
10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/mqtt" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/task" | ||
9 | "time" | 12 | "time" |
10 | 13 | ||
11 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | 14 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" |
@@ -27,11 +30,11 @@ func main() { | @@ -27,11 +30,11 @@ func main() { | ||
27 | log.Logger.Info("server start ....") | 30 | log.Logger.Info("server start ....") |
28 | log.Logger.Debug(fmt.Sprintf("ENABLE_KAFKA_LOG:%v", constant.ENABLE_KAFKA_LOG)) | 31 | log.Logger.Debug(fmt.Sprintf("ENABLE_KAFKA_LOG:%v", constant.ENABLE_KAFKA_LOG)) |
29 | 32 | ||
30 | - //go mqtt.Start(log.Logger) | ||
31 | - //go task.Run() | ||
32 | - //cron := crontab.NewCrontabService(nil) | ||
33 | - //cron.StartCrontabTask() | ||
34 | - //defer cron.StopCrontabTask() | 33 | + go mqtt.Start(log.Logger) |
34 | + go task.Run() | ||
35 | + cron := crontab.NewCrontabService(nil) | ||
36 | + cron.StartCrontabTask() | ||
37 | + defer cron.StopCrontabTask() | ||
35 | time.Sleep(time.Second) | 38 | time.Sleep(time.Second) |
36 | log.Logger.Info("server start!") | 39 | log.Logger.Info("server start!") |
37 | web.Run() | 40 | web.Run() |
@@ -4,6 +4,7 @@ import ( | @@ -4,6 +4,7 @@ import ( | ||
4 | "fmt" | 4 | "fmt" |
5 | "github.com/beego/beego/v2/core/validation" | 5 | "github.com/beego/beego/v2/core/validation" |
6 | "reflect" | 6 | "reflect" |
7 | + "regexp" | ||
7 | "strings" | 8 | "strings" |
8 | ) | 9 | ) |
9 | 10 | ||
@@ -33,7 +34,20 @@ type CreateProductMaterialCommand struct { | @@ -33,7 +34,20 @@ type CreateProductMaterialCommand struct { | ||
33 | } | 34 | } |
34 | 35 | ||
35 | func (createProductMaterialCommand *CreateProductMaterialCommand) Valid(validation *validation.Validation) { | 36 | func (createProductMaterialCommand *CreateProductMaterialCommand) Valid(validation *validation.Validation) { |
36 | - //validation.SetError("CustomValid", "未实现的自定义认证") | 37 | + createProductMaterialCommand.MaterialNumber = strings.ToUpper(createProductMaterialCommand.MaterialNumber) |
38 | + match, err := regexp.MatchString("^[A-Z0-9]+$", createProductMaterialCommand.MaterialNumber) | ||
39 | + if !match { | ||
40 | + validation.Error("物料编码只允许数字加大写字母组合") | ||
41 | + return | ||
42 | + } | ||
43 | + if err != nil { | ||
44 | + validation.Error(err.Error()) | ||
45 | + return | ||
46 | + } | ||
47 | + if len([]rune(createProductMaterialCommand.Specification)) > 50 { | ||
48 | + validation.Error("规格最多允许50个字符") | ||
49 | + return | ||
50 | + } | ||
37 | } | 51 | } |
38 | 52 | ||
39 | func (createProductMaterialCommand *CreateProductMaterialCommand) ValidateCommand() error { | 53 | func (createProductMaterialCommand *CreateProductMaterialCommand) ValidateCommand() error { |
@@ -36,7 +36,10 @@ type UpdateProductMaterialCommand struct { | @@ -36,7 +36,10 @@ type UpdateProductMaterialCommand struct { | ||
36 | } | 36 | } |
37 | 37 | ||
38 | func (updateProductMaterialCommand *UpdateProductMaterialCommand) Valid(validation *validation.Validation) { | 38 | func (updateProductMaterialCommand *UpdateProductMaterialCommand) Valid(validation *validation.Validation) { |
39 | - //validation.SetError("CustomValid", "未实现的自定义认证") | 39 | + if len([]rune(updateProductMaterialCommand.Specification)) > 50 { |
40 | + validation.Error("规格最多允许50个字符") | ||
41 | + return | ||
42 | + } | ||
40 | } | 43 | } |
41 | 44 | ||
42 | func (updateProductMaterialCommand *UpdateProductMaterialCommand) ValidateCommand() error { | 45 | func (updateProductMaterialCommand *UpdateProductMaterialCommand) ValidateCommand() error { |
@@ -91,7 +91,7 @@ func (productMaterialService *ProductMaterialService) GetProductMaterial(operate | @@ -91,7 +91,7 @@ func (productMaterialService *ProductMaterialService) GetProductMaterial(operate | ||
91 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductMaterialQuery.ProductMaterialId))) | 91 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductMaterialQuery.ProductMaterialId))) |
92 | } else { | 92 | } else { |
93 | materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) | 93 | materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) |
94 | - productMaterialGroupIdNames, _, err := materialService.AllMaterialGroupParent(operateInfo, productMaterial.ProductMaterialGroupId) | 94 | + productMaterialGroupIdNames, _, err := materialService.AllMaterialGroupParentByBacktracking(operateInfo, productMaterial.ProductMaterialGroupId) |
95 | if err != nil { | 95 | if err != nil { |
96 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 96 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
97 | } | 97 | } |
@@ -25,7 +25,6 @@ func (dao *DeviceDailyRunningRecordDao) TimeSectionRunningRecord(companyId, orgI | @@ -25,7 +25,6 @@ func (dao *DeviceDailyRunningRecordDao) TimeSectionRunningRecord(companyId, orgI | ||
25 | 25 | ||
26 | tx := dao.transactionContext.PgTx | 26 | tx := dao.transactionContext.PgTx |
27 | sql := fmt.Sprintf(` | 27 | sql := fmt.Sprintf(` |
28 | - | ||
29 | WITH ts_product as( | 28 | WITH ts_product as( |
30 | select sum(a.weight) total,a.ts from ( | 29 | select sum(a.weight) total,a.ts from ( |
31 | select | 30 | select |
@@ -47,8 +46,8 @@ WITH ts_product as( | @@ -47,8 +46,8 @@ WITH ts_product as( | ||
47 | -- select * from ts_product | 46 | -- select * from ts_product |
48 | , ts_product_list as ( | 47 | , ts_product_list as ( |
49 | select d.ts,ts_product.total from ( | 48 | select d.ts,ts_product.total from ( |
50 | - select to_char(c.ts::timestamp at time ZONE 'Asia/shanghai','mm-dd') ts from ( | ||
51 | - select generate_series(to_timestamp(?,'YYYY-MM-DD HH24:MI:SS'),to_timestamp(?,'YYYY-MM-DD HH24:MI:SS'),'1 day') ts | 49 | + select to_char(c.ts,'mm-dd') ts from ( |
50 | + select generate_series(to_timestamp(?,'YYYY-MM-DD HH24:MI:SS') at time ZONE 'Asia/shanghai',to_timestamp(?,'YYYY-MM-DD HH24:MI:SS') at time ZONE 'Asia/shanghai','1 day') ts | ||
52 | ) c ) d left join ts_product on d.ts = ts_product.ts | 51 | ) c ) d left join ts_product on d.ts = ts_product.ts |
53 | ) | 52 | ) |
54 | SELECT ts, coalesce(total,0) total | 53 | SELECT ts, coalesce(total,0) total |
@@ -100,7 +100,7 @@ func (ptr *PGCommonStatisticsService) HourProductiveStatistics(queryOptions map[ | @@ -100,7 +100,7 @@ func (ptr *PGCommonStatisticsService) HourProductiveStatistics(queryOptions map[ | ||
100 | beginTime = xtime.BeginningOfDay() //time.Now().Add(-time.Hour*5) | 100 | beginTime = xtime.BeginningOfDay() //time.Now().Add(-time.Hour*5) |
101 | endTime = time.Now() | 101 | endTime = time.Now() |
102 | ) | 102 | ) |
103 | - if !xtime.IsZero(request.Date.Time()) { | 103 | + if !xtime.IsZero(request.Date.Time()) && !request.Date.Time().Equal(beginTime) { |
104 | beginTime = request.Date.Time().AddDate(0, 0, -1) | 104 | beginTime = request.Date.Time().AddDate(0, 0, -1) |
105 | endTime = request.Date.Time() | 105 | endTime = request.Date.Time() |
106 | } | 106 | } |
@@ -162,13 +162,13 @@ func (ptr *PGCommonStatisticsService) DailyProductiveStatistics(queryOptions map | @@ -162,13 +162,13 @@ func (ptr *PGCommonStatisticsService) DailyProductiveStatistics(queryOptions map | ||
162 | Total float64 `json:"total"` | 162 | Total float64 `json:"total"` |
163 | } | 163 | } |
164 | var ( | 164 | var ( |
165 | - beingTime = xtime.BeginningOfDay().AddDate(0, 0, -5) | ||
166 | - endTime = xtime.BeginningOfDay().AddDate(0, 0, 1) | 165 | + beingTime = xtime.BeginningOfDay().AddDate(0, 0, -6) |
166 | + endTime = xtime.BeginningOfDay().AddDate(0, 0, 1).Add(-time.Second) | ||
167 | ) | 167 | ) |
168 | - //if !xtime.IsZero(time.Time(request.Date)) { | ||
169 | - // beingTime = request.Date.Time().AddDate(0, 0, -5) | ||
170 | - // endTime = request.Date.Time().AddDate(0, 0, 1) | ||
171 | - //} | 168 | + if !xtime.IsZero(time.Time(request.Date)) { |
169 | + beingTime = request.Date.Time().AddDate(0, 0, -6) | ||
170 | + endTime = request.Date.Time().AddDate(0, 0, 1).Add(-time.Second) | ||
171 | + } | ||
172 | workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": request.WorkshopId}) | 172 | workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": request.WorkshopId}) |
173 | if err != nil || workshop == nil { | 173 | if err != nil || workshop == nil { |
174 | return nil, nil | 174 | return nil, nil |
@@ -215,6 +215,34 @@ func (ptr *PGMaterialService) AllMaterialGroupParent(opt *domain.OperateInfo, pr | @@ -215,6 +215,34 @@ func (ptr *PGMaterialService) AllMaterialGroupParent(opt *domain.OperateInfo, pr | ||
215 | return result, listId, err | 215 | return result, listId, err |
216 | } | 216 | } |
217 | 217 | ||
218 | +func (ptr *PGMaterialService) AllMaterialGroupParentByBacktracking(opt *domain.OperateInfo, productMaterialGroupId int) ([]*domain.ProductMaterialGroup, []int, error) { | ||
219 | + var ( | ||
220 | + err error | ||
221 | + listId []int | ||
222 | + productMaterialGroup *domain.ProductMaterialGroup | ||
223 | + productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext) | ||
224 | + pid = productMaterialGroupId | ||
225 | + mapExists = make(map[int]int) | ||
226 | + ) | ||
227 | + var result = make([]*domain.ProductMaterialGroup, 0) | ||
228 | + for { | ||
229 | + if pid == 0 { | ||
230 | + break | ||
231 | + } | ||
232 | + if _, exists := mapExists[pid]; exists { | ||
233 | + break | ||
234 | + } | ||
235 | + mapExists[pid] = pid | ||
236 | + productMaterialGroup, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": pid, "allWithDeleted": "1"}) | ||
237 | + if err != nil || productMaterialGroup == nil { | ||
238 | + return nil, listId, fmt.Errorf("物料分组不存在") | ||
239 | + } | ||
240 | + pid = productMaterialGroup.Pid | ||
241 | + result = append([]*domain.ProductMaterialGroup{productMaterialGroup}, result...) | ||
242 | + } | ||
243 | + return result, listId, err | ||
244 | +} | ||
245 | + | ||
218 | func NewPGMaterialService(transactionContext *pgTransaction.TransactionContext) (*PGMaterialService, error) { | 246 | func NewPGMaterialService(transactionContext *pgTransaction.TransactionContext) (*PGMaterialService, error) { |
219 | if transactionContext == nil { | 247 | if transactionContext == nil { |
220 | return nil, fmt.Errorf("transactionContext参数不能为nil") | 248 | return nil, fmt.Errorf("transactionContext参数不能为nil") |
@@ -120,6 +120,9 @@ func (repository *ProductMaterialGroupRepository) FindOne(queryOptions map[strin | @@ -120,6 +120,9 @@ func (repository *ProductMaterialGroupRepository) FindOne(queryOptions map[strin | ||
120 | query.SetWhereByQueryOption("product_material_group_id = ?", "productMaterialGroupId") | 120 | query.SetWhereByQueryOption("product_material_group_id = ?", "productMaterialGroupId") |
121 | query.SetWhereByQueryOption("company_id = ?", "companyId") | 121 | query.SetWhereByQueryOption("company_id = ?", "companyId") |
122 | query.SetWhereByQueryOption("material_group_number = ?", "materialGroupNumber") | 122 | query.SetWhereByQueryOption("material_group_number = ?", "materialGroupNumber") |
123 | + if _, ok := queryOptions["allWithDeleted"]; ok { | ||
124 | + query.AllWithDeleted() | ||
125 | + } | ||
123 | if err := query.First(); err != nil { | 126 | if err := query.First(); err != nil { |
124 | if err.Error() == "pg: no rows in result set" { | 127 | if err.Error() == "pg: no rows in result set" { |
125 | return nil, domain.ErrorNotFound | 128 | return nil, domain.ErrorNotFound |
-
请 注册 或 登录 后发表评论