合并分支 'test' 到 'feature_material'
Test 查看合并请求 !9
正在显示
79 个修改的文件
包含
1569 行增加
和
284 行删除
config/app.conf
0 → 100644
1 | +POSTGRESQL_DB_NAME = allied_creation_dev | ||
2 | +POSTGRESQL_HOST = 114.55.200.59 | ||
3 | +POSTGRESQL_PORT = 31543 | ||
4 | +POSTGRESQL_USER = postgres | ||
5 | +POSTGRESQL_PASSWORD = eagle1010 | ||
6 | +DISABLE_SQL_GENERATE_COMMENT = false | ||
7 | +SERVICE_ENV = test | ||
8 | +HTTP_PORT = 8081 | ||
9 | +ENABLE_KAFKA_LOG11 = true | ||
10 | +HTTPS_PORT = 8143 | ||
11 | +ALLIED_CREATION_USER_HOST = http://allied-creation-user-dev.fjmaimaimai.com |
config/app_test.conf
0 → 100644
1 | +POSTGRESQL_DB_NAME = allied_creation_test | ||
2 | +POSTGRESQL_HOST = 114.55.200.59 | ||
3 | +POSTGRESQL_PORT = 31543 | ||
4 | +POSTGRESQL_USER = postgres | ||
5 | +POSTGRESQL_PASSWORD = eagle1010 | ||
6 | +DISABLE_SQL_GENERATE_COMMENT = false | ||
7 | +SERVICE_ENV = test | ||
8 | +HTTP_PORT = 8081 | ||
9 | +ENABLE_KAFKA_LOG11 = true | ||
10 | +HTTPS_PORT = 8143 | ||
11 | +ALLIED_CREATION_USER_HOST = http://allied-creation-user-test.fjmaimaimai.com | ||
12 | +MANUFACTURE_DEFAULT_COMPANYID = 23 | ||
13 | +MANUFACTURE_DEFAULT_ORGID = 487 | ||
14 | +MANUFACTURE_DEFAULT_WORKSHOPID = 28 |
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' |
@@ -4,4 +4,19 @@ ALTER TABLE manufacture.product_calendar ADD COLUMN break_time_periods jsonb; | @@ -4,4 +4,19 @@ ALTER TABLE manufacture.product_calendar ADD COLUMN break_time_periods jsonb; | ||
4 | 4 | ||
5 | -- 表product_attendance_record 增加字段 product_date | 5 | -- 表product_attendance_record 增加字段 product_date |
6 | alter table manufacture.product_attendance_record add COLUMN product_date timestamptz; | 6 | alter table manufacture.product_attendance_record add COLUMN product_date timestamptz; |
7 | -update manufacture.product_attendance_record set product_date = sign_in where product_date is null ; | ||
7 | +update manufacture.product_attendance_record set product_date = sign_in where product_date is null ; | ||
8 | + | ||
9 | + | ||
10 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (260, 174, '监控中心', 'BUSINESS_ALLIED-MANUFACTURING_MONITORING-CENTER', '', 'catalog', '', 5, '', '7', '38,174', 1, 0, NULL); | ||
11 | + | ||
12 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (261, 260, '生产设备监控', 'BUSINESS_ALLIED-MANUFACTURING_MONITORING-CENTER_DEVICE-MONITOR', '', 'menu', '', 1, '', '7', '38,174,233,244', 1, 2, NULL); | ||
13 | + | ||
14 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (262, 260, '生产管理看板', 'BUSINESS_ALLIED-MANUFACTURING_MONITORING-CENTER_PRODUCTION-MONITOR', '', 'menu', '', 2, '', '7', '38,174,260', 1, 2, NULL); | ||
15 | + | ||
16 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (263, 224, '新增工时', 'BUSINESS_ALLIED-MANUFACTURING_PRODUCTION_MAN-HOUR_ADD', '', 'button', '', 1, '', '7', '38,174,223,224', 1, 2, NULL); | ||
17 | + | ||
18 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (264, 174, '大屏看板', 'BUSINESS_ALLIED-MANUFACTURING_LARGE-SCREEN-SIGNAGE', '', 'catalog', '', 6, '', '7', '38,174', 1, 2, NULL); | ||
19 | + | ||
20 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (265, 264, '生产管理看板', 'BUSINESS_ALLIED-MANUFACTURING_LARGE-SCREEN-SIGNAGE_PRODUCTION', '', 'menu', 'https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20220517/object/1652752760_w66QpzZTfxsmhbM5mmBrHjpytcydMNs2.png', 1, '', '7', '38,174,264', 1, 2, NULL); | ||
21 | + | ||
22 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (266, 264, '设备监控看板', 'BUSINESS_ALLIED-MANUFACTURING_LARGE-SCREEN-SIGNAGE_DEVICE', '', 'menu', 'https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20220517/object/1652753144_XsBEXcRxJscRHCzQmxeseTAEQXTH7A7Z.png', 2, '', '7', '38,174,264', 1, 2, NULL); |
@@ -4,4 +4,25 @@ | @@ -4,4 +4,25 @@ | ||
4 | create UNIQUE INDEX idx_unq_product_material_group_company_id_org_id_material_group_number on manufacture.product_material_group using btree(company_id,org_id,material_group_number,deleted_at); | 4 | create UNIQUE INDEX idx_unq_product_material_group_company_id_org_id_material_group_number on manufacture.product_material_group using btree(company_id,org_id,material_group_number,deleted_at); |
5 | 5 | ||
6 | -- 表product_material 增加唯一索引 idx_unq_product_material_company_id_material_number | 6 | -- 表product_material 增加唯一索引 idx_unq_product_material_company_id_material_number |
7 | -create UNIQUE INDEX idx_unq_product_material_company_id_material_number on manufacture.product_material using btree(company_id,material_number,deleted_at); | ||
7 | +create UNIQUE INDEX idx_unq_product_material_company_id_material_number on manufacture.product_material using btree(company_id,material_number,deleted_at); | ||
8 | + | ||
9 | + | ||
10 | +-- 菜单脚本 | ||
11 | + | ||
12 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (269, 175, '物料信息', 'BUSINESS_ALLIED-MANUFACTURING_BASIC_MATERIAL', '', 'menu', 'https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20220302/object/1646211608_CH2pTwT56j6TXfRdYhGxBfKRNFfpzWKE.png', 3, '', '7', '38,174,175', 1, 0, NULL); | ||
13 | + | ||
14 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (270, 269, '删除', 'BUSINESS_ALLIED-MANUFACTURING_BASIC_MATERIAL_DEL', '', 'button', '', 1, '', '7', '38,174,175,269', 1, 2, NULL); | ||
15 | + | ||
16 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (271, 269, '新增', 'BUSINESS_ALLIED-MANUFACTURING_BASIC_MATERIAL_ADD', '', 'button', '', 1, '', '7', '38,174,175,269', 1, 2, NULL); | ||
17 | + | ||
18 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (272, 269, '编辑', 'BUSINESS_ALLIED-MANUFACTURING_BASIC_MATERIAL_EDIT', '', 'button', '', 1, '', '7', '38,174,175,269', 1, 2, NULL); | ||
19 | + | ||
20 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (273, 269, '查看', 'BUSINESS_ALLIED-MANUFACTURING_BASIC_MATERIAL_VIEW', '', 'button', '', 1, '', '7', '38,174,175,269', 1, 2, NULL); | ||
21 | + | ||
22 | +UPDATE "users"."menu" SET "parent_id" = 175, "menu_name" = '产品管理', "code" = 'BUSINESS_ALLIED-MANUFACTURING_BASIC_PRODUCT', "access_code" = '', "menu_type" = 'menu', "icon" = 'https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20220302/object/1646211429_wMrRfxYMyhBySwWkysZaXBbfDapSppBs.png', "sort" = 4, "remark" = '', "category" = '7', "parent_path" = '38,174,175', "is_publish" = 1, "enable_status" = 0, "link" = NULL WHERE "menu_id" = 186; | ||
23 | + | ||
24 | +UPDATE "users"."menu" SET "parent_id" = 175, "menu_name" = '设备档案', "code" = 'BUSINESS_ALLIED-MANUFACTURING_BASIC_DEVICE', "access_code" = '', "menu_type" = 'menu', "icon" = 'https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20220302/object/1646211439_WaAKb65X7wX2zjsMExDyy56XRnTRAmPD.png', "sort" = 5, "remark" = '', "category" = '7', "parent_path" = '38,174,175', "is_publish" = 1, "enable_status" = 0, "link" = NULL WHERE "menu_id" = 193; | ||
25 | + | ||
26 | +UPDATE "users"."menu" SET "parent_id" = 175, "menu_name" = '工厂日历', "code" = 'BUSINESS_ALLIED-MANUFACTURING_BASIC_CALENDAR', "access_code" = '', "menu_type" = 'menu', "icon" = 'https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20220302/object/1646211448_GBY3HhbPpNnNpnGPWGE6wETW6F6THfr4.png', "sort" = 6, "remark" = '', "category" = '7', "parent_path" = '38,174,175', "is_publish" = 1, "enable_status" = 0, "link" = NULL WHERE "menu_id" = 199; | ||
27 | + | ||
28 | +UPDATE "users"."menu" SET "parent_id" = 175, "menu_name" = '单位换算', "code" = 'BUSINESS_ALLIED-MANUFACTURING_BASIC_UNIT-CONVERSION', "access_code" = '', "menu_type" = 'menu', "icon" = 'https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20220302/object/1646211456_cKxKHHXHQnM3e7RZNxdkZ3n7ZXJjdKba.png', "sort" = 7, "remark" = '', "category" = '7', "parent_path" = '38,174,175', "is_publish" = 1, "enable_status" = 0, "link" = NULL WHERE "menu_id" = 203; |
deploy/db/v1.0.3 db_script.sql
0 → 100644
1 | + | ||
2 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (274, 42, '同步考勤机', 'ADMIN_SYSTEM-MANAGE_BASE_USER_SYNC', 'w1-1-1-1-9', 'button', '', 9, '同步考勤机', '7', '37,39,40,42', 1, 0, NULL); |
1 | +apiVersion: v1 | ||
2 | +kind: Service | ||
3 | +metadata: | ||
4 | + name: allied-creation-manufacture | ||
5 | + namespace: mmm-suplus-test | ||
6 | + labels: | ||
7 | + k8s-app: allied-creation-manufacture | ||
8 | +spec: | ||
9 | + ports: | ||
10 | + - name: "http" | ||
11 | + port: 80 | ||
12 | + targetPort: 8082 | ||
13 | + selector: | ||
14 | + k8s-app: allied-creation-manufacture | ||
15 | +--- | ||
16 | +apiVersion: extensions/v1beta1 | ||
17 | +kind: Deployment | ||
18 | +metadata: | ||
19 | + name: allied-creation-manufacture | ||
20 | + namespace: mmm-suplus-test | ||
21 | + labels: | ||
22 | + k8s-app: allied-creation-manufacture | ||
23 | +spec: | ||
24 | + replicas: 1 | ||
25 | + template: | ||
26 | + metadata: | ||
27 | + labels: | ||
28 | + k8s-app: allied-creation-manufacture | ||
29 | + spec: | ||
30 | + affinity: | ||
31 | + nodeAffinity: | ||
32 | + preferredDuringSchedulingIgnoredDuringExecution: | ||
33 | + - preference: {} | ||
34 | + weight: 100 | ||
35 | + requiredDuringSchedulingIgnoredDuringExecution: | ||
36 | + nodeSelectorTerms: | ||
37 | + - matchExpressions: | ||
38 | + - key: kubernetes.io/hostname | ||
39 | + operator: In | ||
40 | + values: | ||
41 | + - cn-hangzhou.i-bp1djh1xn7taumbue1ze | ||
42 | + - cn-hangzhou.i-bp1djh1xn7taumbue1zd | ||
43 | + - cn-hangzhou.i-bp1euf5u1ph9kbhtndhb | ||
44 | + - cn-hangzhou.i-bp1hyp5oips9cdwxxgxy | ||
45 | + containers: | ||
46 | + - name: allied-creation-manufacture | ||
47 | + image: 192.168.0.243:5000/mmm/allied-creation-manufacture:dev | ||
48 | + imagePullPolicy: Always | ||
49 | + ports: | ||
50 | + - containerPort: 8082 | ||
51 | + env: | ||
52 | + - name: POSTGRESQL_DB_NAME | ||
53 | + valueFrom: | ||
54 | + configMapKeyRef: | ||
55 | + name: suplus-config | ||
56 | + key: postgresqlalliedcreation.dbname | ||
57 | + - name: POSTGRESQL_USER | ||
58 | + valueFrom: | ||
59 | + configMapKeyRef: | ||
60 | + name: suplus-config | ||
61 | + key: postgresql.user | ||
62 | + - name: POSTGRESQL_PASSWORD | ||
63 | + valueFrom: | ||
64 | + configMapKeyRef: | ||
65 | + name: suplus-config | ||
66 | + key: postgresql.password | ||
67 | + - name: POSTGRESQL_HOST | ||
68 | + valueFrom: | ||
69 | + configMapKeyRef: | ||
70 | + name: suplus-config | ||
71 | + key: postgresql.host | ||
72 | + - name: POSTGRESQL_PORT | ||
73 | + valueFrom: | ||
74 | + configMapKeyRef: | ||
75 | + name: suplus-config | ||
76 | + key: postgresql.port | ||
77 | + - name: REDIS_HOST | ||
78 | + valueFrom: | ||
79 | + configMapKeyRef: | ||
80 | + name: suplus-config | ||
81 | + key: redis.ip | ||
82 | + - name: REDIS_PORT | ||
83 | + valueFrom: | ||
84 | + configMapKeyRef: | ||
85 | + name: suplus-config | ||
86 | + key: redis.port | ||
87 | + - name: REDIS_AUTH | ||
88 | + value: "" | ||
89 | + - name: LOG_LEVEL | ||
90 | + value: "debug" | ||
91 | + - name: ERROR_BASE_CODE | ||
92 | + value: "1" | ||
93 | + - name: ERROR_BASE_CODE_MULTIPLE | ||
94 | + value: "2000" | ||
95 | + - name: ENABLE_KAFKA_LOG | ||
96 | + value: "true" | ||
97 | + - name: HTTP_PORT | ||
98 | + value: "8082" | ||
99 | + - name: SERVICE_ENV | ||
100 | + value: "test" | ||
101 | + - name: SUPLUS_ADMIN_BASE_HOST | ||
102 | + value: "http://suplus-admin-base-dev.fjmaimaimai.com" | ||
103 | + - name: ALLIED_CREATION_GATEWAY_HOST | ||
104 | + value: "https://allied-creation-gateway-test.fjmaimaimai.com" | ||
105 | + - name: ALLIED_CREATION_USER_HOST | ||
106 | + value: "https://allied-creation-user-test.fjmaimaimai.com" | ||
107 | + - name: ALLIED_CREATION_COOPERATION_HOST | ||
108 | + value: "https://allied-creation-cooperation-test.fjmaimaimai.com" | ||
109 | + - name: ALLIED_CREATION_BASIC_HOST | ||
110 | + value: "https://allied-creation-basic-test.fjmaimaimai.com" | ||
111 | + - name: ALLIED_CREATION_MANUFACTURE_HOST | ||
112 | + value: "http://allied-creation-manufacture-test.fjmaimaimai.com" | ||
113 | + - name: SMS_SERVE_HOST | ||
114 | + value: "https://sms.fjmaimaimai.com:9897" | ||
115 | + - name: SUPLUS_SALE_APP | ||
116 | + value: "http://suplus-sale-app-gateway-test.fjmaimaimai.com" | ||
117 | + - name: MANUFACTURE_DEFAULT_COMPANYID | ||
118 | + value: "23" | ||
119 | + - name: MANUFACTURE_DEFAULT_ORGID | ||
120 | + value: "487" | ||
121 | + - name: MANUFACTURE_DEFAULT_WORKSHOPID | ||
122 | + value: "28" | ||
123 | + - name: MANUFACTURE_PRODUCT_TYPE | ||
124 | + value: "SG,SG" | ||
125 | + - name: MQTT_HOST | ||
126 | + value: "47.97.5.102" | ||
127 | + - name: MQTT_PORT | ||
128 | + value: "6000" | ||
129 | + - name: MQTT_UP | ||
130 | + value: "false" |
@@ -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" |
@@ -26,12 +29,13 @@ func main() { | @@ -26,12 +29,13 @@ func main() { | ||
26 | redis.InitRedis() | 29 | redis.InitRedis() |
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 | - | ||
30 | - //go mqtt.Start(log.Logger) | ||
31 | - //go task.Run() | ||
32 | - //cron := crontab.NewCrontabService(nil) | ||
33 | - //cron.StartCrontabTask() | ||
34 | - //defer cron.StopCrontabTask() | 32 | + if constant.MQTT_UP { |
33 | + go mqtt.Start(log.Logger) | ||
34 | + } | ||
35 | + go task.Run() | ||
36 | + cron := crontab.NewCrontabService(nil) | ||
37 | + cron.StartCrontabTask() | ||
38 | + defer cron.StopCrontabTask() | ||
35 | time.Sleep(time.Second) | 39 | time.Sleep(time.Second) |
36 | log.Logger.Info("server start!") | 40 | log.Logger.Info("server start!") |
37 | web.Run() | 41 | web.Run() |
@@ -2,11 +2,10 @@ package command | @@ -2,11 +2,10 @@ package command | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "github.com/beego/beego/v2/core/validation" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
5 | "reflect" | 7 | "reflect" |
6 | "strings" | 8 | "strings" |
7 | - "time" | ||
8 | - | ||
9 | - "github.com/beego/beego/v2/core/validation" | ||
10 | ) | 9 | ) |
11 | 10 | ||
12 | type CreateAttendanceCommand struct { | 11 | type CreateAttendanceCommand struct { |
@@ -25,11 +24,11 @@ type CreateAttendanceCommand struct { | @@ -25,11 +24,11 @@ type CreateAttendanceCommand struct { | ||
25 | // 工段ID | 24 | // 工段ID |
26 | SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` | 25 | SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` |
27 | // 生产日期 | 26 | // 生产日期 |
28 | - ProductDate time.Time `cname:"生产日期" json:"productDate,omitempty" valid:"Required"` | 27 | + ProductDate string `cname:"生产日期" json:"productDate,omitempty" valid:"Required"` |
29 | // 签到 | 28 | // 签到 |
30 | - SignIn time.Time `cname:"上岗时间" json:"signIn,omitempty" valid:"Required"` | 29 | + SignIn string `cname:"上岗时间" json:"signIn,omitempty" valid:"Required"` |
31 | // 签退 | 30 | // 签退 |
32 | - SignOut time.Time `cname:"下岗时间" json:"signOut,omitempty" valid:"Required"` | 31 | + SignOut string `cname:"下岗时间" json:"signOut,omitempty" valid:"Required"` |
33 | // 考勤状态 1.未审核 2:审核 | 32 | // 考勤状态 1.未审核 2:审核 |
34 | AttendanceStatus int `cname:"考勤状态" json:"attendanceStatus,omitempty"` | 33 | AttendanceStatus int `cname:"考勤状态" json:"attendanceStatus,omitempty"` |
35 | // 休息时长 | 34 | // 休息时长 |
@@ -41,7 +40,14 @@ type CreateAttendanceCommand struct { | @@ -41,7 +40,14 @@ type CreateAttendanceCommand struct { | ||
41 | } | 40 | } |
42 | 41 | ||
43 | func (createAttendanceCommand *CreateAttendanceCommand) Valid(validation *validation.Validation) { | 42 | func (createAttendanceCommand *CreateAttendanceCommand) Valid(validation *validation.Validation) { |
44 | - //validation.SetError("CustomValid", "未实现的自定义认证") | 43 | + if err := utils.ValidWorkTime(createAttendanceCommand.SignIn); err != nil { |
44 | + validation.Error(err.Error()) | ||
45 | + return | ||
46 | + } | ||
47 | + if err := utils.ValidWorkTime(createAttendanceCommand.SignOut); err != nil { | ||
48 | + validation.Error(err.Error()) | ||
49 | + return | ||
50 | + } | ||
45 | validation.Range(createAttendanceCommand.AttendanceStatus, 1, 2, "attendanceStatus") | 51 | validation.Range(createAttendanceCommand.AttendanceStatus, 1, 2, "attendanceStatus") |
46 | } | 52 | } |
47 | 53 |
@@ -31,6 +31,10 @@ type AttendanceRecordDto struct { | @@ -31,6 +31,10 @@ type AttendanceRecordDto struct { | ||
31 | SignOut string `json:"signOut"` | 31 | SignOut string `json:"signOut"` |
32 | // 考勤状态 1.未审核 2:已审核 3.自动审核 | 32 | // 考勤状态 1.未审核 2:已审核 3.自动审核 |
33 | AttendanceStatus int `json:"attendanceStatus"` | 33 | AttendanceStatus int `json:"attendanceStatus"` |
34 | + // 打卡工时 | ||
35 | + WorkTime float64 `json:"workTime"` | ||
36 | + // 休息工时 | ||
37 | + BreakTime float64 `json:"breakTime"` | ||
34 | // 工时(审核前) | 38 | // 工时(审核前) |
35 | WorkTimeBefore float64 `json:"workTimeBefore"` | 39 | WorkTimeBefore float64 `json:"workTimeBefore"` |
36 | // 工时(审核后) | 40 | // 工时(审核后) |
@@ -50,7 +54,7 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i | @@ -50,7 +54,7 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i | ||
50 | d.WorkStation = m.WorkStation | 54 | d.WorkStation = m.WorkStation |
51 | if !m.SignIn.IsZero() { | 55 | if !m.SignIn.IsZero() { |
52 | d.SignIn = m.SignIn.Local().Format("15:04:05") | 56 | d.SignIn = m.SignIn.Local().Format("15:04:05") |
53 | - d.SignDate = m.ProductTime().Format("2006-01-02") | 57 | + d.SignDate = m.ProductTime().Local().Format("2006-01-02") |
54 | } | 58 | } |
55 | if !m.SignOut.IsZero() { | 59 | if !m.SignOut.IsZero() { |
56 | d.SignOut = m.SignOut.Local().Format("15:04:05") | 60 | d.SignOut = m.SignOut.Local().Format("15:04:05") |
@@ -67,6 +71,8 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i | @@ -67,6 +71,8 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i | ||
67 | t := time.Unix(m.Ext.AttendanceExt.ApproveAt, 0) | 71 | t := time.Unix(m.Ext.AttendanceExt.ApproveAt, 0) |
68 | d.ApproveAt = t.Local().Format("2006-01-02 15:04:05") | 72 | d.ApproveAt = t.Local().Format("2006-01-02 15:04:05") |
69 | } | 73 | } |
74 | + d.WorkTime = m.WorkTimeBefore + m.Ext.AttendanceExt.BreakTime | ||
75 | + d.BreakTime = m.Ext.AttendanceExt.BreakTime | ||
70 | } | 76 | } |
71 | return d | 77 | return d |
72 | } | 78 | } |
@@ -14,6 +14,12 @@ type WorkshopWorkTimeRecordDto struct { | @@ -14,6 +14,12 @@ type WorkshopWorkTimeRecordDto struct { | ||
14 | //SignDate string `json:"signDate"` | 14 | //SignDate string `json:"signDate"` |
15 | // 记录信息 | 15 | // 记录信息 |
16 | *domain.WorkshopWorkTimeRecordInfo | 16 | *domain.WorkshopWorkTimeRecordInfo |
17 | + // 固定工时 | ||
18 | + EFTWorkTime float64 `json:"eftWorkTime"` | ||
19 | + // 临时工时 | ||
20 | + EDWorkTime float64 `json:"edWorkTime"` | ||
21 | + // 派遣工时 | ||
22 | + EPTWorkTime float64 `json:"eptWorkTime"` | ||
17 | // 记录日期 | 23 | // 记录日期 |
18 | RecordDate string `json:"recordDate"` | 24 | RecordDate string `json:"recordDate"` |
19 | // 组织名称 | 25 | // 组织名称 |
@@ -30,6 +36,9 @@ func (d *WorkshopWorkTimeRecordDto) LoadDto(m *domain.WorkshopWorkTimeRecord, or | @@ -30,6 +36,9 @@ func (d *WorkshopWorkTimeRecordDto) LoadDto(m *domain.WorkshopWorkTimeRecord, or | ||
30 | d.WorkshopWorkTimeRecordInfo.EPTWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EPTWorkTime, 1) | 36 | d.WorkshopWorkTimeRecordInfo.EPTWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EPTWorkTime, 1) |
31 | d.WorkshopWorkTimeRecordInfo.EDWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EDWorkTime, 1) | 37 | d.WorkshopWorkTimeRecordInfo.EDWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EDWorkTime, 1) |
32 | d.WorkshopWorkTimeRecordInfo.EFTWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EFTWorkTime, 1) | 38 | d.WorkshopWorkTimeRecordInfo.EFTWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EFTWorkTime, 1) |
39 | + d.EPTWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EPTWorkTime, 1) | ||
40 | + d.EDWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EDWorkTime, 1) | ||
41 | + d.EFTWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EFTWorkTime, 1) | ||
33 | } | 42 | } |
34 | d.WorkStation = m.WorkStation | 43 | d.WorkStation = m.WorkStation |
35 | d.RecordDate = m.RecordDate.Local().Format("2006-01-02") | 44 | d.RecordDate = m.RecordDate.Local().Format("2006-01-02") |
@@ -55,21 +55,22 @@ func (cmd *SearchEmployeeAttendanceQuery) Valid(validation *validation.Validatio | @@ -55,21 +55,22 @@ func (cmd *SearchEmployeeAttendanceQuery) Valid(validation *validation.Validatio | ||
55 | cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize) | 55 | cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize) |
56 | var err error | 56 | var err error |
57 | if len(cmd.BeginTime) > 0 { | 57 | if len(cmd.BeginTime) > 0 { |
58 | - if cmd.SignBeginTime, err = time.ParseInLocation("2006-01-02 15:04:05", cmd.BeginTime, time.Local); err != nil { | 58 | + if cmd.SignBeginTime, err = time.ParseInLocation("2006-01-02", cmd.BeginTime, time.Local); err != nil { |
59 | log.Logger.Error(err.Error()) | 59 | log.Logger.Error(err.Error()) |
60 | validation.Error("开始时间有误") | 60 | validation.Error("开始时间有误") |
61 | return | 61 | return |
62 | } | 62 | } |
63 | } | 63 | } |
64 | if len(cmd.EndTime) > 0 { | 64 | if len(cmd.EndTime) > 0 { |
65 | - if cmd.SignEndTime, err = time.ParseInLocation("2006-01-02 15:04:05", cmd.EndTime, time.Local); err != nil { | 65 | + if cmd.SignEndTime, err = time.ParseInLocation("2006-01-02", cmd.EndTime, time.Local); err != nil { |
66 | log.Logger.Error(err.Error()) | 66 | log.Logger.Error(err.Error()) |
67 | validation.Error("结束时间有误") | 67 | validation.Error("结束时间有误") |
68 | return | 68 | return |
69 | } | 69 | } |
70 | - if cmd.SignBeginTime.Equal(cmd.SignEndTime) { | ||
71 | - cmd.SignEndTime = cmd.SignEndTime.Add(time.Hour * 24) | ||
72 | - } | 70 | + cmd.SignEndTime = cmd.SignEndTime.AddDate(0, 0, 1) |
71 | + //if cmd.SignBeginTime.Equal(cmd.SignEndTime) { | ||
72 | + // cmd.SignEndTime = cmd.SignEndTime.Add(time.Hour * 24) | ||
73 | + //} | ||
73 | } | 74 | } |
74 | //cmd.AttendanceStatus = 6 // 审核 + 自动审核 | 75 | //cmd.AttendanceStatus = 6 // 审核 + 自动审核 |
75 | cmd.InAttendanceStatus = []int{2, 3} | 76 | cmd.InAttendanceStatus = []int{2, 3} |
@@ -105,9 +105,24 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | @@ -105,9 +105,24 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | ||
105 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 105 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
106 | } | 106 | } |
107 | 107 | ||
108 | - var workTime float64 = 0 | ||
109 | - if cmd.WorkTime-cmd.BreakTime > 0 { | ||
110 | - workTime = cmd.WorkTime - cmd.BreakTime | 108 | + //var workTime float64 = 0 |
109 | + //if cmd.WorkTime-cmd.BreakTime > 0 { | ||
110 | + // workTime = cmd.WorkTime - cmd.BreakTime | ||
111 | + //} | ||
112 | + signIn, err := xtime.ParseInLocation(time.Local, fmt.Sprintf("%v %v:00", cmd.ProductDate, cmd.SignIn)) | ||
113 | + if err != nil { | ||
114 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
115 | + } | ||
116 | + signOut, err := xtime.ParseInLocation(time.Local, fmt.Sprintf("%v %v:00", cmd.ProductDate, cmd.SignOut)) | ||
117 | + if err != nil { | ||
118 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
119 | + } | ||
120 | + productDate, err := xtime.ParseInLocation(time.Local, cmd.ProductDate) | ||
121 | + if err != nil { | ||
122 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
123 | + } | ||
124 | + if !xtime.BeforeEqual(productDate, time.Now()) { | ||
125 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("日期需要小于等于%v", time.Now().Format("2006-01-02"))) | ||
111 | } | 126 | } |
112 | newAttendance := &domain.ProductAttendanceRecord{ | 127 | newAttendance := &domain.ProductAttendanceRecord{ |
113 | //ProductAttendanceId: cmd.ProductAttendanceId, | 128 | //ProductAttendanceId: cmd.ProductAttendanceId, |
@@ -116,23 +131,24 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | @@ -116,23 +131,24 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | ||
116 | AttendanceType: cmd.AttendanceType, | 131 | AttendanceType: cmd.AttendanceType, |
117 | ProductWorker: user, | 132 | ProductWorker: user, |
118 | WorkStation: workStation, | 133 | WorkStation: workStation, |
119 | - SignIn: cmd.SignIn, | ||
120 | - SignOut: cmd.SignOut, | 134 | + SignIn: signIn, |
135 | + SignOut: signOut, | ||
121 | AttendanceStatus: cmd.AttendanceStatus, | 136 | AttendanceStatus: cmd.AttendanceStatus, |
122 | - WorkTimeBefore: workTime, | 137 | + WorkTimeBefore: cmd.WorkTime, |
123 | WorkTimeAfter: 0, | 138 | WorkTimeAfter: 0, |
124 | CreatedAt: time.Now(), | 139 | CreatedAt: time.Now(), |
125 | UpdatedAt: time.Now(), | 140 | UpdatedAt: time.Now(), |
126 | Ext: domain.NewExt(org.OrgName).WithAttendanceExt(&domain.ProductAttendanceRecordExt{ | 141 | Ext: domain.NewExt(org.OrgName).WithAttendanceExt(&domain.ProductAttendanceRecordExt{ |
127 | GroupName: productGroup.GroupName, | 142 | GroupName: productGroup.GroupName, |
128 | ProductGroupId: productGroup.ProductGroupId, | 143 | ProductGroupId: productGroup.ProductGroupId, |
144 | + BreakTime: cmd.BreakTime, | ||
129 | }), | 145 | }), |
130 | - ProductDate: xtime.New(cmd.ProductDate).BeginningOfDay(), | 146 | + ProductDate: productDate, |
131 | } | 147 | } |
132 | 148 | ||
133 | if cmd.AttendanceStatus == domain.AttendanceApproved { | 149 | if cmd.AttendanceStatus == domain.AttendanceApproved { |
134 | newAttendance.WorkTimeAfter = domain.AttendanceApproved | 150 | newAttendance.WorkTimeAfter = domain.AttendanceApproved |
135 | - newAttendance.WorkTimeAfter = workTime | 151 | + newAttendance.WorkTimeAfter = cmd.WorkTime |
136 | } | 152 | } |
137 | var ( | 153 | var ( |
138 | attendanceRepository domain.ProductAttendanceRecordRepository | 154 | attendanceRepository domain.ProductAttendanceRecordRepository |
@@ -142,12 +158,15 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | @@ -142,12 +158,15 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | ||
142 | attendanceRepository, _, _ = factory.FastPgAttendance(transactionContext, 0) | 158 | attendanceRepository, _, _ = factory.FastPgAttendance(transactionContext, 0) |
143 | if !cmd.Prepared { | 159 | if !cmd.Prepared { |
144 | // 检查时间段内是否有重复的打卡记录 | 160 | // 检查时间段内是否有重复的打卡记录 |
145 | - count, _, err := attendanceRecordDao.WorkerAttendanceRecordsByProductDate(operateInfo.CompanyId, operateInfo.OrgId, cmd.ProductWorkerId, newAttendance.ProductDate, cmd.SignIn, cmd.SignIn) | 161 | + count, _, err := attendanceRecordDao.WorkerAttendanceRecordsByProductDate(operateInfo.CompanyId, operateInfo.OrgId, cmd.ProductWorkerId, newAttendance.ProductDate, newAttendance.SignIn, newAttendance.SignIn) |
146 | if err != nil { | 162 | if err != nil { |
147 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 163 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
148 | } | 164 | } |
149 | if count > 0 { | 165 | if count > 0 { |
150 | - return nil, &application.ServiceError{Code: 10040001, Message: fmt.Sprintf("已存在员工%v的工时记录,是否继续新增", user.UserName)} | 166 | + return map[string]interface{}{ |
167 | + "message": fmt.Sprintf("已存在员工%v的工时记录,是否继续新增", user.UserName), | ||
168 | + "needConfirm": true, | ||
169 | + }, nil | ||
151 | } | 170 | } |
152 | } | 171 | } |
153 | if attendance, err := attendanceRepository.Save(newAttendance); err != nil { | 172 | if attendance, err := attendanceRepository.Save(newAttendance); err != nil { |
@@ -157,7 +176,7 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | @@ -157,7 +176,7 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | ||
157 | if err := transactionContext.CommitTransaction(); err != nil { | 176 | if err := transactionContext.CommitTransaction(); err != nil { |
158 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 177 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
159 | } | 178 | } |
160 | - return attendance, nil | 179 | + return struct{}{}, nil |
161 | } | 180 | } |
162 | } | 181 | } |
163 | 182 |
@@ -18,25 +18,28 @@ func NewCrontabService(options map[string]interface{}) *CrontabService { | @@ -18,25 +18,28 @@ func NewCrontabService(options map[string]interface{}) *CrontabService { | ||
18 | } | 18 | } |
19 | 19 | ||
20 | func (crontabService *CrontabService) initTask() { | 20 | func (crontabService *CrontabService) initTask() { |
21 | - //拉取物料数据 每5分执行 | ||
22 | - pullMaterialK3cloud := task.NewTask("pullMaterialK3cloud", "0 */5 0 * * *", func(ctx context.Context) error { | 21 | + //拉取物料数据 每4小时执行 |
22 | + pullMaterialK3cloud := task.NewTask("pullMaterialK3cloud", "0 0 */4 * * *", func(ctx context.Context) error { | ||
23 | srv := syncdata.PullDataK3CloudService{} | 23 | srv := syncdata.PullDataK3CloudService{} |
24 | return srv.PullMaterialNewest() | 24 | return srv.PullMaterialNewest() |
25 | }) | 25 | }) |
26 | task.AddTask("pullMaterialK3cloud", pullMaterialK3cloud) | 26 | task.AddTask("pullMaterialK3cloud", pullMaterialK3cloud) |
27 | - //拉取物料分组数据 每5分执行 | ||
28 | - pullMaterialGroupK3cloud := task.NewTask("pullMaterialGroupK3cloud", "0 */5 0 * * *", func(ctx context.Context) error { | 27 | + //拉取物料分组数据 每4小时执行 |
28 | + pullMaterialGroupK3cloud := task.NewTask("pullMaterialGroupK3cloud", "0 0 */4 * * *", func(ctx context.Context) error { | ||
29 | srv := syncdata.PullDataK3CloudService{} | 29 | srv := syncdata.PullDataK3CloudService{} |
30 | return srv.PullMaterialGroup() | 30 | return srv.PullMaterialGroup() |
31 | }) | 31 | }) |
32 | task.AddTask("pullMaterialGroupK3cloud", pullMaterialGroupK3cloud) | 32 | task.AddTask("pullMaterialGroupK3cloud", pullMaterialGroupK3cloud) |
33 | - //拉取订生产订单数据 每5分执行 | ||
34 | - PullPrdMoK3cloud := task.NewTask("PullPrdMoK3cloud", "0 */5 0 * * *", func(ctx context.Context) error { | 33 | + //拉取订生产订单数据 每4小时执行 |
34 | + PullPrdMoK3cloud := task.NewTask("PullPrdMoK3cloud", "0 0 */4 * * *", func(ctx context.Context) error { | ||
35 | srv := syncdata.PullDataK3CloudService{} | 35 | srv := syncdata.PullDataK3CloudService{} |
36 | return srv.PullPrdMoNewest() | 36 | return srv.PullPrdMoNewest() |
37 | }) | 37 | }) |
38 | task.AddTask("PullPrdMoK3cloud", PullPrdMoK3cloud) | 38 | task.AddTask("PullPrdMoK3cloud", PullPrdMoK3cloud) |
39 | 39 | ||
40 | + autoInitWorkshopProductRecord := task.NewTask("AutoInitWorkshopProductRecord", "0 0 */4 * * *", AutoInitWorkshopProductRecord) | ||
41 | + task.AddTask("AutoInitWorkshopProductRecord", autoInitWorkshopProductRecord) | ||
42 | + | ||
40 | autoApproveAttendanceRecord := task.NewTask("autoApproveAttendanceRecord", "0 */2 * * * *", AutoApproveProductAttendanceRecord) | 43 | autoApproveAttendanceRecord := task.NewTask("autoApproveAttendanceRecord", "0 */2 * * * *", AutoApproveProductAttendanceRecord) |
41 | task.AddTask("autoApproveAttendanceRecord", autoApproveAttendanceRecord) | 44 | task.AddTask("autoApproveAttendanceRecord", autoApproveAttendanceRecord) |
42 | 45 |
@@ -41,7 +41,7 @@ func AutoApproveProductRecord(ctx context.Context) error { | @@ -41,7 +41,7 @@ func AutoApproveProductRecord(ctx context.Context) error { | ||
41 | 41 | ||
42 | approveAttendanceRecordsService, _ := domainService.NewPGProductRecordService(transactionContext.(*pgTransaction.TransactionContext)) | 42 | approveAttendanceRecordsService, _ := domainService.NewPGProductRecordService(transactionContext.(*pgTransaction.TransactionContext)) |
43 | 43 | ||
44 | - if _, err = approveAttendanceRecordsService.BatchApprove(records, 0, 0, domain.AttendanceAutoApproved); err != nil { | 44 | + if _, err = approveAttendanceRecordsService.BatchApprove(records, 0, 0, domain.ProductRecordAutoApproved); err != nil { |
45 | log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时审核生产记录"}) | 45 | log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时审核生产记录"}) |
46 | return err | 46 | return err |
47 | } | 47 | } |
1 | +package crontab | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "fmt" | ||
6 | + "github.com/linmadan/egglib-go/transaction/pg" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" | ||
12 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository" | ||
13 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
14 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | ||
15 | + "time" | ||
16 | +) | ||
17 | + | ||
18 | +// AutoInitWorkshopProductRecord 自动初始化车间生产记录 | ||
19 | +func AutoInitWorkshopProductRecord(ctx context.Context) error { | ||
20 | + defer func() { | ||
21 | + if r := recover(); r != nil { | ||
22 | + log.Logger.Error(fmt.Sprintf("%v", r), map[string]interface{}{"task": "自动初始化车间生产记录"}) | ||
23 | + } | ||
24 | + }() | ||
25 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
26 | + if err != nil { | ||
27 | + return err | ||
28 | + } | ||
29 | + if err := transactionContext.StartTransaction(); err != nil { | ||
30 | + return err | ||
31 | + } | ||
32 | + defer func() { | ||
33 | + if err != nil { | ||
34 | + log.Logger.Error("【自动初始化车间生产记录】 失败:" + err.Error()) | ||
35 | + } | ||
36 | + transactionContext.RollbackTransaction() | ||
37 | + }() | ||
38 | + log.Logger.Debug("【自动初始化车间生产记录】 启动") | ||
39 | + _, workshop, err := factory.FastPgWorkshop(transactionContext, constant.MANUFACTURE_DEFAULT_WORKSHOPID) | ||
40 | + if err != nil { | ||
41 | + return err | ||
42 | + } | ||
43 | + productPlanDispatchRecordDao, _ := dao.NewProductPlanDispatchRecord(transactionContext.(*pg.TransactionContext)) | ||
44 | + productPlans, err := productPlanDispatchRecordDao.ProductPlans(constant.MANUFACTURE_DEFAULT_COMPANYID, | ||
45 | + constant.MANUFACTURE_DEFAULT_ORGID, | ||
46 | + constant.MANUFACTURE_DEFAULT_WORKSHOPID, | ||
47 | + utils.GetZeroTimeWithLocal(time.Now(), time.UTC), "") | ||
48 | + if err != nil { | ||
49 | + return err | ||
50 | + } | ||
51 | + if len(productPlans) == 0 { | ||
52 | + log.Logger.Debug("【自动初始化车间生产记录】 当天执行计划为空") | ||
53 | + return nil | ||
54 | + } | ||
55 | + workshopProductRecordDao, _ := dao.NewWorkshopProductRecordDao(transactionContext.(*pg.TransactionContext)) | ||
56 | + workshopProductRecordRepository, _ := repository.NewWorkshopProductRecordRepository(transactionContext.(*pg.TransactionContext)) | ||
57 | + lines := workshop.GetProductLines(domain.NotDeleted) | ||
58 | + for _, line := range lines { | ||
59 | + for _, section := range line.ProductSections { | ||
60 | + if !(section.SectionName == domain.ProductSection1 || section.SectionName == domain.ProductSection2) { | ||
61 | + continue | ||
62 | + } | ||
63 | + if section.Removed == domain.Deleted { | ||
64 | + continue | ||
65 | + } | ||
66 | + workstation := domain.NewWorkStation(workshop, line, section) | ||
67 | + cid := constant.MANUFACTURE_DEFAULT_COMPANYID | ||
68 | + oid := constant.MANUFACTURE_DEFAULT_ORGID | ||
69 | + for _, plan := range productPlans { | ||
70 | + var workshopProductRecord *domain.WorkshopProductRecord | ||
71 | + workshopProductRecord, err = workshopProductRecordDao.WorkshopProductRecord(cid, oid, workstation.WorkStationId, plan.ProductPlanId, time.Now()) | ||
72 | + if err == domain.ErrorNotFound { | ||
73 | + productRecord := &domain.ProductRecord{ | ||
74 | + CompanyId: constant.MANUFACTURE_DEFAULT_COMPANYID, | ||
75 | + OrgId: constant.MANUFACTURE_DEFAULT_ORGID, | ||
76 | + WorkStation: workstation, | ||
77 | + CreatedAt: time.Now(), | ||
78 | + ProductRecordInfo: &domain.ProductRecordInfo{ | ||
79 | + ProductPlanId: plan.ProductPlanId, | ||
80 | + PlanProductName: plan.PlanProductName, | ||
81 | + BatchNumber: plan.BatchNumber, | ||
82 | + }, | ||
83 | + } | ||
84 | + workshopProductRecord = domainService.NewWorkshopProductRecord(productRecord, plan) | ||
85 | + workshopProductRecord.UpdateProductWeigh(productRecord) | ||
86 | + if workshopProductRecord, err = workshopProductRecordRepository.Save(workshopProductRecord); err != nil { | ||
87 | + return err | ||
88 | + } | ||
89 | + log.Logger.Debug(fmt.Sprintf("【自动初始化车间生产记录】 工位:%v(%v) 初始产能:%v kg 日期:%v ID:%v", | ||
90 | + workshopProductRecord.WorkStation.WorkStationId, workshopProductRecord.WorkStation.SectionName, | ||
91 | + workshopProductRecord.ProductWeigh, workshopProductRecord.ProductRecordInfo.ProductDate, workshopProductRecord.WorkshopProductRecordId)) | ||
92 | + continue | ||
93 | + } | ||
94 | + if err != nil { | ||
95 | + log.Logger.Error(err.Error()) | ||
96 | + return nil | ||
97 | + } | ||
98 | + } | ||
99 | + } | ||
100 | + } | ||
101 | + if err = transactionContext.CommitTransaction(); err != nil { | ||
102 | + return err | ||
103 | + } | ||
104 | + return nil | ||
105 | +} |
@@ -24,7 +24,7 @@ type CreateProductCalendarCommand struct { | @@ -24,7 +24,7 @@ type CreateProductCalendarCommand struct { | ||
24 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 | 24 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 |
25 | WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"` | 25 | WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"` |
26 | // 日历选择 | 26 | // 日历选择 |
27 | - CalendarSelected []int `cname:"日历选择" json:"calendarSelected" valid:"Required"` | 27 | + CalendarSelected []int `cname:"日历选择" json:"calendarSelected" ` // valid:"Required" |
28 | // 上岗时间 | 28 | // 上岗时间 |
29 | InWorkAt string `cname:"上岗时间" json:"inWorkAt" valid:"Required"` | 29 | InWorkAt string `cname:"上岗时间" json:"inWorkAt" valid:"Required"` |
30 | // 下岗时间 | 30 | // 下岗时间 |
@@ -21,8 +21,8 @@ type UpdateProductCalendarCommand struct { | @@ -21,8 +21,8 @@ type UpdateProductCalendarCommand struct { | ||
21 | SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` | 21 | SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` |
22 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 | 22 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 |
23 | WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"` | 23 | WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"` |
24 | - // 日历选择 | ||
25 | - CalendarSelected []int `cname:"日历选择" json:"calendarSelected" valid:"Required"` | 24 | + // 日历选择 valid:"Required" |
25 | + CalendarSelected []int `cname:"日历选择" json:"calendarSelected" ` | ||
26 | // 上岗时间 | 26 | // 上岗时间 |
27 | InWorkAt string `cname:"上岗时间" json:"inWorkAt" valid:"Required"` | 27 | InWorkAt string `cname:"上岗时间" json:"inWorkAt" valid:"Required"` |
28 | // 下岗时间 | 28 | // 下岗时间 |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type GetProductGroupCalendarQuery struct { | ||
12 | + // 生产班组ID | ||
13 | + ProductGroupId int `cname:"工厂日历ID" json:"productGroupId" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (getProductCalendarQuery *GetProductGroupCalendarQuery) Valid(validation *validation.Validation) { | ||
17 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (getProductCalendarQuery *GetProductGroupCalendarQuery) ValidateQuery() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(getProductCalendarQuery) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + elem := reflect.TypeOf(getProductCalendarQuery).Elem() | ||
28 | + for _, validErr := range valid.Errors { | ||
29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
30 | + if isExist { | ||
31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
32 | + } else { | ||
33 | + return fmt.Errorf(validErr.Message) | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
@@ -372,6 +372,43 @@ func (productCalendarService *ProductCalendarService) SearchProductCalendar(oper | @@ -372,6 +372,43 @@ func (productCalendarService *ProductCalendarService) SearchProductCalendar(oper | ||
372 | return count, result, nil | 372 | return count, result, nil |
373 | } | 373 | } |
374 | 374 | ||
375 | +// 返回生产班组的工厂日历 | ||
376 | +func (productCalendarService *ProductCalendarService) GetProductGroupCalendar(getProductCalendarQuery *query.GetProductGroupCalendarQuery) (interface{}, error) { | ||
377 | + if err := getProductCalendarQuery.ValidateQuery(); err != nil { | ||
378 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
379 | + } | ||
380 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
381 | + if err != nil { | ||
382 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
383 | + } | ||
384 | + if err := transactionContext.StartTransaction(); err != nil { | ||
385 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
386 | + } | ||
387 | + defer func() { | ||
388 | + transactionContext.RollbackTransaction() | ||
389 | + }() | ||
390 | + productCalendarRepository, _, _ := factory.FastPgProductCalendar(transactionContext, 0) | ||
391 | + _, productGroup, err := factory.FastPgProductGroup(transactionContext, getProductCalendarQuery.ProductGroupId) | ||
392 | + if err != nil { | ||
393 | + return nil, nil | ||
394 | + } | ||
395 | + _, productCalendar, err := productCalendarRepository.Find(map[string]interface{}{"workStationId": productGroup.WorkStation.WorkStationId, "workOn": productGroup.WorkOn, "limit": 1}) | ||
396 | + if err != nil { | ||
397 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
398 | + } | ||
399 | + if len(productCalendar) == 0 { | ||
400 | + return nil, nil | ||
401 | + } | ||
402 | + | ||
403 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
404 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
405 | + } | ||
406 | + | ||
407 | + result := &dto.ProductCalendarDto{} | ||
408 | + result.LoadDto(productCalendar[0], 0) | ||
409 | + return result, nil | ||
410 | +} | ||
411 | + | ||
375 | func NewProductCalendarService(options map[string]interface{}) *ProductCalendarService { | 412 | func NewProductCalendarService(options map[string]interface{}) *ProductCalendarService { |
376 | newProductCalendarService := &ProductCalendarService{} | 413 | newProductCalendarService := &ProductCalendarService{} |
377 | return newProductCalendarService | 414 | return newProductCalendarService |
@@ -21,6 +21,8 @@ type ProductGroupEmployeesDto struct { | @@ -21,6 +21,8 @@ type ProductGroupEmployeesDto struct { | ||
21 | // 工作位置键值 (车间ID+'.'+生产线ID+'.'+工段ID) | 21 | // 工作位置键值 (车间ID+'.'+生产线ID+'.'+工段ID) |
22 | //WorkStationId string `json:"workStationId,omitempty"` | 22 | //WorkStationId string `json:"workStationId,omitempty"` |
23 | UserNamePinyin string `json:"pinyin"` | 23 | UserNamePinyin string `json:"pinyin"` |
24 | + // 在线的 | ||
25 | + Online bool `json:"online"` | ||
24 | } | 26 | } |
25 | 27 | ||
26 | func NewProductGroupEmployeesDto(group *domain.ProductGroup) []*ProductGroupEmployeesDto { | 28 | func NewProductGroupEmployeesDto(group *domain.ProductGroup) []*ProductGroupEmployeesDto { |
@@ -71,14 +73,19 @@ func (d *ProductGroupEmployeesDtos) LoadDto(groups ...*domain.ProductGroup) { | @@ -71,14 +73,19 @@ func (d *ProductGroupEmployeesDtos) LoadDto(groups ...*domain.ProductGroup) { | ||
71 | } | 73 | } |
72 | } | 74 | } |
73 | 75 | ||
74 | -func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRecord, mapGroupUser map[string]*domain.User, keyFunc func(int) string) { | 76 | +func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRecord, mapGroupUser map[string]*domain.User, keyFunc func(int) string, checkUserEnableFunc func(int) bool) { |
75 | var mapUser = make(map[int]int) | 77 | var mapUser = make(map[int]int) |
78 | + // 打卡的用户 | ||
76 | for _, v := range list { | 79 | for _, v := range list { |
77 | item := &ProductGroupEmployeesDto{} | 80 | item := &ProductGroupEmployeesDto{} |
78 | item.UserId = v.ProductWorker.UserId | 81 | item.UserId = v.ProductWorker.UserId |
79 | item.UserName = v.ProductWorker.UserName | 82 | item.UserName = v.ProductWorker.UserName |
80 | item.ProductGroupId = 0 | 83 | item.ProductGroupId = 0 |
81 | item.GroupName = "" | 84 | item.GroupName = "" |
85 | + item.Online = true | ||
86 | + if enable := checkUserEnableFunc(item.UserId); !enable { | ||
87 | + continue | ||
88 | + } | ||
82 | if v, ok := mapGroupUser[keyFunc(item.UserId)]; ok { | 89 | if v, ok := mapGroupUser[keyFunc(item.UserId)]; ok { |
83 | item.GroupName = v.GroupName | 90 | item.GroupName = v.GroupName |
84 | item.ProductGroupId = v.GroupId | 91 | item.ProductGroupId = v.GroupId |
@@ -89,9 +96,24 @@ func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRe | @@ -89,9 +96,24 @@ func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRe | ||
89 | } | 96 | } |
90 | if _, ok := mapUser[item.UserId]; ok { | 97 | if _, ok := mapUser[item.UserId]; ok { |
91 | continue | 98 | continue |
92 | - } else { | ||
93 | - mapUser[item.UserId] = item.UserId | ||
94 | } | 99 | } |
100 | + mapUser[item.UserId] = item.UserId | ||
101 | + d.Append(item) | ||
102 | + } | ||
103 | + // 未打卡的用户 | ||
104 | + for _, v := range mapGroupUser { | ||
105 | + if _, ok := mapUser[v.UserId]; ok { | ||
106 | + continue | ||
107 | + } | ||
108 | + item := &ProductGroupEmployeesDto{} | ||
109 | + item.UserId = v.UserId | ||
110 | + item.UserName = v.UserName | ||
111 | + item.ProductGroupId = v.GroupId | ||
112 | + item.GroupName = v.GroupName | ||
113 | + if enable := checkUserEnableFunc(item.UserId); !enable { | ||
114 | + continue | ||
115 | + } | ||
116 | + mapUser[item.UserId] = item.UserId | ||
95 | d.Append(item) | 117 | d.Append(item) |
96 | } | 118 | } |
97 | } | 119 | } |
@@ -30,6 +30,12 @@ type SearchProductGroupQuery struct { | @@ -30,6 +30,12 @@ type SearchProductGroupQuery struct { | ||
30 | WorkshopName string `cname:"车间名称" json:"workshopName,omitempty"` | 30 | WorkshopName string `cname:"车间名称" json:"workshopName,omitempty"` |
31 | // 生产线名称 | 31 | // 生产线名称 |
32 | LineName string `cname:"生产线名称" json:"lineName,omitempty"` | 32 | LineName string `cname:"生产线名称" json:"lineName,omitempty"` |
33 | + // 车间ID | ||
34 | + WorkshopId int `cname:"车间ID" json: workshopId,omitempty"` | ||
35 | + // 生产线ID | ||
36 | + LineId int `cname:"生产线ID" json:"lineId,omitempty"` | ||
37 | + // 工段ID | ||
38 | + SectionId int `json:"sectionId,omitempty"` | ||
33 | } | 39 | } |
34 | 40 | ||
35 | func (cmd *SearchProductGroupQuery) Valid(validation *validation.Validation) { | 41 | func (cmd *SearchProductGroupQuery) Valid(validation *validation.Validation) { |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" | 12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" |
13 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | 13 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" |
14 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | ||
14 | "sort" | 15 | "sort" |
15 | "strings" | 16 | "strings" |
16 | "time" | 17 | "time" |
@@ -491,7 +492,20 @@ func (productGroupService *ProductGroupService) SearchProductGroupEmployeesV2(op | @@ -491,7 +492,20 @@ func (productGroupService *ProductGroupService) SearchProductGroupEmployeesV2(op | ||
491 | productGroupRepository, _, _ := factory.FastPgProductGroup(transactionContext, 0) | 492 | productGroupRepository, _, _ := factory.FastPgProductGroup(transactionContext, 0) |
492 | mapUser, keyFunc := domainService.FindGroupMembers(productGroupRepository, cmd.CompanyId, cmd.OrgId, domain.WorkstationKey(cmd.WorkshopId, cmd.LineId, cmd.SectionId)) | 493 | mapUser, keyFunc := domainService.FindGroupMembers(productGroupRepository, cmd.CompanyId, cmd.OrgId, domain.WorkstationKey(cmd.WorkshopId, cmd.LineId, cmd.SectionId)) |
493 | var results = dto.NewProductGroupEmployeesDtos() | 494 | var results = dto.NewProductGroupEmployeesDtos() |
494 | - results.LoadDtoV2(productGroups, mapUser, keyFunc) | 495 | + |
496 | + userService := domainService.NewUserService() | ||
497 | + checkUserEnableFunc := func(userId int) bool { | ||
498 | + user, err := userService.User(userId) | ||
499 | + if err != nil { | ||
500 | + return false | ||
501 | + } | ||
502 | + if user.EnableStatus == int(domain.UserStatusEnable) { | ||
503 | + return true | ||
504 | + } | ||
505 | + log.Logger.Debug(fmt.Sprintf("ID:%d 用户:%s 状态:%d 已被禁用,过滤", user.UserId, user.UserName, user.EnableStatus)) | ||
506 | + return false | ||
507 | + } | ||
508 | + results.LoadDtoV2(productGroups, mapUser, keyFunc, checkUserEnableFunc) | ||
495 | sort.Stable(results) | 509 | sort.Stable(results) |
496 | if err := transactionContext.CommitTransaction(); err != nil { | 510 | if err := transactionContext.CommitTransaction(); err != nil { |
497 | return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 511 | return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
@@ -578,9 +592,7 @@ func (productGroupService *ProductGroupService) SelectorProductGroup(operateInfo | @@ -578,9 +592,7 @@ func (productGroupService *ProductGroupService) SelectorProductGroup(operateInfo | ||
578 | if err := transactionContext.CommitTransaction(); err != nil { | 592 | if err := transactionContext.CommitTransaction(); err != nil { |
579 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 593 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
580 | } | 594 | } |
581 | - return map[string]interface{}{ | ||
582 | - "groups": results, | ||
583 | - }, nil | 595 | + return results, nil |
584 | } | 596 | } |
585 | 597 | ||
586 | func NewProductGroupService(options map[string]interface{}) *ProductGroupService { | 598 | func NewProductGroupService(options map[string]interface{}) *ProductGroupService { |
@@ -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 | } |
@@ -130,8 +130,8 @@ func (productMaterialGroupService *ProductMaterialGroupService) ListProductMater | @@ -130,8 +130,8 @@ func (productMaterialGroupService *ProductMaterialGroupService) ListProductMater | ||
130 | } | 130 | } |
131 | 131 | ||
132 | // 移除物料分组服务 | 132 | // 移除物料分组服务 |
133 | -func (productMaterialGroupService *ProductMaterialGroupService) RemoveProductMaterialGroup(removeProductMaterialGroupCommand *command.RemoveProductMaterialGroupCommand) (interface{}, error) { | ||
134 | - if err := removeProductMaterialGroupCommand.ValidateCommand(); err != nil { | 133 | +func (productMaterialGroupService *ProductMaterialGroupService) RemoveProductMaterialGroup(operateInfo *domain.OperateInfo, cmd *command.RemoveProductMaterialGroupCommand) (interface{}, error) { |
134 | + if err := cmd.ValidateCommand(); err != nil { | ||
135 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 135 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
136 | } | 136 | } |
137 | transactionContext, err := factory.CreateTransactionContext(nil) | 137 | transactionContext, err := factory.CreateTransactionContext(nil) |
@@ -144,29 +144,37 @@ func (productMaterialGroupService *ProductMaterialGroupService) RemoveProductMat | @@ -144,29 +144,37 @@ func (productMaterialGroupService *ProductMaterialGroupService) RemoveProductMat | ||
144 | defer func() { | 144 | defer func() { |
145 | transactionContext.RollbackTransaction() | 145 | transactionContext.RollbackTransaction() |
146 | }() | 146 | }() |
147 | - var productMaterialGroupRepository domain.ProductMaterialGroupRepository | ||
148 | - if value, err := factory.CreateProductMaterialGroupRepository(map[string]interface{}{ | ||
149 | - "transactionContext": transactionContext, | ||
150 | - }); err != nil { | 147 | + |
148 | + materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) | ||
149 | + _, ids, err := materialService.AllMaterialGroupChild(operateInfo, cmd.ProductMaterialGroupId) | ||
150 | + if err != nil { | ||
151 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 151 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
152 | - } else { | ||
153 | - productMaterialGroupRepository = value | ||
154 | } | 152 | } |
155 | - productMaterialGroup, err := productMaterialGroupRepository.FindOne(map[string]interface{}{"productMaterialGroupId": removeProductMaterialGroupCommand.ProductMaterialGroupId}) | 153 | + if len(ids) == 0 { |
154 | + return nil, nil | ||
155 | + } | ||
156 | + productMaterialRepository, _, _ := factory.FastProductMaterial(transactionContext, 0) | ||
157 | + count, _, err := productMaterialRepository.Find(map[string]interface{}{"productMaterialGroupIds": ids, "limit": 1}) | ||
156 | if err != nil { | 158 | if err != nil { |
157 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 159 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
158 | } | 160 | } |
159 | - if productMaterialGroup == nil { | ||
160 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("已删除 %s", string(removeProductMaterialGroupCommand.ProductMaterialGroupId))) | 161 | + if count >= 1 { |
162 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "请处理当前分组下存在的物料信息") | ||
161 | } | 163 | } |
162 | - if productMaterialGroup, err := productMaterialGroupRepository.Remove(productMaterialGroup); err != nil { | ||
163 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
164 | - } else { | ||
165 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
166 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 164 | + |
165 | + for _, id := range ids { | ||
166 | + productMaterialGroupRepository, productMaterialGroup, err := factory.FastProductMaterialGroup(transactionContext, id) | ||
167 | + if err != nil { | ||
168 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
169 | + } | ||
170 | + if _, err = productMaterialGroupRepository.Remove(productMaterialGroup); err != nil { | ||
171 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
167 | } | 172 | } |
168 | - return productMaterialGroup, nil | ||
169 | } | 173 | } |
174 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
175 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
176 | + } | ||
177 | + return nil, nil | ||
170 | } | 178 | } |
171 | 179 | ||
172 | // 更新物料分组服务 | 180 | // 更新物料分组服务 |
@@ -5,11 +5,13 @@ import ( | @@ -5,11 +5,13 @@ import ( | ||
5 | "github.com/linmadan/egglib-go/core/application" | 5 | "github.com/linmadan/egglib-go/core/application" |
6 | "github.com/linmadan/egglib-go/transaction/pg" | 6 | "github.com/linmadan/egglib-go/transaction/pg" |
7 | "github.com/linmadan/egglib-go/utils/tool_funs" | 7 | "github.com/linmadan/egglib-go/utils/tool_funs" |
8 | + "github.com/linmadan/egglib-go/utils/xtime" | ||
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" |
9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/command" | 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/command" |
10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/dto" | 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/dto" |
11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/query" | 12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/query" |
12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 13 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
14 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao" | ||
13 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" | 15 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" |
14 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" | 16 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" |
15 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | 17 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" |
@@ -514,6 +516,26 @@ func (productPlanService *ProductPlanService) ReturnMaterial(returnMaterialComma | @@ -514,6 +516,26 @@ func (productPlanService *ProductPlanService) ReturnMaterial(returnMaterialComma | ||
514 | 516 | ||
515 | productRecordService, _ := domainService.NewPGProductRecordService(transactionContext.(*pg.TransactionContext)) | 517 | productRecordService, _ := domainService.NewPGProductRecordService(transactionContext.(*pg.TransactionContext)) |
516 | 518 | ||
519 | + productRecordDao, _ := dao.NewProductRecordDao(transactionContext.(*pg.TransactionContext)) | ||
520 | + begin := xtime.BeginningOfDay() | ||
521 | + end := time.Now() | ||
522 | + workstationId := domain.WorkstationKey(returnMaterialCommand.WorkshopId, returnMaterialCommand.LineId, returnMaterialCommand.SectionId) | ||
523 | + totalReceive, err := productRecordDao.ProductWeightStatics(returnMaterialCommand.CompanyId, returnMaterialCommand.OrgId, domain.RecordTypeReceiveMaterial, returnMaterialCommand.ProductPlanId, workstationId, begin, end) | ||
524 | + if err != nil { | ||
525 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
526 | + } | ||
527 | + totalReturn, err := productRecordDao.ProductWeightStatics(returnMaterialCommand.CompanyId, returnMaterialCommand.OrgId, domain.RecordTypeReturnMaterial, returnMaterialCommand.ProductPlanId, workstationId, begin, end) | ||
528 | + if err != nil { | ||
529 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
530 | + } | ||
531 | + allowReturn := totalReceive - totalReturn | ||
532 | + if totalReturn+returnMaterialCommand.Weigh > totalReceive { | ||
533 | + if allowReturn > 0 { | ||
534 | + return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("当天累计退料大于累计领料,当前只允许退料 %v kg", totalReceive-totalReturn)) | ||
535 | + } | ||
536 | + return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("当天累计退料大于累计领料")) | ||
537 | + } | ||
538 | + | ||
517 | _, err = productRecordService.SubmitProductRecord(domain.RecordTypeReturnMaterial, tool_funs.SimpleStructToMap(returnMaterialCommand)) | 539 | _, err = productRecordService.SubmitProductRecord(domain.RecordTypeReturnMaterial, tool_funs.SimpleStructToMap(returnMaterialCommand)) |
518 | if err != nil { | 540 | if err != nil { |
519 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 541 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
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 CancelProductRecordCommand struct { | ||
12 | + // 生产记录ID | ||
13 | + ProductRecordId int `cname:"生产记录ID" json:"productRecordId" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (cancelProductRecordCommand *CancelProductRecordCommand) Valid(validation *validation.Validation) { | ||
17 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (cancelProductRecordCommand *CancelProductRecordCommand) ValidateCommand() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(cancelProductRecordCommand) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + elem := reflect.TypeOf(cancelProductRecordCommand).Elem() | ||
28 | + for _, validErr := range valid.Errors { | ||
29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
30 | + if isExist { | ||
31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
32 | + } else { | ||
33 | + return fmt.Errorf(validErr.Message) | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
1 | +package dto | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/utils/xtime" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
7 | +) | ||
8 | + | ||
9 | +// HistoryProductRecord 历史生成记录 | ||
10 | +type HistoryProductRecord struct { | ||
11 | + // 生产记录ID | ||
12 | + ProductRecordId int `json:"productRecordId,omitempty"` | ||
13 | + // 批号 | ||
14 | + BatchNumber string `json:"batchNumber,omitempty"` | ||
15 | + // 计划的产品名称 | ||
16 | + PlanProductName string `json:"planProductName,omitempty"` | ||
17 | + // 创建时间 | ||
18 | + CreatedAt string `json:"createdAt,omitempty"` | ||
19 | + // 生产记录类型:1:领料 2:退料 4:称重 8:二级品称重 | ||
20 | + ProductRecordType int `json:"productRecordType"` | ||
21 | + // 生产工人 | ||
22 | + ProductWorker *domain.User `json:"productWorker,omitempty"` | ||
23 | + // 产能 - 审核前 | ||
24 | + Weight float64 `json:"weight"` | ||
25 | + // 状态 1:未审核 2:已审核 3:已撤回 4:已记录 | ||
26 | + Status int `json:"status"` | ||
27 | +} | ||
28 | + | ||
29 | +func (d *HistoryProductRecord) LoadDto(m *domain.ProductRecord) *HistoryProductRecord { | ||
30 | + d.ProductRecordId = m.ProductRecordId | ||
31 | + d.ProductWorker = m.ProductWorker | ||
32 | + d.Weight = utils.Round(m.ProductRecordInfo.Original, 1) | ||
33 | + d.Status = m.ProductRecordInfo.ApproveStatus | ||
34 | + d.PlanProductName = m.ProductRecordInfo.PlanProductName | ||
35 | + d.BatchNumber = m.ProductRecordInfo.BatchNumber | ||
36 | + d.CreatedAt = m.CreatedAt.Local().Format("2006-01-02 15:04:05") | ||
37 | + d.ProductRecordType = m.ProductRecordType | ||
38 | + if m.ProductRecordType != domain.RecordTypeSecondLevelWeigh && | ||
39 | + m.ProductRecordInfo.ApproveStatus == domain.ProductRecordNotApprove && | ||
40 | + !(xtime.BeginningOfDay().Equal(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 | ||
43 | + } | ||
44 | + if m.ProductRecordType == domain.RecordTypeSecondLevelWeigh && m.ProductRecordInfo.ApproveStatus == domain.ProductRecordAutoApproved { | ||
45 | + d.Status = domain.ProductRecordApproved | ||
46 | + } | ||
47 | + return d | ||
48 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/linmadan/egglib-go/utils/xtime" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | ||
8 | + "reflect" | ||
9 | + "strings" | ||
10 | + "time" | ||
11 | + | ||
12 | + "github.com/beego/beego/v2/core/validation" | ||
13 | +) | ||
14 | + | ||
15 | +type HistoryProductRecordQuery struct { | ||
16 | + // 查询偏离量 | ||
17 | + Offset int `cname:"查询偏离量" json:"offset"` | ||
18 | + // 查询限制 | ||
19 | + Limit int `cname:"查询限制" json:"limit"` | ||
20 | + // 当前公司 | ||
21 | + CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"` | ||
22 | + // 当前登录的组织 | ||
23 | + OrgId int `cname:"当前登录的组织" json:"orgId,omitempty"` | ||
24 | + // 匹配多个组织 | ||
25 | + InOrgIds []int `cname:"匹配多个组织" json:"inOrgIds,omitempty"` | ||
26 | + // 页码 | ||
27 | + PageNumber int `cname:"页码" json:"pageNumber,omitempty"` | ||
28 | + // 页数 | ||
29 | + PageSize int `cname:"页数" json:"pageSize,omitempty"` | ||
30 | + // 车间ID | ||
31 | + WorkshopId int `cname:"车间ID" json:"workshopId,omitempty"` | ||
32 | + // 生产线ID | ||
33 | + LineId int `cname:"生产线ID" json:"lineId,omitempty"` | ||
34 | + // 工段ID | ||
35 | + SectionId int `json:"sectionId,omitempty"` | ||
36 | + // 生产记录类型:1:领料 2:退料 4:称重 8:二级品称重 | ||
37 | + ProductRecordType int `cname:"生产记录类型:1:领料 2:退料 4:称重 8:二级品称重" json:"productRecordType"` | ||
38 | + // 生产线名称 | ||
39 | + //LineName string `cname:"生产线名称" json:"lineName,omitempty"` | ||
40 | + // 工段名称 | ||
41 | + //SectionName string `cname:"工段名称" json:"sectionName,omitempty"` | ||
42 | + // 员工类型 1:固定 2:派遣 3.临时 | ||
43 | + //EmployeeType int `cname:"员工类型 1:固定 2:派遣 3.临时" json:"employeeType"` | ||
44 | + // 开始时间 | ||
45 | + //BeginTime string `cname:"开始时间" json:"beginTime"` | ||
46 | + // 结束时间 | ||
47 | + //EndTime string `cname:"结束时间" json:"endTime"` | ||
48 | + | ||
49 | + // 上一次记录ID | ||
50 | + LastProductRecordId int `cname:"上一次记录ID" json:"lastProductRecordId"` | ||
51 | + // 日期 | ||
52 | + Date string `cname:"日期" json:"date"` | ||
53 | + // 生产员工ID | ||
54 | + ProductWorkerId int `cname:"生产员工ID" json:"productWorkerId"` | ||
55 | + // 状态 0:全部 1:未审核 2:已审核 3:已撤回 4:已记录 | ||
56 | + Status int `cname:"状态" json:"status"` | ||
57 | + // 状态 0:全部 1:未审核 2:已审核 3:已撤回 4:已记录 | ||
58 | + InStatus []int `cname:"匹配多个状态" json:"intStatus"` | ||
59 | + | ||
60 | + // 开始时间 | ||
61 | + ProductBeginTime time.Time `cname:"开始时间" json:"productBeginTime"` | ||
62 | + // 结束时间 | ||
63 | + ProductEndTime time.Time `cname:"结束时间" json:"productEndTime"` | ||
64 | +} | ||
65 | + | ||
66 | +func (cmd *HistoryProductRecordQuery) Valid(validation *validation.Validation) { | ||
67 | + cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize) | ||
68 | + | ||
69 | + //var err error | ||
70 | + //if len(cmd.BeginTime) > 0 { | ||
71 | + // if cmd.ProductBeginTime, err = time.Parse("2006-01-02 15:04:05", cmd.BeginTime); err != nil { | ||
72 | + // log.Logger.Error(err.Error()) | ||
73 | + // validation.Error("开始时间有误") | ||
74 | + // return | ||
75 | + // } | ||
76 | + //} | ||
77 | + //if len(cmd.EndTime) > 0 { | ||
78 | + // if cmd.ProductEndTime, err = time.Parse("2006-01-02 15:04:05", cmd.EndTime); err != nil { | ||
79 | + // log.Logger.Error(err.Error()) | ||
80 | + // validation.Error("结束时间有误") | ||
81 | + // return | ||
82 | + // } | ||
83 | + // if cmd.ProductEndTime.Equal(cmd.ProductBeginTime) { | ||
84 | + // cmd.ProductEndTime = cmd.ProductEndTime.Add(time.Hour * 24) | ||
85 | + // } | ||
86 | + //} | ||
87 | + if len(cmd.Date) > 0 { | ||
88 | + t, err := xtime.Parse(cmd.Date) | ||
89 | + if err != nil { | ||
90 | + log.Logger.Error(err.Error()) | ||
91 | + validation.Error("日期有误") | ||
92 | + return | ||
93 | + } | ||
94 | + cmd.ProductBeginTime = t | ||
95 | + cmd.ProductEndTime = t.AddDate(0, 0, 1) | ||
96 | + } | ||
97 | + if cmd.ProductRecordType == domain.RecordTypeReceiveMaterial || cmd.ProductRecordType == domain.RecordTypeReturnMaterial { | ||
98 | + if cmd.Status == domain.ProductRecordNotApprove { | ||
99 | + cmd.Status = domain.ProductRecordNotApprove | ||
100 | + if xtime.IsZero(cmd.ProductBeginTime) || xtime.BeforeEqual(cmd.ProductBeginTime, xtime.BeginningOfDay()) { | ||
101 | + cmd.ProductBeginTime = xtime.BeginningOfDay() | ||
102 | + } | ||
103 | + } else if cmd.Status == domain.ProductRecordLogged { | ||
104 | + cmd.Status = domain.ProductRecordNotApprove | ||
105 | + if len(cmd.Date) == 0 && xtime.IsZero(cmd.ProductEndTime) { | ||
106 | + cmd.ProductEndTime = xtime.BeginningOfDay() | ||
107 | + } | ||
108 | + if len(cmd.Date) > 0 && !xtime.BeforeEqual(cmd.ProductEndTime, xtime.BeginningOfDay()) { | ||
109 | + cmd.Status = domain.ProductRecordLogged | ||
110 | + } | ||
111 | + } | ||
112 | + } | ||
113 | + if cmd.ProductRecordType == domain.RecordTypeSecondLevelWeigh && cmd.Status == domain.ProductRecordApproved { | ||
114 | + cmd.Status = 0 | ||
115 | + cmd.InStatus = []int{domain.ProductRecordApproved, domain.ProductRecordAutoApproved} | ||
116 | + } | ||
117 | +} | ||
118 | + | ||
119 | +func (cmd *HistoryProductRecordQuery) ValidateQuery() error { | ||
120 | + valid := validation.Validation{} | ||
121 | + b, err := valid.Valid(cmd) | ||
122 | + if err != nil { | ||
123 | + return err | ||
124 | + } | ||
125 | + if !b { | ||
126 | + elem := reflect.TypeOf(cmd).Elem() | ||
127 | + for _, validErr := range valid.Errors { | ||
128 | + field, isExist := elem.FieldByName(validErr.Field) | ||
129 | + if isExist { | ||
130 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
131 | + } else { | ||
132 | + return fmt.Errorf(validErr.Message) | ||
133 | + } | ||
134 | + } | ||
135 | + } | ||
136 | + return nil | ||
137 | +} |
@@ -274,6 +274,41 @@ func (productRecordService *ProductRecordService) SearchProductRecord(operateInf | @@ -274,6 +274,41 @@ func (productRecordService *ProductRecordService) SearchProductRecord(operateInf | ||
274 | return count, result, nil | 274 | return count, result, nil |
275 | } | 275 | } |
276 | 276 | ||
277 | +// 返回生产记录服务列表 | ||
278 | +func (productRecordService *ProductRecordService) HistoryProductRecord(operateInfo *domain.OperateInfo, query *query.HistoryProductRecordQuery) (int64, interface{}, error) { | ||
279 | + if err := query.ValidateQuery(); err != nil { | ||
280 | + return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
281 | + } | ||
282 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
283 | + if err != nil { | ||
284 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
285 | + } | ||
286 | + if err := transactionContext.StartTransaction(); err != nil { | ||
287 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
288 | + } | ||
289 | + defer func() { | ||
290 | + transactionContext.RollbackTransaction() | ||
291 | + }() | ||
292 | + var productRecordRepository domain.ProductRecordRepository | ||
293 | + productRecordRepository, _, _ = factory.FastPgProductRecord(transactionContext, 0) | ||
294 | + | ||
295 | + count, productRecords, err := productRecordRepository.Find(utils.ObjectToMap(query)) | ||
296 | + if err != nil { | ||
297 | + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
298 | + } | ||
299 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
300 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
301 | + } | ||
302 | + var result = make([]*dto.HistoryProductRecord, 0) | ||
303 | + for i := range productRecords { | ||
304 | + item := productRecords[i] | ||
305 | + newItem := &dto.HistoryProductRecord{} | ||
306 | + newItem.LoadDto(item) | ||
307 | + result = append(result, newItem) | ||
308 | + } | ||
309 | + return count, result, nil | ||
310 | +} | ||
311 | + | ||
277 | // 生产记录统计 | 312 | // 生产记录统计 |
278 | func (productRecordService *ProductRecordService) ProductRecordStatics(cmd *command.ProductRecordStaticsCommand) (interface{}, error) { | 313 | func (productRecordService *ProductRecordService) ProductRecordStatics(cmd *command.ProductRecordStaticsCommand) (interface{}, error) { |
279 | if err := cmd.ValidateCommand(); err != nil { | 314 | if err := cmd.ValidateCommand(); err != nil { |
@@ -308,6 +343,33 @@ func (productRecordService *ProductRecordService) ProductRecordStatics(cmd *comm | @@ -308,6 +343,33 @@ func (productRecordService *ProductRecordService) ProductRecordStatics(cmd *comm | ||
308 | return nil, nil | 343 | return nil, nil |
309 | } | 344 | } |
310 | 345 | ||
346 | +// 生产记录审核 | ||
347 | +func (productRecordService *ProductRecordService) CancelProductRecord(cmd *command.CancelProductRecordCommand) (interface{}, error) { | ||
348 | + if err := cmd.ValidateCommand(); err != nil { | ||
349 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
350 | + } | ||
351 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
352 | + if err != nil { | ||
353 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
354 | + } | ||
355 | + if err := transactionContext.StartTransaction(); err != nil { | ||
356 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
357 | + } | ||
358 | + defer func() { | ||
359 | + transactionContext.RollbackTransaction() | ||
360 | + }() | ||
361 | + | ||
362 | + svr, err := domainService.NewPGProductRecordService(transactionContext.(*pgTransaction.TransactionContext)) | ||
363 | + if _, err = svr.Cancel(cmd.ProductRecordId); err != nil { | ||
364 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
365 | + } | ||
366 | + | ||
367 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
368 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
369 | + } | ||
370 | + return struct{}{}, nil | ||
371 | +} | ||
372 | + | ||
311 | func NewProductRecordService(options map[string]interface{}) *ProductRecordService { | 373 | func NewProductRecordService(options map[string]interface{}) *ProductRecordService { |
312 | newProductRecordService := &ProductRecordService{} | 374 | newProductRecordService := &ProductRecordService{} |
313 | return newProductRecordService | 375 | return newProductRecordService |
@@ -18,6 +18,8 @@ type SearchMaterialsQuery struct { | @@ -18,6 +18,8 @@ type SearchMaterialsQuery struct { | ||
18 | LineId int `cname:"生产线ID" json:"lineId,omitempty"` | 18 | LineId int `cname:"生产线ID" json:"lineId,omitempty"` |
19 | // 工段ID | 19 | // 工段ID |
20 | SectionId int `json:"sectionId,omitempty"` | 20 | SectionId int `json:"sectionId,omitempty"` |
21 | + // 智能称重标识 0:全部 1:是 2:否 | ||
22 | + IntelligentWeighingFlag int `cname:"智能称重标识" json:"intelligentWeighingFlag"` | ||
21 | } | 23 | } |
22 | 24 | ||
23 | func (listProductGroupQuery *SearchMaterialsQuery) Valid(validation *validation.Validation) { | 25 | func (listProductGroupQuery *SearchMaterialsQuery) Valid(validation *validation.Validation) { |
@@ -2,16 +2,19 @@ package constant | @@ -2,16 +2,19 @@ package constant | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | - "os" | ||
6 | - "strconv" | 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" |
7 | ) | 6 | ) |
8 | 7 | ||
8 | +//var Configurator utils.Configurator = utils.NewConfig("ini","config/app_test.conf") | ||
9 | +var Configurator utils.Configurator = utils.EnvConfigurator{} | ||
10 | + | ||
9 | var SERVICE_NAME = "allied-creation-manufacture" | 11 | var SERVICE_NAME = "allied-creation-manufacture" |
10 | var SERVICE_ENV = "dev" | 12 | var SERVICE_ENV = "dev" |
11 | var HTTP_PORT int = 8081 | 13 | var HTTP_PORT int = 8081 |
12 | var CACHE_PREFIX = "allied-creation-manufacture-dev" | 14 | var CACHE_PREFIX = "allied-creation-manufacture-dev" |
13 | var LOG_LEVEL = "debug" | 15 | var LOG_LEVEL = "debug" |
14 | var LOG_FILE = "app.log" | 16 | var LOG_FILE = "app.log" |
17 | +var PPROF_ON = true | ||
15 | 18 | ||
16 | //天联共创基础模块 | 19 | //天联共创基础模块 |
17 | var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080" //"http://allied-creation-basic-dev.fjmaimaimai.com" | 20 | var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080" //"http://allied-creation-basic-dev.fjmaimaimai.com" |
@@ -35,46 +38,14 @@ const HeaderOrgId = "orgId" | @@ -35,46 +38,14 @@ const HeaderOrgId = "orgId" | ||
35 | const HeaderOrgIds = "orgIds" | 38 | const HeaderOrgIds = "orgIds" |
36 | 39 | ||
37 | func init() { | 40 | func init() { |
38 | - if os.Getenv("LOG_LEVEL") != "" { | ||
39 | - LOG_LEVEL = os.Getenv("LOG_LEVEL") | ||
40 | - } | ||
41 | - //if os.Getenv("CUSTOMER_ACCOUNT") != "" { | ||
42 | - // account := os.Getenv("CUSTOMER_ACCOUNT") | ||
43 | - // accounts := strings.Split(account, CUSTOMER_ACCOUNT_DELIMITER) | ||
44 | - // var tmpAccounts []int64 | ||
45 | - // for i := range accounts { | ||
46 | - // v, err := strconv.ParseInt(accounts[i], 10, 64) | ||
47 | - // if err != nil { | ||
48 | - // panic(err) | ||
49 | - // } | ||
50 | - // tmpAccounts = append(tmpAccounts, v) | ||
51 | - // } | ||
52 | - // if len(tmpAccounts) > 0 { | ||
53 | - // CUSTOMER_ACCOUNT = tmpAccounts | ||
54 | - // } | ||
55 | - //} | ||
56 | - | ||
57 | - if os.Getenv("ALLIED_CREATION_BASIC_HOST") != "" { | ||
58 | - ALLIED_CREATION_BASIC_HOST = os.Getenv("ALLIED_CREATION_BASIC_HOST") | ||
59 | - } | ||
60 | - if os.Getenv("ALLIED_CREATION_USER_HOST") != "" { | ||
61 | - ALLIED_CREATION_USER_HOST = os.Getenv("ALLIED_CREATION_USER_HOST") | ||
62 | - } | ||
63 | - if os.Getenv("ALLIED_CREATION_COOPERATION_HOST") != "" { | ||
64 | - ALLIED_CREATION_COOPERATION_HOST = os.Getenv("ALLIED_CREATION_COOPERATION_HOST") | ||
65 | - } | ||
66 | - //if os.Getenv("SMS_SERVE_HOST") != "" { | ||
67 | - // SMS_SERVE_HOST = os.Getenv("SMS_SERVE_HOST") | ||
68 | - //} | ||
69 | - if os.Getenv("MMM_BYTE_BANK_HOST") != "" { | ||
70 | - MMM_BYTE_BANK_HOST = os.Getenv("MMM_BYTE_BANK_HOST") | ||
71 | - } | ||
72 | - if os.Getenv("SERVICE_ENV") != "" { | ||
73 | - SERVICE_ENV = os.Getenv("SERVICE_ENV") | ||
74 | - } | ||
75 | - if os.Getenv("HTTP_PORT") != "" { | ||
76 | - HTTP_PORT, _ = strconv.Atoi(os.Getenv("HTTP_PORT")) | ||
77 | - } | 41 | + LOG_LEVEL = Configurator.DefaultString("LOG_LEVEL", LOG_LEVEL) |
42 | + ALLIED_CREATION_BASIC_HOST = Configurator.DefaultString("ALLIED_CREATION_BASIC_HOST", ALLIED_CREATION_BASIC_HOST) | ||
43 | + ALLIED_CREATION_USER_HOST = Configurator.DefaultString("ALLIED_CREATION_USER_HOST", ALLIED_CREATION_USER_HOST) | ||
44 | + ALLIED_CREATION_COOPERATION_HOST = Configurator.DefaultString("ALLIED_CREATION_COOPERATION_HOST", ALLIED_CREATION_COOPERATION_HOST) | ||
45 | + MMM_BYTE_BANK_HOST = Configurator.DefaultString("MMM_BYTE_BANK_HOST", MMM_BYTE_BANK_HOST) | ||
46 | + SERVICE_ENV = Configurator.DefaultString("SERVICE_ENV", SERVICE_ENV) | ||
47 | + HTTP_PORT = Configurator.DefaultInt("HTTP_PORT", HTTP_PORT) | ||
78 | SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV) | 48 | SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV) |
49 | + PPROF_ON = Configurator.DefaultBool("PPROF_ON", PPROF_ON) | ||
79 | CACHE_PREFIX = SERVICE_NAME | 50 | CACHE_PREFIX = SERVICE_NAME |
80 | } | 51 | } |
1 | package constant | 1 | package constant |
2 | 2 | ||
3 | -import "os" | ||
4 | - | ||
5 | var ( | 3 | var ( |
6 | // kafka 地址 | 4 | // kafka 地址 |
7 | KAFKA_HOST = "192.168.0.250:9092,192.168.0.251:9092,192.168.0.252:9092" //"106.75.231.90:9092" | 5 | KAFKA_HOST = "192.168.0.250:9092,192.168.0.251:9092,192.168.0.252:9092" //"106.75.231.90:9092" |
@@ -14,13 +12,6 @@ var ( | @@ -14,13 +12,6 @@ var ( | ||
14 | ) | 12 | ) |
15 | 13 | ||
16 | func init() { | 14 | func init() { |
17 | - if os.Getenv("KAFKA_HOST") != "" { | ||
18 | - KAFKA_HOST = os.Getenv("KAFKA_HOST") | ||
19 | - } | ||
20 | - //if os.Getenv("TOPIC_LOG_STASH") != "" { | ||
21 | - // POSTGRESQL_PORT = os.Getenv("TOPIC_LOG_STASH") | ||
22 | - //} | ||
23 | - if os.Getenv("ENABLE_KAFKA_LOG") != "" { | ||
24 | - ENABLE_KAFKA_LOG = true | ||
25 | - } | 15 | + KAFKA_HOST = Configurator.DefaultString("KAFKA_HOST", KAFKA_HOST) |
16 | + ENABLE_KAFKA_LOG = Configurator.DefaultBool("ENABLE_KAFKA_LOG", ENABLE_KAFKA_LOG) | ||
26 | } | 17 | } |
1 | package constant | 1 | package constant |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "os" | ||
5 | - "strconv" | ||
6 | "strings" | 4 | "strings" |
7 | ) | 5 | ) |
8 | 6 | ||
@@ -20,18 +18,10 @@ var ( | @@ -20,18 +18,10 @@ var ( | ||
20 | ) | 18 | ) |
21 | 19 | ||
22 | func init() { | 20 | func init() { |
23 | - if os.Getenv("MANUFACTURE_DEFAULT_COMPANYID") != "" { | ||
24 | - MANUFACTURE_DEFAULT_COMPANYID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_DEFAULT_COMPANYID")) | ||
25 | - } | ||
26 | - if os.Getenv("MANUFACTURE_DEFAULT_ORGID") != "" { | ||
27 | - MANUFACTURE_DEFAULT_ORGID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_DEFAULT_ORGID")) | ||
28 | - } | ||
29 | - if os.Getenv("MANUFACTURE_DEFAULT_WORKSHOPID") != "" { | ||
30 | - MANUFACTURE_DEFAULT_WORKSHOPID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_DEFAULT_WORKSHOPID")) | ||
31 | - } | ||
32 | - if os.Getenv("MANUFACTURE_PRODUCT_TYPE") != "" { | ||
33 | - MANUFACTURE_PRODUCT_TYPE = os.Getenv("MANUFACTURE_PRODUCT_TYPE") | ||
34 | - } | 21 | + MANUFACTURE_DEFAULT_COMPANYID = Configurator.DefaultInt("MANUFACTURE_DEFAULT_COMPANYID", MANUFACTURE_DEFAULT_COMPANYID) |
22 | + MANUFACTURE_DEFAULT_ORGID = Configurator.DefaultInt("MANUFACTURE_DEFAULT_ORGID", MANUFACTURE_DEFAULT_ORGID) | ||
23 | + MANUFACTURE_DEFAULT_WORKSHOPID = Configurator.DefaultInt("MANUFACTURE_DEFAULT_WORKSHOPID", MANUFACTURE_DEFAULT_WORKSHOPID) | ||
24 | + MANUFACTURE_PRODUCT_TYPE = Configurator.DefaultString("MANUFACTURE_PRODUCT_TYPE", MANUFACTURE_PRODUCT_TYPE) | ||
35 | productTypes := strings.Split(MANUFACTURE_PRODUCT_TYPE, ",") | 25 | productTypes := strings.Split(MANUFACTURE_PRODUCT_TYPE, ",") |
36 | for i, v := range productTypes { | 26 | for i, v := range productTypes { |
37 | MapProductType[i+1] = v | 27 | MapProductType[i+1] = v |
1 | package constant | 1 | package constant |
2 | 2 | ||
3 | -import "os" | ||
4 | - | ||
5 | var MQTT_TOPIC = "/MQTT" | 3 | var MQTT_TOPIC = "/MQTT" |
6 | 4 | ||
7 | //设备商提供的测试地址 | 5 | //设备商提供的测试地址 |
@@ -30,18 +28,12 @@ var MQTT_HOST = "47.97.5.102" | @@ -30,18 +28,12 @@ var MQTT_HOST = "47.97.5.102" | ||
30 | var MQTT_PORT = "6000" | 28 | var MQTT_PORT = "6000" |
31 | var MQTT_USER = "admin" | 29 | var MQTT_USER = "admin" |
32 | var MQTT_PASSWORD = "123456" | 30 | var MQTT_PASSWORD = "123456" |
31 | +var MQTT_UP = true | ||
33 | 32 | ||
34 | func init() { | 33 | func init() { |
35 | - if os.Getenv("MQTT_HOST") != "" { | ||
36 | - MQTT_HOST = os.Getenv("MQTT_HOST") | ||
37 | - } | ||
38 | - if os.Getenv("MQTT_PORT") != "" { | ||
39 | - MQTT_PORT = os.Getenv("MQTT_PORT") | ||
40 | - } | ||
41 | - if os.Getenv("MQTT_USER") != "" { | ||
42 | - MQTT_USER = os.Getenv("MQTT_USER") | ||
43 | - } | ||
44 | - if os.Getenv("MQTT_PASSWORD") != "" { | ||
45 | - MQTT_PASSWORD = os.Getenv("MQTT_PASSWORD") | ||
46 | - } | 34 | + MQTT_HOST = Configurator.DefaultString("MQTT_HOST", MQTT_HOST) |
35 | + MQTT_PORT = Configurator.DefaultString("MQTT_PORT", MQTT_PORT) | ||
36 | + MQTT_USER = Configurator.DefaultString("MQTT_USER", MQTT_USER) | ||
37 | + MQTT_PASSWORD = Configurator.DefaultString("MQTT_PASSWORD", MQTT_PASSWORD) | ||
38 | + MQTT_UP = Configurator.DefaultBool("MQTT_UP", MQTT_UP) | ||
47 | } | 39 | } |
@@ -3,10 +3,6 @@ | @@ -3,10 +3,6 @@ | ||
3 | 3 | ||
4 | package constant | 4 | package constant |
5 | 5 | ||
6 | -import ( | ||
7 | - "os" | ||
8 | -) | ||
9 | - | ||
10 | var POSTGRESQL_DB_NAME = "terms" | 6 | var POSTGRESQL_DB_NAME = "terms" |
11 | var POSTGRESQL_USER = "postgres" | 7 | var POSTGRESQL_USER = "postgres" |
12 | var POSTGRESQL_PASSWORD = "123456" | 8 | var POSTGRESQL_PASSWORD = "123456" |
@@ -17,25 +13,12 @@ var DISABLE_SQL_GENERATE_PRINT = false | @@ -17,25 +13,12 @@ var DISABLE_SQL_GENERATE_PRINT = false | ||
17 | var DISABLE_SQL_GENERATE_COMMENT = true | 13 | var DISABLE_SQL_GENERATE_COMMENT = true |
18 | 14 | ||
19 | func init() { | 15 | func init() { |
20 | - if os.Getenv("POSTGRESQL_DB_NAME") != "" { | ||
21 | - POSTGRESQL_DB_NAME = os.Getenv("POSTGRESQL_DB_NAME") | ||
22 | - } | ||
23 | - if os.Getenv("POSTGRESQL_USER") != "" { | ||
24 | - POSTGRESQL_USER = os.Getenv("POSTGRESQL_USER") | ||
25 | - } | ||
26 | - if os.Getenv("POSTGRESQL_PASSWORD") != "" { | ||
27 | - POSTGRESQL_PASSWORD = os.Getenv("POSTGRESQL_PASSWORD") | ||
28 | - } | ||
29 | - if os.Getenv("POSTGRESQL_HOST") != "" { | ||
30 | - POSTGRESQL_HOST = os.Getenv("POSTGRESQL_HOST") | ||
31 | - } | ||
32 | - if os.Getenv("POSTGRESQL_PORT") != "" { | ||
33 | - POSTGRESQL_PORT = os.Getenv("POSTGRESQL_PORT") | ||
34 | - } | ||
35 | - if os.Getenv("DISABLE_CREATE_TABLE") != "" { | ||
36 | - DISABLE_CREATE_TABLE = true | ||
37 | - } | ||
38 | - if os.Getenv("DISABLE_SQL_GENERATE_PRINT") != "" { | ||
39 | - DISABLE_SQL_GENERATE_PRINT = true | ||
40 | - } | 16 | + POSTGRESQL_HOST = Configurator.DefaultString("POSTGRESQL_HOST", POSTGRESQL_HOST) |
17 | + POSTGRESQL_PORT = Configurator.DefaultString("POSTGRESQL_PORT", POSTGRESQL_PORT) | ||
18 | + POSTGRESQL_DB_NAME = Configurator.DefaultString("POSTGRESQL_DB_NAME", POSTGRESQL_DB_NAME) | ||
19 | + POSTGRESQL_USER = Configurator.DefaultString("POSTGRESQL_USER", POSTGRESQL_USER) | ||
20 | + POSTGRESQL_PASSWORD = Configurator.DefaultString("POSTGRESQL_PASSWORD", POSTGRESQL_PASSWORD) | ||
21 | + | ||
22 | + DISABLE_CREATE_TABLE = Configurator.DefaultBool("DISABLE_CREATE_TABLE", DISABLE_CREATE_TABLE) | ||
23 | + DISABLE_SQL_GENERATE_PRINT = Configurator.DefaultBool("DISABLE_SQL_GENERATE_PRINT", DISABLE_SQL_GENERATE_PRINT) | ||
41 | } | 24 | } |
1 | package constant | 1 | package constant |
2 | 2 | ||
3 | -import "os" | ||
4 | - | ||
5 | var ( | 3 | var ( |
6 | - REDIS_HOST = "127.0.0.1" | ||
7 | - REDIS_PORT = "6379" | ||
8 | - REDIS_AUTH = "" | 4 | + REDIS_HOST = "127.0.0.1" |
5 | + REDIS_PORT = "6379" | ||
6 | + REDIS_AUTH = "" | ||
7 | + REDIS_ADDRESS = "" | ||
8 | + | ||
9 | // 是否关闭仓储层缓存 | 9 | // 是否关闭仓储层缓存 |
10 | - DISABLE_REPOSITORY_CACHE = false | 10 | + ENABLE_REPOSITORY_CACHE = true |
11 | // 缓存过期时间 单位秒 | 11 | // 缓存过期时间 单位秒 |
12 | REPOSITORY_CACHE_EXPIRE = 30 * 60 | 12 | REPOSITORY_CACHE_EXPIRE = 30 * 60 |
13 | - | ||
14 | - REDIS_ADDRESS = "" | ||
15 | // redis 考勤机打卡消息队列 | 13 | // redis 考勤机打卡消息队列 |
16 | REDIS_ZKTECO_KEY = "allied-creation-zkteco" | 14 | REDIS_ZKTECO_KEY = "allied-creation-zkteco" |
17 | // redis 车间数据消息队列 | 15 | // redis 车间数据消息队列 |
@@ -19,21 +17,9 @@ var ( | @@ -19,21 +17,9 @@ var ( | ||
19 | ) | 17 | ) |
20 | 18 | ||
21 | func init() { | 19 | func init() { |
22 | - if os.Getenv("REDIS_HOST") != "" { | ||
23 | - REDIS_HOST = os.Getenv("REDIS_HOST") | ||
24 | - REDIS_AUTH = os.Getenv("REDIS_AUTH") | ||
25 | - } | ||
26 | - if os.Getenv("REDIS_PORT") != "" { | ||
27 | - REDIS_PORT = os.Getenv("REDIS_PORT") | ||
28 | - } | ||
29 | - if _, ok := os.LookupEnv("REDIS_AUTH"); ok { | ||
30 | - REDIS_AUTH = os.Getenv("REDIS_AUTH") | ||
31 | - } | ||
32 | - if os.Getenv("ENABLE_REPOSITORY_CACHE") != "" { | ||
33 | - DISABLE_REPOSITORY_CACHE = false | ||
34 | - } | ||
35 | - if os.Getenv("DISABLE_REPOSITORY_CACHE") != "" { | ||
36 | - DISABLE_REPOSITORY_CACHE = true | ||
37 | - } | 20 | + REDIS_HOST = Configurator.DefaultString("REDIS_HOST", REDIS_HOST) |
21 | + REDIS_PORT = Configurator.DefaultString("REDIS_PORT", REDIS_PORT) | ||
22 | + REDIS_AUTH = Configurator.DefaultString("REDIS_AUTH", REDIS_AUTH) | ||
23 | + ENABLE_REPOSITORY_CACHE = Configurator.DefaultBool("ENABLE_REPOSITORY_CACHE", ENABLE_REPOSITORY_CACHE) | ||
38 | REDIS_ADDRESS = REDIS_HOST + ":" + REDIS_PORT | 24 | REDIS_ADDRESS = REDIS_HOST + ":" + REDIS_PORT |
39 | } | 25 | } |
@@ -224,6 +224,17 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string | @@ -224,6 +224,17 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string | ||
224 | on = append(on, s) | 224 | on = append(on, s) |
225 | break | 225 | break |
226 | case 3: | 226 | case 3: |
227 | + if len(s) == 2 && s[1]-s[0] <= 5 { | ||
228 | + last := len(on) - 1 | ||
229 | + if last >= 0 && len(on[last]) == 2 { | ||
230 | + if on[last][1]+1 == s[0] { // [56,79] [80,80] => [56,80] | ||
231 | + on[last][1] = s[1] | ||
232 | + break | ||
233 | + } | ||
234 | + } | ||
235 | + on = append(on, s) | ||
236 | + break | ||
237 | + } | ||
227 | off = append(off, s) | 238 | off = append(off, s) |
228 | break | 239 | break |
229 | } | 240 | } |
@@ -2,8 +2,10 @@ package domain | @@ -2,8 +2,10 @@ package domain | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "errors" | 4 | "errors" |
5 | + "fmt" | ||
5 | "github.com/linmadan/egglib-go/utils/xtime" | 6 | "github.com/linmadan/egglib-go/utils/xtime" |
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" |
8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | ||
7 | "time" | 9 | "time" |
8 | ) | 10 | ) |
9 | 11 | ||
@@ -78,15 +80,48 @@ func (productAttendanceRecord *ProductAttendanceRecord) ComputeWorkTimeBefore(pr | @@ -78,15 +80,48 @@ func (productAttendanceRecord *ProductAttendanceRecord) ComputeWorkTimeBefore(pr | ||
78 | if !productAttendanceRecord.SignOut.After(productAttendanceRecord.SignIn) { | 80 | if !productAttendanceRecord.SignOut.After(productAttendanceRecord.SignIn) { |
79 | return 0 | 81 | return 0 |
80 | } | 82 | } |
81 | - wt := utils.Round(productAttendanceRecord.SignOut.Sub(productAttendanceRecord.SignIn).Hours(), 1) | 83 | + signIn := roundTime(productAttendanceRecord.SignIn) |
84 | + signOut := roundTime(productAttendanceRecord.SignOut) | ||
85 | + wt := utils.Round(signOut.Sub(signIn).Hours(), 2) | ||
82 | if productCalendar == nil { | 86 | if productCalendar == nil { |
83 | - return wt | 87 | + return roundWorkTime(wt) |
84 | } | 88 | } |
85 | wt = wt - productAttendanceRecord.AttendanceBreakTime(productCalendar) | 89 | wt = wt - productAttendanceRecord.AttendanceBreakTime(productCalendar) |
86 | if wt < 0 { | 90 | if wt < 0 { |
87 | return 0 | 91 | return 0 |
88 | } | 92 | } |
89 | - return wt | 93 | + return roundWorkTime(wt) |
94 | +} | ||
95 | + | ||
96 | +// roundWorkTime 工时取整[0:0.167]=> 0 \ [0.167,0.667]=> 0.5 \ [0.667,1]=>1 | ||
97 | +// 10/60 = 0.167 40/60 = 0.667 | ||
98 | +func roundWorkTime(wt float64) float64 { | ||
99 | + i := float64(int(wt)) | ||
100 | + f := wt - i | ||
101 | + if f < 0.167 { | ||
102 | + return i | ||
103 | + } | ||
104 | + if f >= 0.167 && f < 0.667 { | ||
105 | + return i + 0.5 | ||
106 | + } | ||
107 | + if f >= 0.667 { | ||
108 | + return i + 1 | ||
109 | + } | ||
110 | + return i | ||
111 | +} | ||
112 | + | ||
113 | +func roundTime(t time.Time) time.Time { | ||
114 | + hour, min, _ := t.Local().Clock() | ||
115 | + y, m, d := t.Local().Date() | ||
116 | + newTime := time.Date(y, m, d, hour, 0, 0, 0, time.Local) | ||
117 | + if min < 11 { | ||
118 | + min = 0 | ||
119 | + } else if min >= 11 && min < 41 { | ||
120 | + min = 30 | ||
121 | + } else { | ||
122 | + min = 60 | ||
123 | + } | ||
124 | + return newTime.Add(time.Minute * time.Duration(min)) | ||
90 | } | 125 | } |
91 | 126 | ||
92 | func (productAttendanceRecord *ProductAttendanceRecord) SetProductTimeByProductCalendar(productCalendar *ProductCalendar) error { | 127 | func (productAttendanceRecord *ProductAttendanceRecord) SetProductTimeByProductCalendar(productCalendar *ProductCalendar) error { |
@@ -100,7 +135,7 @@ func (productAttendanceRecord *ProductAttendanceRecord) SetProductTimeByProductC | @@ -100,7 +135,7 @@ func (productAttendanceRecord *ProductAttendanceRecord) SetProductTimeByProductC | ||
100 | return nil | 135 | return nil |
101 | } | 136 | } |
102 | newNow := now.BeginningOfDay().Add(-time.Hour * 24) | 137 | newNow := now.BeginningOfDay().Add(-time.Hour * 24) |
103 | - if overDay && productCalendar.MatchCalendarSelected(newNow) { | 138 | + if overDay { //&& productCalendar.MatchCalendarSelected(newNow) |
104 | productAttendanceRecord.ProductDate = newNow | 139 | productAttendanceRecord.ProductDate = newNow |
105 | } | 140 | } |
106 | return nil | 141 | return nil |
@@ -132,20 +167,20 @@ func (productAttendanceRecord *ProductAttendanceRecord) ProductTime() time.Time | @@ -132,20 +167,20 @@ func (productAttendanceRecord *ProductAttendanceRecord) ProductTime() time.Time | ||
132 | } | 167 | } |
133 | 168 | ||
134 | func (productAttendanceRecord *ProductAttendanceRecord) GroupName() string { | 169 | func (productAttendanceRecord *ProductAttendanceRecord) GroupName() string { |
135 | - if productAttendanceRecord.Ext != nil { | 170 | + if productAttendanceRecord.Ext == nil { |
136 | return "" | 171 | return "" |
137 | } | 172 | } |
138 | - if productAttendanceRecord.Ext.AttendanceExt != nil { | 173 | + if productAttendanceRecord.Ext.AttendanceExt == nil { |
139 | return "" | 174 | return "" |
140 | } | 175 | } |
141 | return productAttendanceRecord.Ext.AttendanceExt.GroupName | 176 | return productAttendanceRecord.Ext.AttendanceExt.GroupName |
142 | } | 177 | } |
143 | 178 | ||
144 | func (productAttendanceRecord *ProductAttendanceRecord) ApproveUser() *User { | 179 | func (productAttendanceRecord *ProductAttendanceRecord) ApproveUser() *User { |
145 | - if productAttendanceRecord.Ext != nil { | 180 | + if productAttendanceRecord.Ext == nil { |
146 | return nil | 181 | return nil |
147 | } | 182 | } |
148 | - if productAttendanceRecord.Ext.AttendanceExt != nil { | 183 | + if productAttendanceRecord.Ext.AttendanceExt == nil { |
149 | return nil | 184 | return nil |
150 | } | 185 | } |
151 | if productAttendanceRecord.Ext.AttendanceExt.ApproveUserId == 0 { | 186 | if productAttendanceRecord.Ext.AttendanceExt.ApproveUserId == 0 { |
@@ -179,11 +214,19 @@ func (productAttendanceRecord *ProductAttendanceRecord) AttendanceBreakTime(prod | @@ -179,11 +214,19 @@ func (productAttendanceRecord *ProductAttendanceRecord) AttendanceBreakTime(prod | ||
179 | var ( | 214 | var ( |
180 | checkSignIn, checkSignOut time.Time | 215 | checkSignIn, checkSignOut time.Time |
181 | ) | 216 | ) |
182 | - checkSignIn = v.GetCheckBeginTime(signIn) | ||
183 | - checkSignOut = v.GetCheckEndTime(signIn) | ||
184 | - if xtime.BeforeEqual(signIn, checkSignIn) && xtime.AfterEqual(signOut, checkSignOut) { | ||
185 | - bt += v.BreakTime | 217 | + checkSignIn = v.GetCheckBeginTime(signIn.Local()) |
218 | + checkSignOut = v.GetCheckEndTime(signIn.Local()) | ||
219 | + if xtime.BeforeEqual(signIn.Local(), checkSignIn) && xtime.AfterEqual(signOut.Local(), checkSignIn) { | ||
220 | + if xtime.AfterEqual(signOut.Local(), checkSignOut) { | ||
221 | + bt += v.BreakTime | ||
222 | + } else { | ||
223 | + bt += utils.Round(signOut.Local().Sub(checkSignIn).Hours(), 2) | ||
224 | + } | ||
186 | } | 225 | } |
226 | + log.Logger.Debug(fmt.Sprintf("range(%v,%v) actual(%v,%v) break_time:%v", checkSignIn, checkSignOut, signIn.Local(), signOut.Local(), bt)) | ||
227 | + } | ||
228 | + if productAttendanceRecord.Ext != nil && productAttendanceRecord.Ext.AttendanceExt != nil { | ||
229 | + productAttendanceRecord.Ext.AttendanceExt.BreakTime = bt | ||
187 | } | 230 | } |
188 | return bt | 231 | return bt |
189 | } | 232 | } |
@@ -14,4 +14,6 @@ type ProductAttendanceRecordExt struct { | @@ -14,4 +14,6 @@ type ProductAttendanceRecordExt struct { | ||
14 | ApproveUserName string `json:"approveUserName,omitempty"` | 14 | ApproveUserName string `json:"approveUserName,omitempty"` |
15 | // 审核时间 | 15 | // 审核时间 |
16 | ApproveAt int64 `json:"approveAt,omitempty"` | 16 | ApproveAt int64 `json:"approveAt,omitempty"` |
17 | + // 休息时间 | ||
18 | + BreakTime float64 `json:"breakTime"` | ||
17 | } | 19 | } |
@@ -25,8 +25,8 @@ func TestComputeWorkTimeBefore(t *testing.T) { | @@ -25,8 +25,8 @@ func TestComputeWorkTimeBefore(t *testing.T) { | ||
25 | []*ProductAttendanceRecord{ | 25 | []*ProductAttendanceRecord{ |
26 | { | 26 | { |
27 | SignIn: xtime.MustParse("2022-05-05 09:00:00"), | 27 | SignIn: xtime.MustParse("2022-05-05 09:00:00"), |
28 | - SignOut: xtime.MustParse("2022-05-05 12:00:00"), | ||
29 | - WorkTimeBefore: 2, | 28 | + SignOut: xtime.MustParse("2022-05-05 13:00:00"), |
29 | + WorkTimeBefore: 3, | ||
30 | }, | 30 | }, |
31 | { | 31 | { |
32 | SignIn: xtime.MustParse("2022-05-05 12:00:00"), | 32 | SignIn: xtime.MustParse("2022-05-05 12:00:00"), |
@@ -34,16 +34,16 @@ func (period *ProductCalendarBreakTimePeriod) CheckOverDay() (bool, error) { | @@ -34,16 +34,16 @@ func (period *ProductCalendarBreakTimePeriod) CheckOverDay() (bool, error) { | ||
34 | 34 | ||
35 | func (period *ProductCalendarBreakTimePeriod) GetCheckBeginTime(t time.Time) time.Time { | 35 | func (period *ProductCalendarBreakTimePeriod) GetCheckBeginTime(t time.Time) time.Time { |
36 | y, m, d := t.Date() | 36 | y, m, d := t.Date() |
37 | - inHour, _ := strconv.Atoi(strings.Split(period.BeginAt, ":")[0]) | ||
38 | - inMinuter, _ := strconv.Atoi(strings.Split(period.BeginAt, ":")[1]) | ||
39 | - return time.Date(y, m, d, inHour, inMinuter, 0, 0, t.Location()) | 37 | + inHour, _ := strconv.ParseInt(strings.Split(period.BeginAt, ":")[0], 10, 64) |
38 | + inMinuter, _ := strconv.ParseInt(strings.Split(period.BeginAt, ":")[1], 10, 64) | ||
39 | + return time.Date(y, m, d, int(inHour), int(inMinuter), 0, 0, time.Local) | ||
40 | } | 40 | } |
41 | 41 | ||
42 | func (period *ProductCalendarBreakTimePeriod) GetCheckEndTime(t time.Time) time.Time { | 42 | func (period *ProductCalendarBreakTimePeriod) GetCheckEndTime(t time.Time) time.Time { |
43 | y, m, d := t.Date() | 43 | y, m, d := t.Date() |
44 | - inHour, _ := strconv.Atoi(strings.Split(period.EndAt, ":")[0]) | ||
45 | - inMinuter, _ := strconv.Atoi(strings.Split(period.EndAt, ":")[1]) | ||
46 | - checkTime := time.Date(y, m, d, inHour, inMinuter, 0, 0, t.Location()) | 44 | + inHour, _ := strconv.ParseInt(strings.Split(period.EndAt, ":")[0], 10, 64) |
45 | + inMinuter, _ := strconv.ParseInt(strings.Split(period.EndAt, ":")[1], 10, 64) | ||
46 | + checkTime := time.Date(y, m, d, int(inHour), int(inMinuter), 0, 0, time.Local) | ||
47 | if overDay, err := period.CheckOverDay(); overDay && err == nil { | 47 | if overDay, err := period.CheckOverDay(); overDay && err == nil { |
48 | return checkTime.AddDate(0, 0, 1) | 48 | return checkTime.AddDate(0, 0, 1) |
49 | } | 49 | } |
@@ -15,8 +15,11 @@ const ( | @@ -15,8 +15,11 @@ const ( | ||
15 | ) | 15 | ) |
16 | 16 | ||
17 | const ( | 17 | const ( |
18 | - ProductRecordNotApprove = 1 // 未审核 | ||
19 | - ProductRecordApproved = 2 // 已审核 | 18 | + ProductRecordNotApprove = 1 // 未审核 |
19 | + ProductRecordApproved = 2 // 已审核 | ||
20 | + ProductRecordWithdraw = 3 // 已撤回 | ||
21 | + ProductRecordLogged = 4 // 已记录 | ||
22 | + ProductRecordAutoApproved = 5 // 自动审核 | ||
20 | ) | 23 | ) |
21 | 24 | ||
22 | // 生产记录 | 25 | // 生产记录 |
@@ -82,6 +85,21 @@ func (productRecord *ProductRecord) Approve(approveUser *User, weighAfter float6 | @@ -82,6 +85,21 @@ func (productRecord *ProductRecord) Approve(approveUser *User, weighAfter float6 | ||
82 | return nil | 85 | return nil |
83 | } | 86 | } |
84 | 87 | ||
88 | +func (productRecord *ProductRecord) Cancel() error { | ||
89 | + if productRecord.ProductRecordInfo.ApproveStatus == ProductRecordApproved { | ||
90 | + return errors.New("已审核") | ||
91 | + } | ||
92 | + if productRecord.ProductRecordInfo.ApproveStatus == ProductRecordWithdraw { | ||
93 | + return errors.New("已撤销") | ||
94 | + } | ||
95 | + //if xtime.BeforeEqual(productRecord.CreatedAt, xtime.BeginningOfDay()) { | ||
96 | + // return errors.New("已记录") | ||
97 | + //} | ||
98 | + productRecord.ProductRecordInfo.ApproveStatus = ProductRecordWithdraw | ||
99 | + productRecord.UpdatedAt = time.Now() | ||
100 | + return nil | ||
101 | +} | ||
102 | + | ||
85 | func TaskKeyPatternProductRecordStatics() string { | 103 | func TaskKeyPatternProductRecordStatics() string { |
86 | return fmt.Sprintf("%v:task:product-record:statics", constant.CACHE_PREFIX) | 104 | return fmt.Sprintf("%v:task:product-record:statics", constant.CACHE_PREFIX) |
87 | } | 105 | } |
@@ -11,7 +11,7 @@ const ( | @@ -11,7 +11,7 @@ const ( | ||
11 | ) | 11 | ) |
12 | 12 | ||
13 | const ( | 13 | const ( |
14 | - ProductSection1 = "打料" | 14 | + ProductSection1 = "制模" |
15 | ProductSection2 = "成型" | 15 | ProductSection2 = "成型" |
16 | ProductSection3 = "穿串" | 16 | ProductSection3 = "穿串" |
17 | ProductSection4 = "包装" | 17 | ProductSection4 = "包装" |
@@ -12,7 +12,7 @@ type ProductRecordInfo struct { | @@ -12,7 +12,7 @@ type ProductRecordInfo struct { | ||
12 | WeighBefore float64 `json:"weighBefore"` | 12 | WeighBefore float64 `json:"weighBefore"` |
13 | // 产能-审核后 | 13 | // 产能-审核后 |
14 | WeighAfter float64 `json:"weighAfter"` | 14 | WeighAfter float64 `json:"weighAfter"` |
15 | - // 审核状态 1:未审核 2:已审核 | 15 | + // 审核状态 1:未审核 2:已审核 3.已撤回 4.已记录 5.自动审核 |
16 | ApproveStatus int `json:"approveStatus"` | 16 | ApproveStatus int `json:"approveStatus"` |
17 | // 审核时间 | 17 | // 审核时间 |
18 | ApproveAt int64 `json:"approveAt"` | 18 | ApproveAt int64 `json:"approveAt"` |
@@ -6,6 +6,15 @@ const ( | @@ -6,6 +6,15 @@ const ( | ||
6 | EmployeePartTime = 3 // 临时 | 6 | EmployeePartTime = 3 // 临时 |
7 | ) | 7 | ) |
8 | 8 | ||
9 | +// 用户状态 | ||
10 | +const ( | ||
11 | + UserStatusEnable UserStatus = 1 | ||
12 | + UserStatusDisable UserStatus = 2 | ||
13 | + UserStatusDestroy UserStatus = 3 | ||
14 | +) | ||
15 | + | ||
16 | +type UserStatus int | ||
17 | + | ||
9 | // 用户对象 | 18 | // 用户对象 |
10 | type User struct { | 19 | type User struct { |
11 | // 用户Id 用户唯一标识 | 20 | // 用户Id 用户唯一标识 |
@@ -21,6 +30,8 @@ type User struct { | @@ -21,6 +30,8 @@ type User struct { | ||
21 | // 手机号码 | 30 | // 手机号码 |
22 | Phone string `json:"phone,omitempty"` | 31 | Phone string `json:"phone,omitempty"` |
23 | 32 | ||
33 | + // 启用状态 | ||
34 | + EnableStatus int `json:"-"` | ||
24 | // 额外扩展的参数 | 35 | // 额外扩展的参数 |
25 | GroupId int `json:"-"` | 36 | GroupId int `json:"-"` |
26 | GroupName string `json:"-"` | 37 | GroupName string `json:"-"` |
@@ -176,3 +176,12 @@ func (gateway HttpLibAlliedCreationUser) OrgSearch(param ReqOrgSearch) (int, []* | @@ -176,3 +176,12 @@ func (gateway HttpLibAlliedCreationUser) OrgSearch(param ReqOrgSearch) (int, []* | ||
176 | err := gateway.FastDoRequest(url, method, param, &data) | 176 | err := gateway.FastDoRequest(url, method, param, &data) |
177 | return data.Count, data.Orgs, err | 177 | return data.Count, data.Orgs, err |
178 | } | 178 | } |
179 | + | ||
180 | +// TerminalReport 终端汇报 | ||
181 | +func (gateway HttpLibAlliedCreationUser) TerminalReport(param ReqTerminalReport) (DataTerminalReport, error) { | ||
182 | + url := gateway.Host() + "/terminal/report" | ||
183 | + method := "post" | ||
184 | + var data DataTerminalReport | ||
185 | + err := gateway.FastDoRequest(url, method, param, &data) | ||
186 | + return data, err | ||
187 | +} |
@@ -163,3 +163,21 @@ type ( | @@ -163,3 +163,21 @@ type ( | ||
163 | Orgs []*models.Organization `json:"orgs"` | 163 | Orgs []*models.Organization `json:"orgs"` |
164 | } | 164 | } |
165 | ) | 165 | ) |
166 | + | ||
167 | +//返回组织列表 | ||
168 | +type ( | ||
169 | + ReqTerminalReport struct { | ||
170 | + TerminalType string `json:"terminalType"` | ||
171 | + TerminalId string `json:"terminalId"` | ||
172 | + Command string `json:"command"` | ||
173 | + Content string `json:"content"` | ||
174 | + Table string `json:"table"` | ||
175 | + | ||
176 | + CompanyId int64 `json:"companyId"` | ||
177 | + OrgId int64 `json:"orgId"` | ||
178 | + } | ||
179 | + | ||
180 | + DataTerminalReport struct { | ||
181 | + Response string `json:"response"` | ||
182 | + } | ||
183 | +) |
@@ -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 |
@@ -29,7 +29,7 @@ func NewProductPlanDispatchRecord(transactionContext *pgTransaction.TransactionC | @@ -29,7 +29,7 @@ func NewProductPlanDispatchRecord(transactionContext *pgTransaction.TransactionC | ||
29 | // 日期 | 29 | // 日期 |
30 | // 产品编号 | 30 | // 产品编号 |
31 | // 调度状态 status | 31 | // 调度状态 status |
32 | -func (dao *ProductPlanDispatchRecordDao) DeviceProductPlan(companyId, orgId int, workStationId string, date time.Time, productCode string, status int) (*domain.ProductPlanDispatchRecord, error) { | 32 | +func (dao *ProductPlanDispatchRecordDao) ProductPlanDispatchRecord(companyId, orgId int, workStationId string, date time.Time, productCode string, status int) (*domain.ProductPlanDispatchRecord, error) { |
33 | tx := dao.transactionContext.PgTx | 33 | tx := dao.transactionContext.PgTx |
34 | productPlanDispatchRecordModel := new(models.ProductPlanDispatchRecord) | 34 | productPlanDispatchRecordModel := new(models.ProductPlanDispatchRecord) |
35 | query := sqlbuilder.BuildQuery(tx.Model(productPlanDispatchRecordModel), map[string]interface{}{}) | 35 | query := sqlbuilder.BuildQuery(tx.Model(productPlanDispatchRecordModel), map[string]interface{}{}) |
@@ -37,7 +37,9 @@ func (dao *ProductPlanDispatchRecordDao) DeviceProductPlan(companyId, orgId int, | @@ -37,7 +37,9 @@ func (dao *ProductPlanDispatchRecordDao) DeviceProductPlan(companyId, orgId int, | ||
37 | query.Where("org_id = ?", orgId) | 37 | query.Where("org_id = ?", orgId) |
38 | query.Where("work_station->>'workStationId'=?", workStationId) | 38 | query.Where("work_station->>'workStationId'=?", workStationId) |
39 | query.Where("product_date = ?", date) | 39 | query.Where("product_date = ?", date) |
40 | - query.Where("plan_dispatch_status = ?", status) | 40 | + if status > 0 { |
41 | + query.Where("plan_dispatch_status = ?", status) | ||
42 | + } | ||
41 | query.Where("plan_dispatch_record_ext->>'productCode'=?", productCode) | 43 | query.Where("plan_dispatch_record_ext->>'productCode'=?", productCode) |
42 | query.Order("updated_at desc") | 44 | query.Order("updated_at desc") |
43 | if err := query.First(); err != nil { | 45 | if err := query.First(); err != nil { |
@@ -53,3 +55,57 @@ func (dao *ProductPlanDispatchRecordDao) DeviceProductPlan(companyId, orgId int, | @@ -53,3 +55,57 @@ func (dao *ProductPlanDispatchRecordDao) DeviceProductPlan(companyId, orgId int, | ||
53 | return transform.TransformToProductPlanDispatchRecordDomainModelFromPgModels(productPlanDispatchRecordModel) | 55 | return transform.TransformToProductPlanDispatchRecordDomainModelFromPgModels(productPlanDispatchRecordModel) |
54 | } | 56 | } |
55 | } | 57 | } |
58 | + | ||
59 | +func (dao *ProductPlanDispatchRecordDao) ProductPlan(companyId, orgId int, workshopId int, date time.Time, productCode string) (*domain.ProductPlan, error) { | ||
60 | + tx := dao.transactionContext.PgTx | ||
61 | + productPlan := new(models.ProductPlan) | ||
62 | + query := sqlbuilder.BuildQuery(tx.Model(productPlan), map[string]interface{}{}) | ||
63 | + query.Where("company_id = ?", companyId) | ||
64 | + query.Where("org_id = ?", orgId) | ||
65 | + query.Where("workshop->>'workshopId'='?'", workshopId) | ||
66 | + query.Where("product_date = ?", date) | ||
67 | + if len(productCode) > 0 { | ||
68 | + query.Where("ext #>>'{productPlanExt,productCode}'=?", productCode) | ||
69 | + } | ||
70 | + query.Order("updated_at desc") | ||
71 | + if err := query.First(); err != nil { | ||
72 | + if err.Error() == "pg: no rows in result set" { | ||
73 | + return nil, domain.ErrorNotFound | ||
74 | + } else { | ||
75 | + return nil, err | ||
76 | + } | ||
77 | + } | ||
78 | + if productPlan.ProductPlanId == 0 { | ||
79 | + return nil, nil | ||
80 | + } else { | ||
81 | + return transform.TransformToProductPlanDomainModelFromPgModels(productPlan) | ||
82 | + } | ||
83 | +} | ||
84 | + | ||
85 | +func (dao *ProductPlanDispatchRecordDao) ProductPlans(companyId, orgId int, workshopId int, date time.Time, productCode string) ([]*domain.ProductPlan, error) { | ||
86 | + tx := dao.transactionContext.PgTx | ||
87 | + productPlan := new(models.ProductPlan) | ||
88 | + query := sqlbuilder.BuildQuery(tx.Model(productPlan), map[string]interface{}{}) | ||
89 | + query.Where("company_id = ?", companyId) | ||
90 | + query.Where("org_id = ?", orgId) | ||
91 | + query.Where("workshop->>'workshopId'='?'", workshopId) | ||
92 | + query.Where("product_date = ?", date) | ||
93 | + if len(productCode) > 0 { | ||
94 | + query.Where("ext #>>'{productPlanExt,productCode}'=?", productCode) | ||
95 | + } | ||
96 | + query.Order("updated_at desc") | ||
97 | + var productPlanModels = make([]*models.ProductPlan, 0) | ||
98 | + var productPlans = make([]*domain.ProductPlan, 0) | ||
99 | + if err := query.Select(&productPlanModels); err != nil { | ||
100 | + return productPlans, err | ||
101 | + } else { | ||
102 | + for _, productPlanModel := range productPlanModels { | ||
103 | + if productPlan, err := transform.TransformToProductPlanDomainModelFromPgModels(productPlanModel); err != nil { | ||
104 | + return productPlans, err | ||
105 | + } else { | ||
106 | + productPlans = append(productPlans, productPlan) | ||
107 | + } | ||
108 | + } | ||
109 | + return productPlans, nil | ||
110 | + } | ||
111 | +} |
@@ -117,7 +117,7 @@ select sum(a.weight) item_total,max(sname) sname from ( | @@ -117,7 +117,7 @@ select sum(a.weight) item_total,max(sname) sname from ( | ||
117 | and product_record_info->>'approveStatus'='2' | 117 | and product_record_info->>'approveStatus'='2' |
118 | and created_at >=? | 118 | and created_at >=? |
119 | and created_at <? | 119 | and created_at <? |
120 | - and work_station->>'sectionName' in ('打料','成型','穿串','包装') | 120 | + and work_station->>'sectionName' in ('制模','成型','穿串','包装') |
121 | ) a | 121 | ) a |
122 | group by a.workStationId | 122 | group by a.workStationId |
123 | ) | 123 | ) |
@@ -127,10 +127,31 @@ select sname,round(item_total/(select sum(item_total) from item_product)*100, 0) | @@ -127,10 +127,31 @@ select sname,round(item_total/(select sum(item_total) from item_product)*100, 0) | ||
127 | ) | 127 | ) |
128 | --select * from item_product_rate | 128 | --select * from item_product_rate |
129 | select a.sname, coalesce(b.rate,0) rate from ( | 129 | select a.sname, coalesce(b.rate,0) rate from ( |
130 | - select unnest(ARRAY ['打料','成型','穿串','包装']) sname | 130 | + select unnest(ARRAY ['制模','成型','穿串','包装']) sname |
131 | ) a left join item_product_rate b on a.sname=b.sname`) | 131 | ) a left join item_product_rate b on a.sname=b.sname`) |
132 | if _, err := tx.Query(result, sql, companyId, orgId, workshopId, beginTime, endTime); err != nil { | 132 | if _, err := tx.Query(result, sql, companyId, orgId, workshopId, beginTime, endTime); err != nil { |
133 | return err | 133 | return err |
134 | } | 134 | } |
135 | return nil | 135 | return nil |
136 | } | 136 | } |
137 | + | ||
138 | +// ProductWeightStatics 产能统计 | ||
139 | +func (dao *ProductRecordDao) ProductWeightStatics(companyId, orgId, productRecordType, productPlanId int, workstationId string, beginTime time.Time, endTime time.Time) (float64, error) { | ||
140 | + | ||
141 | + tx := dao.transactionContext.PgTx | ||
142 | + var result = struct { | ||
143 | + Total float64 | ||
144 | + }{} | ||
145 | + sql := fmt.Sprintf(` | ||
146 | +select coalesce(sum(cast(product_record_info->>'original' as DECIMAL)),0) total | ||
147 | +from manufacture.product_records | ||
148 | +where company_id = ? and org_id = ? and product_record_type = ? | ||
149 | +and work_station->>'workStationId' = ? | ||
150 | +and product_record_info->>'productPlanId' = '?' | ||
151 | +and created_at >= ? and created_at < ? | ||
152 | +`) | ||
153 | + if _, err := tx.QueryOne(&result, sql, companyId, orgId, productRecordType, workstationId, productPlanId, beginTime, endTime); err != nil { | ||
154 | + return 0, err | ||
155 | + } | ||
156 | + return result.Total, nil | ||
157 | +} |
@@ -63,6 +63,7 @@ func (svr *UserService) ToUser(from *models.User) *domain.User { | @@ -63,6 +63,7 @@ func (svr *UserService) ToUser(from *models.User) *domain.User { | ||
63 | IcCardNumber: from.IcCardNumber, | 63 | IcCardNumber: from.IcCardNumber, |
64 | Avatar: from.UserInfo.Avatar, | 64 | Avatar: from.UserInfo.Avatar, |
65 | Phone: from.UserInfo.Phone, | 65 | Phone: from.UserInfo.Phone, |
66 | + EnableStatus: from.EnableStatus, | ||
66 | } | 67 | } |
67 | if user.EmployeeType == 0 { | 68 | if user.EmployeeType == 0 { |
68 | user.EmployeeType = 1 //默认正式员工 | 69 | user.EmployeeType = 1 //默认正式员工 |
@@ -100,9 +100,9 @@ func (ptr *PGCommonStatisticsService) HourProductiveStatistics(queryOptions map[ | @@ -100,9 +100,9 @@ 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()) { | ||
104 | - beginTime = request.Date.Time().AddDate(0, 0, -1) | ||
105 | - endTime = request.Date.Time() | 103 | + if !xtime.IsZero(request.Date.Time()) && !request.Date.Time().Equal(beginTime) { |
104 | + beginTime = request.Date.Time() | ||
105 | + endTime = request.Date.Time().AddDate(0, 0, 1) | ||
106 | } | 106 | } |
107 | for _, v := range workshop.GetProductLines(domain.NotDeleted) { | 107 | for _, v := range workshop.GetProductLines(domain.NotDeleted) { |
108 | var result = make([]*record, 0) | 108 | var result = make([]*record, 0) |
@@ -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") |
@@ -180,7 +180,31 @@ func (ptr *PGProductRecordService) Approve(productRecordId int, approveUserId in | @@ -180,7 +180,31 @@ func (ptr *PGProductRecordService) Approve(productRecordId int, approveUserId in | ||
180 | return struct{}{}, nil | 180 | return struct{}{}, nil |
181 | } | 181 | } |
182 | 182 | ||
183 | -func (ptr *PGProductRecordService) BatchApprove(list []*domain.ProductRecord, approveUserId int, weight float64, status int) (interface{}, error) { | 183 | +// Approve 审核生产记录 (二级品审核) |
184 | +func (ptr *PGProductRecordService) Cancel(productRecordId int) (interface{}, error) { | ||
185 | + productRecordRepository, err := repository.NewProductRecordRepository(ptr.transactionContext) | ||
186 | + | ||
187 | + var productRecord *domain.ProductRecord | ||
188 | + productRecord, err = productRecordRepository.FindOne(map[string]interface{}{"productRecordId": productRecordId}) | ||
189 | + if err != nil { | ||
190 | + return nil, err | ||
191 | + } | ||
192 | + | ||
193 | + if err = productRecord.Cancel(); err != nil { | ||
194 | + return nil, err | ||
195 | + } | ||
196 | + if _, err = productRecordRepository.Save(productRecord); err != nil { | ||
197 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
198 | + } | ||
199 | + // 发送Job | ||
200 | + productRecord.ProductRecordInfo.Weigh = -productRecord.ProductRecordInfo.Weigh | ||
201 | + if err = SendProductRecordStaticsJob(productRecord); err != nil { | ||
202 | + return nil, err | ||
203 | + } | ||
204 | + return struct{}{}, nil | ||
205 | +} | ||
206 | + | ||
207 | +func (ptr *PGProductRecordService) BatchApprove(list []*domain.ProductRecord, approveUserId int, weightAfter float64, status int) (interface{}, error) { | ||
184 | var productRecordRepository, _ = repository.NewProductRecordRepository(ptr.transactionContext) | 208 | var productRecordRepository, _ = repository.NewProductRecordRepository(ptr.transactionContext) |
185 | var record *domain.ProductRecord | 209 | var record *domain.ProductRecord |
186 | var err error | 210 | var err error |
@@ -196,26 +220,19 @@ func (ptr *PGProductRecordService) BatchApprove(list []*domain.ProductRecord, ap | @@ -196,26 +220,19 @@ func (ptr *PGProductRecordService) BatchApprove(list []*domain.ProductRecord, ap | ||
196 | 220 | ||
197 | for i := range list { | 221 | for i := range list { |
198 | record = list[i] | 222 | record = list[i] |
199 | - t := record.ProductRecordInfo.WeighBefore | ||
200 | - if weight > 0 { | ||
201 | - t = weight | 223 | + weighBefore := record.ProductRecordInfo.WeighBefore |
224 | + if weightAfter > 0 { | ||
225 | + weighBefore = weightAfter | ||
202 | } | 226 | } |
203 | - if t <= 0 && status == domain.AttendanceAutoApproved { | 227 | + if weighBefore <= 0 || record.ProductRecordInfo.ApproveStatus != domain.ProductRecordNotApprove { |
204 | continue | 228 | continue |
205 | } | 229 | } |
206 | - if err = record.Approve(user, t, time.Now(), status); err != nil { | 230 | + if err = record.Approve(user, weighBefore, time.Now(), status); err != nil { |
207 | return nil, err | 231 | return nil, err |
208 | } | 232 | } |
209 | if _, err := productRecordRepository.Save(record); err != nil { | 233 | if _, err := productRecordRepository.Save(record); err != nil { |
210 | return nil, err | 234 | return nil, err |
211 | } | 235 | } |
212 | - } | ||
213 | - | ||
214 | - for i := range list { | ||
215 | - record = list[i] | ||
216 | - if record.ProductRecordInfo.WeighBefore <= 0 && status == domain.AttendanceAutoApproved { | ||
217 | - continue | ||
218 | - } | ||
219 | if e := SendProductRecordStaticsJob(record); e != nil { | 236 | if e := SendProductRecordStaticsJob(record); e != nil { |
220 | log.Logger.Error("【发送产量统计任务失败】" + e.Error()) | 237 | log.Logger.Error("【发送产量统计任务失败】" + e.Error()) |
221 | } | 238 | } |
@@ -11,7 +11,7 @@ import ( | @@ -11,7 +11,7 @@ import ( | ||
11 | ) | 11 | ) |
12 | 12 | ||
13 | const ( | 13 | const ( |
14 | - ProductSection1 = "打料" | 14 | + ProductSection1 = "制模" //打料更新为制模 |
15 | ProductSection2 = "成型" | 15 | ProductSection2 = "成型" |
16 | ProductSection3 = "穿串" | 16 | ProductSection3 = "穿串" |
17 | ProductSection4 = "包装" | 17 | ProductSection4 = "包装" |
@@ -298,7 +298,7 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain. | @@ -298,7 +298,7 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain. | ||
298 | workshopProductRecordDao, _ := dao.NewWorkshopProductRecordDao(ptr.transactionContext) | 298 | workshopProductRecordDao, _ := dao.NewWorkshopProductRecordDao(ptr.transactionContext) |
299 | workshopProductRecord, err = workshopProductRecordDao.WorkshopProductRecord(cid, oid, productRecord.WorkStation.WorkStationId, planId, productRecord.CreatedAt) | 299 | workshopProductRecord, err = workshopProductRecordDao.WorkshopProductRecord(cid, oid, productRecord.WorkStation.WorkStationId, planId, productRecord.CreatedAt) |
300 | if err == domain.ErrorNotFound { | 300 | if err == domain.ErrorNotFound { |
301 | - workshopProductRecord = newWorkshopProductRecord(productRecord, productPlan) | 301 | + workshopProductRecord = NewWorkshopProductRecord(productRecord, productPlan) |
302 | } else { | 302 | } else { |
303 | if err != nil { | 303 | if err != nil { |
304 | log.Logger.Error(err.Error()) | 304 | log.Logger.Error(err.Error()) |
@@ -310,9 +310,9 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain. | @@ -310,9 +310,9 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain. | ||
310 | workshopProductRecord.ProductWeigh, productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordInfo.Original)) | 310 | workshopProductRecord.ProductWeigh, productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordInfo.Original)) |
311 | workshopProductRecord.UpdateProductWeigh(productRecord) | 311 | workshopProductRecord.UpdateProductWeigh(productRecord) |
312 | // 打料 跟 成型工段的初始产能是批次的产能 | 312 | // 打料 跟 成型工段的初始产能是批次的产能 |
313 | - if productRecord.WorkStation.SectionName == ProductSection1 && productRecord.WorkStation.SectionName == ProductSection2 { | ||
314 | - workshopProductRecord.AddPlanProductWeight(productPlan.PlanDevoted.Weight, productPlan.ProductPlanId) | ||
315 | - } | 313 | + //if productRecord.WorkStation.SectionName == ProductSection1 || productRecord.WorkStation.SectionName == ProductSection2 { |
314 | + // workshopProductRecord.AddPlanProductWeight(productPlan.PlanDevoted.Weight, productPlan.ProductPlanId) | ||
315 | + //} | ||
316 | 316 | ||
317 | if workshopProductRecord, err = workshopProductRecordRepository.Save(workshopProductRecord); err != nil { | 317 | if workshopProductRecord, err = workshopProductRecordRepository.Save(workshopProductRecord); err != nil { |
318 | // TODO:异常处理 | 318 | // TODO:异常处理 |
@@ -321,8 +321,8 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain. | @@ -321,8 +321,8 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain. | ||
321 | return nil, nil | 321 | return nil, nil |
322 | } | 322 | } |
323 | 323 | ||
324 | -// newEmployeeProductRecord 员工生产记录 | ||
325 | -func newWorkshopProductRecord(productRecord *domain.ProductRecord, productPlan *domain.ProductPlan) *domain.WorkshopProductRecord { | 324 | +// NewWorkshopProductRecord 车间生产记录 |
325 | +func NewWorkshopProductRecord(productRecord *domain.ProductRecord, productPlan *domain.ProductPlan) *domain.WorkshopProductRecord { | ||
326 | record := &domain.WorkshopProductRecord{ | 326 | record := &domain.WorkshopProductRecord{ |
327 | CompanyId: productRecord.CompanyId, | 327 | CompanyId: productRecord.CompanyId, |
328 | OrgId: productRecord.OrgId, | 328 | OrgId: productRecord.OrgId, |
@@ -347,7 +347,7 @@ func newWorkshopProductRecord(productRecord *domain.ProductRecord, productPlan * | @@ -347,7 +347,7 @@ func newWorkshopProductRecord(productRecord *domain.ProductRecord, productPlan * | ||
347 | } | 347 | } |
348 | // 打料、成型有初始值 | 348 | // 打料、成型有初始值 |
349 | if productRecord.WorkStation.SectionName == ProductSection1 || productRecord.WorkStation.SectionName == ProductSection2 { | 349 | if productRecord.WorkStation.SectionName == ProductSection1 || productRecord.WorkStation.SectionName == ProductSection2 { |
350 | - record.ProductWeigh = productPlan.PlanDevoted.Weight | 350 | + record.AddPlanProductWeight(productPlan.PlanDevoted.Weight, productPlan.ProductPlanId) |
351 | } | 351 | } |
352 | return record | 352 | return record |
353 | } | 353 | } |
@@ -78,7 +78,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | @@ -78,7 +78,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d | ||
78 | // 封箱机、串串机需要定位到批次 | 78 | // 封箱机、串串机需要定位到批次 |
79 | if record.DeviceType == domain.DeviceTypeChuanChuanJi { //record.DeviceType == domain.DeviceTypeFengXiangJi || | 79 | if record.DeviceType == domain.DeviceTypeChuanChuanJi { //record.DeviceType == domain.DeviceTypeFengXiangJi || |
80 | datetime, _ := time.ParseInLocation("2006-01-02", deviceRunningData.Date, time.Local) | 80 | datetime, _ := time.ParseInLocation("2006-01-02", deviceRunningData.Date, time.Local) |
81 | - if plan, err = ptr.findDeviceProductPlan(companyId, orgId, workStation.WorkStationId, utils.GetZeroTimeWithLocal(datetime, time.UTC), deviceRunningData.ProductType); err != nil { | 81 | + if plan, err = ptr.findProductPlanAndActive(companyId, orgId, workStation, utils.GetZeroTimeWithLocal(datetime, time.UTC), deviceRunningData.ProductType); err != nil { |
82 | log.Logger.Error(err.Error(), map[string]interface{}{"workstation": workStation, "product_code": deviceRunningData.ProductType}) | 82 | log.Logger.Error(err.Error(), map[string]interface{}{"workstation": workStation, "product_code": deviceRunningData.ProductType}) |
83 | } else { | 83 | } else { |
84 | planId = plan.PlanDispatchRecordExt.ProductPlanId | 84 | planId = plan.PlanDispatchRecordExt.ProductPlanId |
@@ -161,7 +161,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev | @@ -161,7 +161,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev | ||
161 | } | 161 | } |
162 | data.Temp1 = utils.Truncate(deviceYouZhaJi.FrontTemp, 1) | 162 | data.Temp1 = utils.Truncate(deviceYouZhaJi.FrontTemp, 1) |
163 | data.Temp2 = utils.Truncate(deviceYouZhaJi.BackTemp, 1) | 163 | data.Temp2 = utils.Truncate(deviceYouZhaJi.BackTemp, 1) |
164 | - data.Alarm = deviceYouZhaJi.Alarm | 164 | + //data.Alarm = deviceYouZhaJi.Alarm |
165 | } else { | 165 | } else { |
166 | deviceYouZhaJi := &domain.DeviceYouZhaJi2{} | 166 | deviceYouZhaJi := &domain.DeviceYouZhaJi2{} |
167 | err = json.Unmarshal(mBytes, deviceYouZhaJi) | 167 | err = json.Unmarshal(mBytes, deviceYouZhaJi) |
@@ -170,7 +170,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev | @@ -170,7 +170,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev | ||
170 | } | 170 | } |
171 | data.Temp1 = utils.Truncate(deviceYouZhaJi.Temp1, 1) | 171 | data.Temp1 = utils.Truncate(deviceYouZhaJi.Temp1, 1) |
172 | data.Temp2 = utils.Truncate(deviceYouZhaJi.Temp2, 1) | 172 | data.Temp2 = utils.Truncate(deviceYouZhaJi.Temp2, 1) |
173 | - data.Alarm = deviceYouZhaJi.Alarm | 173 | + //data.Alarm = deviceYouZhaJi.Alarm |
174 | } | 174 | } |
175 | break | 175 | break |
176 | //串串机 | 176 | //串串机 |
@@ -326,20 +326,29 @@ func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId, | @@ -326,20 +326,29 @@ func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId, | ||
326 | } | 326 | } |
327 | 327 | ||
328 | // 查找设备的生产计划,如果计划没有上线的话将他上线 | 328 | // 查找设备的生产计划,如果计划没有上线的话将他上线 |
329 | -func (ptr *PGWorkshopDataConsumeService) findDeviceProductPlan(companyId, orgId int, workStationId string, date time.Time, productCode string) (*domain.ProductPlanDispatchRecord, error) { | 329 | +func (ptr *PGWorkshopDataConsumeService) findProductPlanAndActive(companyId, orgId int, workStation *domain.WorkStation, date time.Time, productCode string) (*domain.ProductPlanDispatchRecord, error) { |
330 | planDispatchRecordDao, _ := dao.NewProductPlanDispatchRecord(ptr.transactionContext) | 330 | planDispatchRecordDao, _ := dao.NewProductPlanDispatchRecord(ptr.transactionContext) |
331 | planDispatchRecordRepository, _ := repository.NewProductPlanDispatchRecordRepository(ptr.transactionContext) | 331 | planDispatchRecordRepository, _ := repository.NewProductPlanDispatchRecordRepository(ptr.transactionContext) |
332 | - var setPlanOnline = false | ||
333 | - record, err := planDispatchRecordDao.DeviceProductPlan(companyId, orgId, workStationId, date, productCode, domain.PlanOnline) | 332 | + record, err := planDispatchRecordDao.ProductPlanDispatchRecord(companyId, orgId, workStation.WorkStationId, date, productCode, 0) |
333 | + // 未找到当前工段的调度计划,从计划管理查询是否有匹配记录,如果有在调度计划中上线 | ||
334 | + var productPlan *domain.ProductPlan | ||
334 | if err == domain.ErrorNotFound { | 335 | if err == domain.ErrorNotFound { |
335 | - if record, err = planDispatchRecordDao.DeviceProductPlan(companyId, orgId, workStationId, date, productCode, domain.PlanOffline); err != nil { | ||
336 | - return nil, err | ||
337 | - } else { | ||
338 | - setPlanOnline = true | 336 | + if productPlan, err = planDispatchRecordDao.ProductPlan(companyId, orgId, workStation.WorkshopId, date, productCode); err == nil && productPlan != nil { |
337 | + var productPlanDispatch = domain.NewProductPlanDispatchRecord(productPlan, workStation) | ||
338 | + if productPlanDispatch, err = planDispatchRecordRepository.Save(productPlanDispatch); err != nil { | ||
339 | + return nil, err | ||
340 | + } | ||
341 | + return productPlanDispatch, nil | ||
339 | } | 342 | } |
343 | + return nil, err | ||
340 | } | 344 | } |
341 | - if setPlanOnline { | ||
342 | - record.ChangeStatus(domain.PlanOnline) | 345 | + if err != nil { |
346 | + return nil, err | ||
347 | + } | ||
348 | + if record != nil && record.PlanDispatchStatus == domain.PlanOffline { | ||
349 | + if err = record.ChangeStatus(domain.PlanOnline); err != nil { | ||
350 | + return nil, err | ||
351 | + } | ||
343 | if record, err = planDispatchRecordRepository.Save(record); err != nil { | 352 | if record, err = planDispatchRecordRepository.Save(record); err != nil { |
344 | return nil, err | 353 | return nil, err |
345 | } | 354 | } |
@@ -6,6 +6,17 @@ import ( | @@ -6,6 +6,17 @@ import ( | ||
6 | ) | 6 | ) |
7 | 7 | ||
8 | func TransformToDeviceCollectionDomainModelFromPgModels(deviceCollectionModel *models.DeviceCollection) (*domain.DeviceCollection, error) { | 8 | func TransformToDeviceCollectionDomainModelFromPgModels(deviceCollectionModel *models.DeviceCollection) (*domain.DeviceCollection, error) { |
9 | + if deviceCollectionModel.DeviceType == domain.DeviceTypeYouZhaJi { | ||
10 | + if tmp, ok := deviceCollectionModel.Values["Temp1"]; ok { | ||
11 | + deviceCollectionModel.Values["FrontTemp"] = tmp | ||
12 | + } | ||
13 | + if tmp, ok := deviceCollectionModel.Values["Temp2"]; ok { | ||
14 | + deviceCollectionModel.Values["TankTemp"] = tmp | ||
15 | + } | ||
16 | + if tmp, ok := deviceCollectionModel.Values["Temp3"]; ok { | ||
17 | + deviceCollectionModel.Values["BackTemp"] = tmp | ||
18 | + } | ||
19 | + } | ||
9 | return &domain.DeviceCollection{ | 20 | return &domain.DeviceCollection{ |
10 | DeviceCollectionId: deviceCollectionModel.DeviceCollectionId, | 21 | DeviceCollectionId: deviceCollectionModel.DeviceCollectionId, |
11 | WorkShopName: deviceCollectionModel.WorkShopName, | 22 | WorkShopName: deviceCollectionModel.WorkShopName, |
@@ -130,6 +130,7 @@ func (repository *ProductGroupRepository) FindOne(queryOptions map[string]interf | @@ -130,6 +130,7 @@ func (repository *ProductGroupRepository) FindOne(queryOptions map[string]interf | ||
130 | query.SetWhereByQueryOption("work_station->>'workStationId'=?", "workStationId") | 130 | query.SetWhereByQueryOption("work_station->>'workStationId'=?", "workStationId") |
131 | query.SetWhereByQueryOption("work_station->>'workshopId'='?'", "workshopId") | 131 | query.SetWhereByQueryOption("work_station->>'workshopId'='?'", "workshopId") |
132 | query.SetWhereByQueryOption("work_station->>'lineId'='?'", "lineId") | 132 | query.SetWhereByQueryOption("work_station->>'lineId'='?'", "lineId") |
133 | + query.SetWhereByQueryOption("work_station->>'sectionId'='?'", "sectionId") | ||
133 | if v, ok := queryOptions["includeDeleted"]; ok && v.(bool) { | 134 | if v, ok := queryOptions["includeDeleted"]; ok && v.(bool) { |
134 | query.AllWithDeleted() | 135 | query.AllWithDeleted() |
135 | } | 136 | } |
@@ -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 |
@@ -164,7 +164,7 @@ func (repository *ProductMaterialRepository) Find(queryOptions map[string]interf | @@ -164,7 +164,7 @@ func (repository *ProductMaterialRepository) Find(queryOptions map[string]interf | ||
164 | query.Where("material_name like ?", fmt.Sprintf("%%%v%%", v)) | 164 | query.Where("material_name like ?", fmt.Sprintf("%%%v%%", v)) |
165 | } | 165 | } |
166 | if v, ok := queryOptions["materialCategory"]; ok && v != "" { | 166 | if v, ok := queryOptions["materialCategory"]; ok && v != "" { |
167 | - query.Where(fmt.Sprintf(`material_category->>'category' like '%%%v%%'`, v)) | 167 | + query.Where(fmt.Sprintf(`material_category->>'category' = '%v'`, v)) |
168 | } | 168 | } |
169 | if v, ok := queryOptions["materialNumbers"]; ok && len(v.([]string)) > 0 { | 169 | if v, ok := queryOptions["materialNumbers"]; ok && len(v.([]string)) > 0 { |
170 | query.Where("material_number in (?)", pg.In(v)) | 170 | query.Where("material_number in (?)", pg.In(v)) |
@@ -6,6 +6,7 @@ import ( | @@ -6,6 +6,7 @@ import ( | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" |
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform" |
9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
9 | "time" | 10 | "time" |
10 | 11 | ||
11 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | 12 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" |
@@ -147,12 +148,18 @@ func (repository *ProductRecordRepository) Find(queryOptions map[string]interfac | @@ -147,12 +148,18 @@ func (repository *ProductRecordRepository) Find(queryOptions map[string]interfac | ||
147 | query.SetWhereByQueryOption("company_id = ?", "companyId") | 148 | query.SetWhereByQueryOption("company_id = ?", "companyId") |
148 | query.SetWhereByQueryOption("org_id = ?", "orgId") | 149 | query.SetWhereByQueryOption("org_id = ?", "orgId") |
149 | query.SetWhereByQueryOption("product_record_type & ? >0", "productRecordType") | 150 | query.SetWhereByQueryOption("product_record_type & ? >0", "productRecordType") |
151 | + query.SetWhereByQueryOption("work_station->>'workshopId'='?'", "workshopId") | ||
152 | + query.SetWhereByQueryOption("work_station->>'lineId'='?'", "lineId") | ||
153 | + query.SetWhereByQueryOption("work_station->>'sectionId'='?'", "sectionId") | ||
150 | if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 { | 154 | if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 { |
151 | query.Where(`org_id in (?)`, pg.In(v)) | 155 | query.Where(`org_id in (?)`, pg.In(v)) |
152 | } | 156 | } |
153 | if v, ok := queryOptions["userName"]; ok && len(v.(string)) > 0 { | 157 | if v, ok := queryOptions["userName"]; ok && len(v.(string)) > 0 { |
154 | query.Where(fmt.Sprintf(`product_worker->>'userName' like '%%%v%%'`, v)) | 158 | query.Where(fmt.Sprintf(`product_worker->>'userName' like '%%%v%%'`, v)) |
155 | } | 159 | } |
160 | + if v, ok := queryOptions["productWorkerId"]; ok && v.(int) > 0 { | ||
161 | + query.Where(`product_worker->>'userId' = '?'`, v) | ||
162 | + } | ||
156 | if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 { | 163 | if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 { |
157 | query.Where(fmt.Sprintf(`work_station->>'workshopName' like '%%%v%%'`, v)) | 164 | query.Where(fmt.Sprintf(`work_station->>'workshopName' like '%%%v%%'`, v)) |
158 | } | 165 | } |
@@ -180,6 +187,15 @@ func (repository *ProductRecordRepository) Find(queryOptions map[string]interfac | @@ -180,6 +187,15 @@ func (repository *ProductRecordRepository) Find(queryOptions map[string]interfac | ||
180 | if v, ok := queryOptions["productPlanId"]; ok && v.(int) > 0 { | 187 | if v, ok := queryOptions["productPlanId"]; ok && v.(int) > 0 { |
181 | query.Where(fmt.Sprintf(`product_record_info->>'productPlanId' = '%v'`, v)) | 188 | query.Where(fmt.Sprintf(`product_record_info->>'productPlanId' = '%v'`, v)) |
182 | } | 189 | } |
190 | + if v, ok := queryOptions["status"]; ok && v.(int) > 0 { | ||
191 | + query.Where(fmt.Sprintf(`product_record_info->>'approveStatus' = '%v'`, v)) | ||
192 | + } | ||
193 | + if v, ok := queryOptions["inStatus"]; ok && len(v.([]int)) > 0 { | ||
194 | + query.Where(`product_record_info->>'approveStatus' in (?)`, pg.In(utils.ToArrayString(v.([]int)))) | ||
195 | + } | ||
196 | + if v, ok := queryOptions["lastProductRecordId"]; ok && v.(int) > 0 { | ||
197 | + query.Where(`product_record_id < ?`, v) | ||
198 | + } | ||
183 | query.SetOffsetAndLimit(domain.MaxQueryRow) | 199 | query.SetOffsetAndLimit(domain.MaxQueryRow) |
184 | query.SetOrderDirect("product_record_id", "DESC") | 200 | query.SetOrderDirect("product_record_id", "DESC") |
185 | if count, err := query.SelectAndCount(); err != nil { | 201 | if count, err := query.SelectAndCount(); err != nil { |
pkg/infrastructure/utils/config.go
0 → 100644
1 | +package utils | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/core/config" | ||
5 | + "github.com/beego/beego/v2/server/web" | ||
6 | + "os" | ||
7 | + "strconv" | ||
8 | +) | ||
9 | + | ||
10 | +type Configurator interface { | ||
11 | + DefaultString(key string, defaultVal string) string | ||
12 | + DefaultInt(key string, defaultVal int) int | ||
13 | + DefaultInt64(key string, defaultVal int64) int64 | ||
14 | + DefaultBool(key string, defaultVal bool) bool | ||
15 | + DefaultFloat(key string, defaultVal float64) float64 | ||
16 | +} | ||
17 | + | ||
18 | +// EnvConfigurator read config from env param with default value | ||
19 | +type EnvConfigurator struct{} | ||
20 | + | ||
21 | +func (c EnvConfigurator) DefaultString(key string, defaultVal string) string { | ||
22 | + if os.Getenv(key) != "" { | ||
23 | + return os.Getenv(key) | ||
24 | + } | ||
25 | + return defaultVal | ||
26 | +} | ||
27 | +func (c EnvConfigurator) DefaultInt(key string, defaultVal int) int { | ||
28 | + if os.Getenv(key) == "" { | ||
29 | + return defaultVal | ||
30 | + } | ||
31 | + v, err := strconv.Atoi(os.Getenv(key)) | ||
32 | + if err != nil { | ||
33 | + return defaultVal | ||
34 | + } | ||
35 | + return v | ||
36 | +} | ||
37 | +func (c EnvConfigurator) DefaultInt64(key string, defaultVal int64) int64 { | ||
38 | + if os.Getenv(key) == "" { | ||
39 | + return defaultVal | ||
40 | + } | ||
41 | + v, err := strconv.ParseInt(os.Getenv(key), 10, 64) | ||
42 | + if err != nil { | ||
43 | + return defaultVal | ||
44 | + } | ||
45 | + return v | ||
46 | +} | ||
47 | +func (c EnvConfigurator) DefaultBool(key string, defaultVal bool) bool { | ||
48 | + if os.Getenv(key) == "" { | ||
49 | + return defaultVal | ||
50 | + } | ||
51 | + v, err := strconv.ParseBool(os.Getenv(key)) | ||
52 | + if err != nil { | ||
53 | + return defaultVal | ||
54 | + } | ||
55 | + return v | ||
56 | +} | ||
57 | +func (c EnvConfigurator) DefaultFloat(key string, defaultVal float64) float64 { | ||
58 | + if os.Getenv(key) == "" { | ||
59 | + return defaultVal | ||
60 | + } | ||
61 | + v, err := strconv.ParseFloat(os.Getenv(key), 64) | ||
62 | + if err != nil { | ||
63 | + return defaultVal | ||
64 | + } | ||
65 | + return v | ||
66 | +} | ||
67 | + | ||
68 | +// BeegoAppConfigurator read config from beego config file with default value | ||
69 | +type BeegoAppConfigurator struct { | ||
70 | +} | ||
71 | + | ||
72 | +func (c BeegoAppConfigurator) DefaultString(key string, defaultVal string) string { | ||
73 | + return web.AppConfig.DefaultString(key, defaultVal) | ||
74 | +} | ||
75 | +func (c BeegoAppConfigurator) DefaultInt(key string, defaultVal int) int { | ||
76 | + return web.AppConfig.DefaultInt(key, defaultVal) | ||
77 | +} | ||
78 | +func (c BeegoAppConfigurator) DefaultInt64(key string, defaultVal int64) int64 { | ||
79 | + return web.AppConfig.DefaultInt64(key, defaultVal) | ||
80 | +} | ||
81 | +func (c BeegoAppConfigurator) DefaultBool(key string, defaultVal bool) bool { | ||
82 | + return web.AppConfig.DefaultBool(key, defaultVal) | ||
83 | +} | ||
84 | +func (c BeegoAppConfigurator) DefaultFloat(key string, defaultVal float64) float64 { | ||
85 | + return web.AppConfig.DefaultFloat(key, defaultVal) | ||
86 | +} | ||
87 | + | ||
88 | +func NewConfig(adapterName, filename string) Configurator { | ||
89 | + config, err := config.NewConfig(adapterName, filename) | ||
90 | + if err != nil { | ||
91 | + panic(err) | ||
92 | + } | ||
93 | + return config | ||
94 | +} |
pkg/infrastructure/utils/config_test.go
0 → 100644
1 | +package utils | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/stretchr/testify/assert" | ||
5 | + "os" | ||
6 | + "testing" | ||
7 | +) | ||
8 | + | ||
9 | +func TestEnvConfigurator(t *testing.T) { | ||
10 | + os.Setenv("bool", "true") | ||
11 | + os.Setenv("hello", "world") | ||
12 | + os.Setenv("number", "10") | ||
13 | + | ||
14 | + var config Configurator = EnvConfigurator{} | ||
15 | + assert.Equal(t, "world", config.DefaultString("hello", "w")) | ||
16 | + assert.Equal(t, "w", config.DefaultString("unknown", "w")) | ||
17 | + | ||
18 | + assert.Equal(t, true, config.DefaultBool("bool", false)) | ||
19 | + assert.Equal(t, true, config.DefaultBool("unknown", true)) | ||
20 | + | ||
21 | + assert.Equal(t, 10, config.DefaultInt("number", 5)) | ||
22 | + assert.Equal(t, 5, config.DefaultInt("unknown", 5)) | ||
23 | + | ||
24 | + assert.Equal(t, int64(10), config.DefaultInt64("number", 5)) | ||
25 | + assert.Equal(t, int64(5), config.DefaultInt64("unknown", 5)) | ||
26 | + | ||
27 | + assert.Equal(t, float64(10), config.DefaultFloat("number", 5)) | ||
28 | + assert.Equal(t, float64(5), config.DefaultFloat("unknown", 5)) | ||
29 | +} |
@@ -8,7 +8,10 @@ import ( | @@ -8,7 +8,10 @@ import ( | ||
8 | "github.com/bwmarrin/snowflake" | 8 | "github.com/bwmarrin/snowflake" |
9 | jsonlib "github.com/linmadan/egglib-go/utils/json" | 9 | jsonlib "github.com/linmadan/egglib-go/utils/json" |
10 | "github.com/shopspring/decimal" | 10 | "github.com/shopspring/decimal" |
11 | + "golang.org/x/text/encoding/simplifiedchinese" | ||
12 | + "golang.org/x/text/transform" | ||
11 | "io" | 13 | "io" |
14 | + "io/ioutil" | ||
12 | "reflect" | 15 | "reflect" |
13 | "strconv" | 16 | "strconv" |
14 | "strings" | 17 | "strings" |
@@ -422,3 +425,21 @@ func Truncate(value float64, places int32) float64 { | @@ -422,3 +425,21 @@ func Truncate(value float64, places int32) float64 { | ||
422 | rsp, _ := quantity.Float64() | 425 | rsp, _ := quantity.Float64() |
423 | return rsp | 426 | return rsp |
424 | } | 427 | } |
428 | + | ||
429 | +func Utf8ToGbk(s []byte) ([]byte, error) { | ||
430 | + reader := transform.NewReader(bytes.NewReader(s), simplifiedchinese.GBK.NewEncoder()) | ||
431 | + d, e := ioutil.ReadAll(reader) | ||
432 | + if e != nil { | ||
433 | + return nil, e | ||
434 | + } | ||
435 | + return d, nil | ||
436 | +} | ||
437 | + | ||
438 | +func GbkToUtf8(s []byte) ([]byte, error) { | ||
439 | + reader := transform.NewReader(bytes.NewReader(s), simplifiedchinese.GBK.NewDecoder()) | ||
440 | + d, e := ioutil.ReadAll(reader) | ||
441 | + if e != nil { | ||
442 | + return nil, e | ||
443 | + } | ||
444 | + return d, nil | ||
445 | +} |
@@ -3,6 +3,9 @@ package beego | @@ -3,6 +3,9 @@ package beego | ||
3 | import ( | 3 | import ( |
4 | "github.com/beego/beego/v2/server/web" | 4 | "github.com/beego/beego/v2/server/web" |
5 | "github.com/linmadan/egglib-go/web/beego/filters" | 5 | "github.com/linmadan/egglib-go/web/beego/filters" |
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | ||
7 | + "net/http" | ||
8 | + "net/http/pprof" | ||
6 | "os" | 9 | "os" |
7 | "strconv" | 10 | "strconv" |
8 | 11 | ||
@@ -39,6 +42,22 @@ func init() { | @@ -39,6 +42,22 @@ func init() { | ||
39 | web.BConfig.Listen.HTTPSPort = port | 42 | web.BConfig.Listen.HTTPSPort = port |
40 | } | 43 | } |
41 | } | 44 | } |
45 | + | ||
46 | + if constant.PPROF_ON { | ||
47 | + web.Handler("/debug/pprof/", http.HandlerFunc(pprof.Index)) | ||
48 | + web.Handler("/debug/cmdline", http.HandlerFunc(pprof.Cmdline)) | ||
49 | + web.Handler("/debug/profile", http.HandlerFunc(pprof.Profile)) | ||
50 | + web.Handler("/debug/symbol", http.HandlerFunc(pprof.Symbol)) | ||
51 | + web.Handler("/debug/trace", http.HandlerFunc(pprof.Trace)) | ||
52 | + | ||
53 | + web.Handler("/debug/allocs", pprof.Handler("allocs")) | ||
54 | + web.Handler("/debug/block", pprof.Handler("block")) | ||
55 | + web.Handler("/debug/goroutine", pprof.Handler("goroutine")) | ||
56 | + web.Handler("/debug/heap", pprof.Handler("heap")) | ||
57 | + web.Handler("/debug/mutex", pprof.Handler("mutex")) | ||
58 | + web.Handler("/debug/threadcreate", pprof.Handler("threadcreate")) | ||
59 | + } | ||
60 | + | ||
42 | web.BConfig.Listen.HTTPSCertFile = "./config/fjmaimaimai.com_bundle.crt" | 61 | web.BConfig.Listen.HTTPSCertFile = "./config/fjmaimaimai.com_bundle.crt" |
43 | web.BConfig.Listen.HTTPSKeyFile = "./config/fjmaimaimai.com.key" | 62 | web.BConfig.Listen.HTTPSKeyFile = "./config/fjmaimaimai.com.key" |
44 | web.InsertFilter("/*", web.BeforeExec, filters.AllowCors()) | 63 | web.InsertFilter("/*", web.BeforeExec, filters.AllowCors()) |
@@ -154,6 +154,8 @@ func (controller *StatisticsController) TaskHandler() func(ctx *context.Context) | @@ -154,6 +154,8 @@ func (controller *StatisticsController) TaskHandler() func(ctx *context.Context) | ||
154 | Response(ctx, nil, err) | 154 | Response(ctx, nil, err) |
155 | return | 155 | return |
156 | } | 156 | } |
157 | + case "13": | ||
158 | + crontab.AutoInitWorkshopProductRecord(nil) | ||
157 | } | 159 | } |
158 | Response(ctx, nil, nil) | 160 | Response(ctx, nil, nil) |
159 | } | 161 | } |
1 | package controllers | 1 | package controllers |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "fmt" | ||
5 | + "github.com/beego/beego/v2/server/web/context" | ||
4 | "github.com/linmadan/egglib-go/web/beego" | 6 | "github.com/linmadan/egglib-go/web/beego" |
7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/gateway/allied_creation_user" | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" | 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" |
11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | 12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" |
8 | "strings" | 13 | "strings" |
9 | "time" | 14 | "time" |
15 | + "unicode/utf8" | ||
10 | ) | 16 | ) |
11 | 17 | ||
12 | type DeviceZKTecoController struct { | 18 | type DeviceZKTecoController struct { |
@@ -21,7 +27,8 @@ func (controller *DeviceZKTecoController) PostCdata() { | @@ -21,7 +27,8 @@ func (controller *DeviceZKTecoController) PostCdata() { | ||
21 | data := &domain.DeviceZkTeco{ | 27 | data := &domain.DeviceZkTeco{ |
22 | Sn: sn, | 28 | Sn: sn, |
23 | } | 29 | } |
24 | - if len(bodyList) > 2 { | 30 | + table := controller.Ctx.Input.Query("table") |
31 | + if len(bodyList) > 2 && table == "ATTLOG" { | ||
25 | data.UserNo = bodyList[0] | 32 | data.UserNo = bodyList[0] |
26 | //转成时间格式 | 33 | //转成时间格式 |
27 | mTime, err := time.ParseInLocation("2006-01-02 15:04:05", bodyList[1], time.Local) | 34 | mTime, err := time.ParseInLocation("2006-01-02 15:04:05", bodyList[1], time.Local) |
@@ -36,6 +43,7 @@ func (controller *DeviceZKTecoController) PostCdata() { | @@ -36,6 +43,7 @@ func (controller *DeviceZKTecoController) PostCdata() { | ||
36 | log.Logger.Debug(err.Error() + "data:" + bodyList[1]) | 43 | log.Logger.Debug(err.Error() + "data:" + bodyList[1]) |
37 | } | 44 | } |
38 | } | 45 | } |
46 | + RedirectToUserModule(controller.Ctx, false) | ||
39 | controller.Response(data, nil) | 47 | controller.Response(data, nil) |
40 | } | 48 | } |
41 | 49 | ||
@@ -46,9 +54,72 @@ func (controller *DeviceZKTecoController) GetCdata() { | @@ -46,9 +54,72 @@ func (controller *DeviceZKTecoController) GetCdata() { | ||
46 | 54 | ||
47 | func (controller *DeviceZKTecoController) GetRequest() { | 55 | func (controller *DeviceZKTecoController) GetRequest() { |
48 | //controller.Ctx.WriteString("C:11:DATA\tQUERY\tUSERINFO\tPIN=10086") | 56 | //controller.Ctx.WriteString("C:11:DATA\tQUERY\tUSERINFO\tPIN=10086") |
49 | - controller.Ctx.WriteString("OK") | 57 | + //controller.Ctx.WriteString("C:7EceWxtHB6:DATA QUERY USERINFO PIN=3") |
58 | + //controller.Ctx.WriteString("OK") | ||
59 | + RedirectToUserModule(controller.Ctx, true) | ||
50 | } | 60 | } |
51 | 61 | ||
52 | func (controller *DeviceZKTecoController) Ping() { | 62 | func (controller *DeviceZKTecoController) Ping() { |
53 | controller.Ctx.WriteString("OK") | 63 | controller.Ctx.WriteString("OK") |
54 | } | 64 | } |
65 | + | ||
66 | +func RedirectToUserModule(ctx *context.Context, useResult bool) { | ||
67 | + var svr = allied_creation_user.NewHttpLibAlliedCreationUser(constant.ALLIED_CREATION_USER_HOST) | ||
68 | + data := ctx.Input.RequestBody | ||
69 | + uri := ctx.Request.URL.Path | ||
70 | + sn := ctx.Input.Query("SN") | ||
71 | + table := "" | ||
72 | + cmd := uri | ||
73 | + switch uri { | ||
74 | + case "/zkteco/iclock/getrequest": // 获取下行命令 | ||
75 | + cmd = "getrequest" | ||
76 | + case "/zkteco/iclock/cdata": // 上报数据 | ||
77 | + cmd = "cdata" | ||
78 | + table = ctx.Input.Query("table") | ||
79 | + case "/zkteco/iclock/devicecmd": | ||
80 | + cmd = "devicecmd" | ||
81 | + } | ||
82 | + content := string(data) | ||
83 | + if !utf8.Valid(data) { | ||
84 | + utf8Content, _ := utils.GbkToUtf8(data) //ConvertToString(content, "gbk", "utf-8") | ||
85 | + content = string(utf8Content) | ||
86 | + } | ||
87 | + param := allied_creation_user.ReqTerminalReport{ | ||
88 | + TerminalType: "zkteco", | ||
89 | + TerminalId: sn, | ||
90 | + Command: cmd, | ||
91 | + CompanyId: int64(constant.MANUFACTURE_DEFAULT_COMPANYID), | ||
92 | + OrgId: int64(constant.MANUFACTURE_DEFAULT_ORGID), | ||
93 | + Table: table, | ||
94 | + Content: content, | ||
95 | + } | ||
96 | + if !useResult { | ||
97 | + log.Logger.Debug(fmt.Sprintf("命令透传(sn:%v)-命令:%v 命令(内容):%v 成功", sn, cmd, content)) | ||
98 | + go func() { | ||
99 | + defer func() { | ||
100 | + if p := recover(); p != nil { | ||
101 | + log.Logger.Error(fmt.Sprintf("%v", p)) | ||
102 | + } | ||
103 | + }() | ||
104 | + svr.TerminalReport(param) | ||
105 | + }() | ||
106 | + return | ||
107 | + } | ||
108 | + response, err := svr.TerminalReport(param) | ||
109 | + if err != nil { | ||
110 | + log.Logger.Debug(fmt.Sprintf("命令透传(sn:%v)-命令:%v 命令(内容):%v 应答:%v 错误:%v", sn, cmd, string(data), response.Response, err.Error())) | ||
111 | + ctx.WriteString("OK") | ||
112 | + return | ||
113 | + } | ||
114 | + log.Logger.Debug(fmt.Sprintf("命令透传(sn:%v)-命令:%v 命令(内容):%v 应答:%v 成功", sn, cmd, string(data), response.Response)) | ||
115 | + gbkData, _ := utils.Utf8ToGbk([]byte(response.Response)) | ||
116 | + ctx.Output.Header("Content-Type", "text/plain;charset=gbk") | ||
117 | + ack := string(gbkData) | ||
118 | + ctx.WriteString(ack) | ||
119 | +} | ||
120 | + | ||
121 | +func (controller *DeviceZKTecoController) DeviceCmd() { | ||
122 | + //sn := controller.Ctx.Input.Query("SN") | ||
123 | + RedirectToUserModule(controller.Ctx, false) | ||
124 | + controller.Ctx.WriteString("OK") | ||
125 | +} |
@@ -78,3 +78,11 @@ func (controller *ProductCalendarController) SearchProductCalendar() { | @@ -78,3 +78,11 @@ func (controller *ProductCalendarController) SearchProductCalendar() { | ||
78 | total, data, err := productCalendarService.SearchProductCalendar(ParseOperateInfo(controller.BaseController), cmd) | 78 | total, data, err := productCalendarService.SearchProductCalendar(ParseOperateInfo(controller.BaseController), cmd) |
79 | ResponseGrid(controller.BaseController, total, data, err) | 79 | ResponseGrid(controller.BaseController, total, data, err) |
80 | } | 80 | } |
81 | + | ||
82 | +func (controller *ProductCalendarController) GetProductGroupCalendar() { | ||
83 | + productCalendarService := service.NewProductCalendarService(nil) | ||
84 | + cmd := &query.GetProductGroupCalendarQuery{} | ||
85 | + Must(controller.Unmarshal(cmd)) | ||
86 | + data, err := productCalendarService.GetProductGroupCalendar(cmd) | ||
87 | + controller.Response(data, err) | ||
88 | +} |
@@ -48,7 +48,8 @@ func (controller *ProductMaterialGroupController) RemoveProductMaterialGroup() { | @@ -48,7 +48,8 @@ func (controller *ProductMaterialGroupController) RemoveProductMaterialGroup() { | ||
48 | controller.Unmarshal(removeProductMaterialGroupCommand) | 48 | controller.Unmarshal(removeProductMaterialGroupCommand) |
49 | productMaterialGroupId, _ := controller.GetInt(":productMaterialGroupId") | 49 | productMaterialGroupId, _ := controller.GetInt(":productMaterialGroupId") |
50 | removeProductMaterialGroupCommand.ProductMaterialGroupId = productMaterialGroupId | 50 | removeProductMaterialGroupCommand.ProductMaterialGroupId = productMaterialGroupId |
51 | - data, err := productMaterialGroupService.RemoveProductMaterialGroup(removeProductMaterialGroupCommand) | 51 | + operateInfo := ParseOperateInfo(controller.BaseController) |
52 | + data, err := productMaterialGroupService.RemoveProductMaterialGroup(operateInfo, removeProductMaterialGroupCommand) | ||
52 | controller.Response(data, err) | 53 | controller.Response(data, err) |
53 | } | 54 | } |
54 | 55 |
@@ -84,6 +84,26 @@ func (controller *ProductRecordController) SearchProductRecord() { | @@ -84,6 +84,26 @@ func (controller *ProductRecordController) SearchProductRecord() { | ||
84 | ResponseGrid(controller.BaseController, total, data, err) | 84 | ResponseGrid(controller.BaseController, total, data, err) |
85 | } | 85 | } |
86 | 86 | ||
87 | +func (controller *ProductRecordController) History() { | ||
88 | + productPlanService := service.NewProductRecordService(nil) | ||
89 | + cmd := &query.HistoryProductRecordQuery{} | ||
90 | + Must(controller.Unmarshal(cmd)) | ||
91 | + operateInfo := ParseOperateInfo(controller.BaseController) | ||
92 | + //cmd.OrgId = operateInfo.OrgId | ||
93 | + cmd.CompanyId = operateInfo.CompanyId | ||
94 | + cmd.InOrgIds = operateInfo.OrgIds | ||
95 | + total, data, err := productPlanService.HistoryProductRecord(ParseOperateInfo(controller.BaseController), cmd) | ||
96 | + ResponseGrid(controller.BaseController, total, data, err) | ||
97 | +} | ||
98 | + | ||
99 | +func (controller *ProductRecordController) CancelProductRecord() { | ||
100 | + productRecordService := service.NewProductRecordService(nil) | ||
101 | + cmd := &command.CancelProductRecordCommand{} | ||
102 | + controller.Unmarshal(cmd) | ||
103 | + data, err := productRecordService.CancelProductRecord(cmd) | ||
104 | + controller.Response(data, err) | ||
105 | +} | ||
106 | + | ||
87 | func (controller *ProductRecordController) SearchEmployeeProductRecord() { | 107 | func (controller *ProductRecordController) SearchEmployeeProductRecord() { |
88 | productPlanService := service.NewProductRecordService(nil) | 108 | productPlanService := service.NewProductRecordService(nil) |
89 | cmd := &query.SearchEmployeeProductRecordQuery{} | 109 | cmd := &query.SearchEmployeeProductRecordQuery{} |
@@ -86,6 +86,7 @@ func (controller *UnitConversionController) SearchMaterial() { | @@ -86,6 +86,7 @@ func (controller *UnitConversionController) SearchMaterial() { | ||
86 | operateInfo := ParseOperateInfo(controller.BaseController) | 86 | operateInfo := ParseOperateInfo(controller.BaseController) |
87 | cmd.OrgId = operateInfo.OrgId | 87 | cmd.OrgId = operateInfo.OrgId |
88 | cmd.CompanyId = operateInfo.CompanyId | 88 | cmd.CompanyId = operateInfo.CompanyId |
89 | + cmd.IntelligentWeighingFlag = 1 | ||
89 | _, data, err := unitConversionService.SearchMaterial(ParseOperateInfo(controller.BaseController), cmd) | 90 | _, data, err := unitConversionService.SearchMaterial(ParseOperateInfo(controller.BaseController), cmd) |
90 | controller.Response(data, err) | 91 | controller.Response(data, err) |
91 | } | 92 | } |
@@ -21,4 +21,5 @@ func init() { | @@ -21,4 +21,5 @@ func init() { | ||
21 | web.Router("/zkteco/iclock/cdata", &controllers.DeviceZKTecoController{}, "Get:GetCdata") | 21 | web.Router("/zkteco/iclock/cdata", &controllers.DeviceZKTecoController{}, "Get:GetCdata") |
22 | web.Router("/zkteco/iclock/getrequest", &controllers.DeviceZKTecoController{}, "Get:GetRequest") | 22 | web.Router("/zkteco/iclock/getrequest", &controllers.DeviceZKTecoController{}, "Get:GetRequest") |
23 | web.Router("/zkteco/iclock/ping", &controllers.DeviceZKTecoController{}, "Get:Ping") | 23 | web.Router("/zkteco/iclock/ping", &controllers.DeviceZKTecoController{}, "Get:Ping") |
24 | + web.Router("/zkteco/iclock/devicecmd", &controllers.DeviceZKTecoController{}, "Post:DeviceCmd") | ||
24 | } | 25 | } |
@@ -14,4 +14,5 @@ func init() { | @@ -14,4 +14,5 @@ func init() { | ||
14 | web.Router("/product-calendars/", &controllers.ProductCalendarController{}, "Get:ListProductCalendar") | 14 | web.Router("/product-calendars/", &controllers.ProductCalendarController{}, "Get:ListProductCalendar") |
15 | 15 | ||
16 | web.Router("/product-calendars/search", &controllers.ProductCalendarController{}, "Post:SearchProductCalendar") | 16 | web.Router("/product-calendars/search", &controllers.ProductCalendarController{}, "Post:SearchProductCalendar") |
17 | + web.Router("/product-calendars/product-group-calendar", &controllers.ProductCalendarController{}, "Post:GetProductGroupCalendar") | ||
17 | } | 18 | } |
@@ -14,6 +14,8 @@ func init() { | @@ -14,6 +14,8 @@ func init() { | ||
14 | web.Router("/product-records/approve", &controllers.ProductRecordController{}, "Post:ApproveProductRecord") | 14 | web.Router("/product-records/approve", &controllers.ProductRecordController{}, "Post:ApproveProductRecord") |
15 | web.Router("/product-records/search", &controllers.ProductRecordController{}, "Post:SearchProductRecord") | 15 | web.Router("/product-records/search", &controllers.ProductRecordController{}, "Post:SearchProductRecord") |
16 | web.Router("/product-records/second-level-record/search", &controllers.ProductRecordController{}, "Post:SearchProductRecord") | 16 | web.Router("/product-records/second-level-record/search", &controllers.ProductRecordController{}, "Post:SearchProductRecord") |
17 | + web.Router("/product-records/history", &controllers.ProductRecordController{}, "Post:History") | ||
18 | + web.Router("/product-records/cancel", &controllers.ProductRecordController{}, "Post:CancelProductRecord") | ||
17 | web.Router("/product-records/employee-productive/search", &controllers.ProductRecordController{}, "Post:SearchEmployeeProductRecord") | 19 | web.Router("/product-records/employee-productive/search", &controllers.ProductRecordController{}, "Post:SearchEmployeeProductRecord") |
18 | web.Router("/product-records/workshop-productive/search", &controllers.ProductRecordController{}, "Post:SearchWorkshopProductRecord") | 20 | web.Router("/product-records/workshop-productive/search", &controllers.ProductRecordController{}, "Post:SearchWorkshopProductRecord") |
19 | } | 21 | } |
@@ -30,13 +30,14 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { | @@ -30,13 +30,14 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { | ||
30 | } | 30 | } |
31 | if workShop, ok := payload["WorkShop"]; ok { | 31 | if workShop, ok := payload["WorkShop"]; ok { |
32 | 32 | ||
33 | - if t, ok := payload["UpTime"]; ok { | ||
34 | - collectionTime, _ = time.ParseInLocation("2006-01-02 - 15:04:05", t.(string), time.Local) | ||
35 | - } | ||
36 | - if collectionTime.IsZero() { | ||
37 | - log.Logger.Error(fmt.Sprintf("采集时间有误:%v ", collectionTime), map[string]interface{}{"data": message}) | ||
38 | - return | ||
39 | - } | 33 | + //if t, ok := payload["UpTime"]; ok { |
34 | + // collectionTime, _ = time.ParseInLocation("2006-01-02 - 15:04:05", t.(string), time.Local) | ||
35 | + //} | ||
36 | + //if collectionTime.IsZero() { | ||
37 | + // log.Logger.Error(fmt.Sprintf("采集时间有误:%v ", collectionTime), map[string]interface{}{"data": message}) | ||
38 | + // return | ||
39 | + //} | ||
40 | + collectionTime = time.Now() | ||
40 | var mBytes []byte | 41 | var mBytes []byte |
41 | for key, item := range payload { | 42 | for key, item := range payload { |
42 | if key == "WorkShop" || key == "UpTime" { | 43 | if key == "WorkShop" || key == "UpTime" { |
-
请 注册 或 登录 后发表评论