作者 Your Name
正在显示 60 个修改的文件 包含 1336 行增加275 行删除
performance
pkg/constant/kafka_local.go
/.idea
performance.exe
\ No newline at end of file
go.sum
performance.exe
debug.log
\ No newline at end of file
... ...
FROM golang:latest
#FROM 192.168.0.243:5000/mmm/digital-platform:20220831
ENV APP_DIR $GOPATH/src/digital-platform
ENV APP_DIR $GOPATH/src/performance
RUN mkdir -p $APP_DIR
WORKDIR $APP_DIR/
COPY ./pkg pkg
... ... @@ -13,5 +13,5 @@ ENV GO111MODULE on
ENV GOPROXY https://goproxy.io
RUN ["go","mod","tidy"]
RUN ["ls"]
RUN ["go","build","-o","digital-platform"]
ENTRYPOINT ["./digital-platform"]
\ No newline at end of file
RUN ["go","build","-o","performance"]
ENTRYPOINT ["./performance"]
\ No newline at end of file
... ...
2022/11/10 09:28:21.494 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "company" ("id" bigserial, "logo" text, "name" text, "charge_user_ids" jsonb, "status" bigint, "update_at" timestamptz, "create_at" timestamptz, "delete_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 09:28:21.521 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "department" ("id" bigserial, "company_id" bigint, "level" bigint, "name" text, "parent_id" bigint, "charge_user_ids" jsonb, "path" text, "create_at" timestamptz, "update_at" timestamptz, "delete_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 09:28:21.548 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "user" ("id" bigserial, "account" text, "avatar_url" text, "company_id" bigint, "admin_type" bigint, "name" text, "email" text, "status" bigint, "department_id" jsonb, "update_at" timestamptz, "create_at" timestamptz, "delete_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 09:28:21.575 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "received_message" ("message_id" bigserial, "message_type" text, "message_body" text, "occurred_on" timestamptz, "create_at" timestamptz, PRIMARY KEY ("message_id")) null
2022/11/10 09:28:21.602 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "role" ("id" bigserial, "name" text, "type" bigint, "description" text, "company_id" bigint, "created_at" timestamptz, "updated_at" timestamptz, "deleted_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 09:28:21.630 [D] [hook.go:130] performance COMMENT ON TABLE public."role" IS '角色'; null
2022/11/10 09:28:21.659 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".id IS 'ID'; null
2022/11/10 09:28:21.688 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".name IS '角色名称'; null
2022/11/10 09:28:21.716 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".type IS '角色类型(0角色可删、1系统预置角色不可删)'; null
2022/11/10 09:28:21.743 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".description IS '角色描述'; null
2022/11/10 09:28:21.771 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".company_id IS '公司ID'; null
2022/11/10 09:28:21.799 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".created_at IS '创建时间'; null
2022/11/10 09:28:21.828 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".updated_at IS '更新时间'; null
2022/11/10 09:28:21.856 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".deleted_at IS '删除时间'; null
2022/11/10 09:28:21.883 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "role_user" ("id" bigserial, "role_id" bigint, "user_id" bigint, "company_id" bigint, "created_at" timestamptz, "updated_at" timestamptz, "deleted_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 09:28:21.911 [D] [hook.go:130] performance COMMENT ON TABLE public."role_user" IS '角色用户关系'; null
2022/11/10 09:28:21.937 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".id IS 'ID'; null
2022/11/10 09:28:21.964 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".role_id IS '角色ID'; null
2022/11/10 09:28:21.993 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".user_id IS '用户ID'; null
2022/11/10 09:28:22.020 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".company_id IS '公司ID'; null
2022/11/10 09:28:22.047 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".created_at IS '创建时间'; null
2022/11/10 09:28:22.075 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".updated_at IS '更新时间'; null
2022/11/10 09:28:22.102 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".deleted_at IS '删除时间'; null
2022/11/10 09:28:22.116 [I] [???:0] performance http server Running on http://:8082
2022/11/10 09:28:22.860 [E] [asm_amd64.s:1594] performance kafka: client has run out of available brokers to talk to (Is your cluster reachable?) []
2022/11/10 09:29:54.845 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "company" ("id" bigserial, "logo" text, "name" text, "charge_user_ids" jsonb, "status" bigint, "update_at" timestamptz, "create_at" timestamptz, "delete_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 09:29:54.873 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "department" ("id" bigserial, "company_id" bigint, "level" bigint, "name" text, "parent_id" bigint, "charge_user_ids" jsonb, "path" text, "create_at" timestamptz, "update_at" timestamptz, "delete_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 09:29:54.899 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "user" ("id" bigserial, "account" text, "avatar_url" text, "company_id" bigint, "admin_type" bigint, "name" text, "email" text, "status" bigint, "department_id" jsonb, "update_at" timestamptz, "create_at" timestamptz, "delete_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 09:29:54.926 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "received_message" ("message_id" bigserial, "message_type" text, "message_body" text, "occurred_on" timestamptz, "create_at" timestamptz, PRIMARY KEY ("message_id")) null
2022/11/10 09:29:54.953 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "role" ("id" bigserial, "name" text, "type" bigint, "description" text, "company_id" bigint, "created_at" timestamptz, "updated_at" timestamptz, "deleted_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 09:29:54.981 [D] [hook.go:130] performance COMMENT ON TABLE public."role" IS '角色'; null
2022/11/10 09:29:55.009 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".id IS 'ID'; null
2022/11/10 09:29:55.037 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".name IS '角色名称'; null
2022/11/10 09:29:55.068 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".type IS '角色类型(0角色可删、1系统预置角色不可删)'; null
2022/11/10 09:29:55.094 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".description IS '角色描述'; null
2022/11/10 09:29:55.121 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".company_id IS '公司ID'; null
2022/11/10 09:29:55.149 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".created_at IS '创建时间'; null
2022/11/10 09:29:55.183 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".updated_at IS '更新时间'; null
2022/11/10 09:29:55.212 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".deleted_at IS '删除时间'; null
2022/11/10 09:29:55.243 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "role_user" ("id" bigserial, "role_id" bigint, "user_id" bigint, "company_id" bigint, "created_at" timestamptz, "updated_at" timestamptz, "deleted_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 09:29:55.270 [D] [hook.go:130] performance COMMENT ON TABLE public."role_user" IS '角色用户关系'; null
2022/11/10 09:29:55.297 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".id IS 'ID'; null
2022/11/10 09:29:55.324 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".role_id IS '角色ID'; null
2022/11/10 09:29:55.351 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".user_id IS '用户ID'; null
2022/11/10 09:29:55.377 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".company_id IS '公司ID'; null
2022/11/10 09:29:55.403 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".created_at IS '创建时间'; null
2022/11/10 09:29:55.430 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".updated_at IS '更新时间'; null
2022/11/10 09:29:55.456 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".deleted_at IS '删除时间'; null
2022/11/10 09:29:55.466 [I] [???:0] performance http server Running on http://:8082
2022/11/10 09:29:56.217 [E] [asm_amd64.s:1594] performance kafka: client has run out of available brokers to talk to (Is your cluster reachable?) []
2022/11/10 09:30:15.476 [D] [router.go:977] performance | 127.0.0.1| 200 | 364.534µs| match| GET  /log r:/log
2022/11/10 09:30:15.546 [D] [router.go:977] performance | 127.0.0.1| 404 | 959.763µs| nomatch| GET  /favicon.ico
2022/11/10 15:07:19.528 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "company" ("id" bigserial, "logo" text, "name" text, "charge_user_ids" jsonb, "status" bigint, "update_at" timestamptz, "create_at" timestamptz, "delete_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 15:07:19.556 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "department" ("id" bigserial, "company_id" bigint, "level" bigint, "name" text, "parent_id" bigint, "charge_user_ids" jsonb, "path" text, "create_at" timestamptz, "update_at" timestamptz, "delete_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 15:07:19.583 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "user" ("id" bigserial, "account" text, "avatar_url" text, "company_id" bigint, "admin_type" bigint, "name" text, "email" text, "status" bigint, "department_id" jsonb, "update_at" timestamptz, "create_at" timestamptz, "delete_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 15:07:19.611 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "received_message" ("message_id" bigserial, "message_type" text, "message_body" text, "occurred_on" timestamptz, "create_at" timestamptz, PRIMARY KEY ("message_id")) null
2022/11/10 15:07:19.638 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "role" ("id" bigserial, "name" text, "type" bigint, "description" text, "company_id" bigint, "created_at" timestamptz, "updated_at" timestamptz, "deleted_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 15:07:19.666 [D] [hook.go:130] performance COMMENT ON TABLE public."role" IS '角色'; null
2022/11/10 15:07:19.695 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".id IS 'ID'; null
2022/11/10 15:07:19.723 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".name IS '角色名称'; null
2022/11/10 15:07:19.750 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".type IS '角色类型(0角色可删、1系统预置角色不可删)'; null
2022/11/10 15:07:19.777 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".description IS '角色描述'; null
2022/11/10 15:07:19.805 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".company_id IS '公司ID'; null
2022/11/10 15:07:19.834 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".created_at IS '创建时间'; null
2022/11/10 15:07:19.861 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".updated_at IS '更新时间'; null
2022/11/10 15:07:19.889 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".deleted_at IS '删除时间'; null
2022/11/10 15:07:19.916 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "role_user" ("id" bigserial, "role_id" bigint, "user_id" bigint, "company_id" bigint, "created_at" timestamptz, "updated_at" timestamptz, "deleted_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 15:07:19.944 [D] [hook.go:130] performance COMMENT ON TABLE public."role_user" IS '角色用户关系'; null
2022/11/10 15:07:19.971 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".id IS 'ID'; null
2022/11/10 15:07:19.998 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".role_id IS '角色ID'; null
2022/11/10 15:07:20.026 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".user_id IS '用户ID'; null
2022/11/10 15:07:20.054 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".company_id IS '公司ID'; null
2022/11/10 15:07:20.081 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".created_at IS '创建时间'; null
2022/11/10 15:07:20.109 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".updated_at IS '更新时间'; null
2022/11/10 15:07:20.136 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".deleted_at IS '删除时间'; null
2022/11/10 15:07:20.221 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "positions" ("id" bigserial, "company_id" bigint, "name" text, "parent_id" bigint, "path" text, "level" bigint, "remarks" text, "created_at" timestamptz, "updated_at" timestamptz, "deleted_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 15:07:20.257 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "user_positions" ("id" bigserial, "company_id" bigint, "position_id" bigint, "user_id" bigint, "created_at" timestamptz, "updated_at" timestamptz, "deleted_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 15:07:20.272 [I] [???:0] performance http server Running on http://:8082
2022/11/10 15:07:21.024 [E] [asm_amd64.s:1594] performance kafka: client has run out of available brokers to talk to (Is your cluster reachable?) []
2022/11/10 15:58:14.817 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "company" ("id" bigserial, "logo" text, "name" text, "charge_user_ids" jsonb, "status" bigint, "update_at" timestamptz, "create_at" timestamptz, "delete_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 15:58:14.843 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "department" ("id" bigserial, "company_id" bigint, "level" bigint, "name" text, "parent_id" bigint, "charge_user_ids" jsonb, "path" text, "create_at" timestamptz, "update_at" timestamptz, "delete_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 15:58:14.870 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "user" ("id" bigserial, "account" text, "avatar_url" text, "company_id" bigint, "admin_type" bigint, "name" text, "email" text, "status" bigint, "department_id" jsonb, "position_id" jsonb, "update_at" timestamptz, "create_at" timestamptz, "delete_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 15:58:14.897 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "received_message" ("message_id" bigserial, "message_type" text, "message_body" text, "occurred_on" timestamptz, "create_at" timestamptz, PRIMARY KEY ("message_id")) null
2022/11/10 15:58:14.924 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "role" ("id" bigserial, "name" text, "type" bigint, "description" text, "company_id" bigint, "created_at" timestamptz, "updated_at" timestamptz, "deleted_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 15:58:14.952 [D] [hook.go:130] performance COMMENT ON TABLE public."role" IS '角色'; null
2022/11/10 15:58:14.979 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".id IS 'ID'; null
2022/11/10 15:58:15.006 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".name IS '角色名称'; null
2022/11/10 15:58:15.033 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".type IS '角色类型(0角色可删、1系统预置角色不可删)'; null
2022/11/10 15:58:15.060 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".description IS '角色描述'; null
2022/11/10 15:58:15.087 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".company_id IS '公司ID'; null
2022/11/10 15:58:15.114 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".created_at IS '创建时间'; null
2022/11/10 15:58:15.141 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".updated_at IS '更新时间'; null
2022/11/10 15:58:15.168 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".deleted_at IS '删除时间'; null
2022/11/10 15:58:15.194 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "role_user" ("id" bigserial, "role_id" bigint, "user_id" bigint, "company_id" bigint, "created_at" timestamptz, "updated_at" timestamptz, "deleted_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 15:58:15.222 [D] [hook.go:130] performance COMMENT ON TABLE public."role_user" IS '角色用户关系'; null
2022/11/10 15:58:15.249 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".id IS 'ID'; null
2022/11/10 15:58:15.275 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".role_id IS '角色ID'; null
2022/11/10 15:58:15.302 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".user_id IS '用户ID'; null
2022/11/10 15:58:15.329 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".company_id IS '公司ID'; null
2022/11/10 15:58:15.356 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".created_at IS '创建时间'; null
2022/11/10 15:58:15.383 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".updated_at IS '更新时间'; null
2022/11/10 15:58:15.409 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".deleted_at IS '删除时间'; null
2022/11/10 15:58:15.435 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "positions" ("id" bigserial, "company_id" bigint, "name" text, "parent_id" bigint, "path" text, "level" bigint, "remarks" text, "created_at" timestamptz, "updated_at" timestamptz, "deleted_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 15:58:15.450 [I] [???:0] performance http server Running on http://:8082
2022/11/10 15:58:16.194 [E] [asm_amd64.s:1594] performance kafka: client has run out of available brokers to talk to (Is your cluster reachable?) []
2022/11/10 16:16:09.220 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "company" ("id" bigserial, "logo" text, "name" text, "charge_user_ids" jsonb, "status" bigint, "update_at" timestamptz, "create_at" timestamptz, "delete_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 16:16:09.247 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "department" ("id" bigserial, "company_id" bigint, "level" bigint, "name" text, "parent_id" bigint, "charge_user_ids" jsonb, "path" text, "create_at" timestamptz, "update_at" timestamptz, "delete_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 16:16:09.274 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "user" ("id" bigserial, "account" text, "avatar_url" text, "company_id" bigint, "admin_type" bigint, "name" text, "email" text, "status" bigint, "department_id" jsonb, "position_id" jsonb, "update_at" timestamptz, "create_at" timestamptz, "delete_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 16:16:09.302 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "received_message" ("message_id" bigserial, "message_type" text, "message_body" text, "occurred_on" timestamptz, "create_at" timestamptz, PRIMARY KEY ("message_id")) null
2022/11/10 16:16:09.330 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "role" ("id" bigserial, "name" text, "type" bigint, "description" text, "company_id" bigint, "created_at" timestamptz, "updated_at" timestamptz, "deleted_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 16:16:09.359 [D] [hook.go:130] performance COMMENT ON TABLE public."role" IS '角色'; null
2022/11/10 16:16:09.386 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".id IS 'ID'; null
2022/11/10 16:16:09.415 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".name IS '角色名称'; null
2022/11/10 16:16:09.442 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".type IS '角色类型(0角色可删、1系统预置角色不可删)'; null
2022/11/10 16:16:09.470 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".description IS '角色描述'; null
2022/11/10 16:16:09.497 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".company_id IS '公司ID'; null
2022/11/10 16:16:09.524 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".created_at IS '创建时间'; null
2022/11/10 16:16:09.553 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".updated_at IS '更新时间'; null
2022/11/10 16:16:09.580 [D] [hook.go:130] performance COMMENT ON COLUMN public."role".deleted_at IS '删除时间'; null
2022/11/10 16:16:09.606 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "role_user" ("id" bigserial, "role_id" bigint, "user_id" bigint, "company_id" bigint, "created_at" timestamptz, "updated_at" timestamptz, "deleted_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 16:16:09.633 [D] [hook.go:130] performance COMMENT ON TABLE public."role_user" IS '角色用户关系'; null
2022/11/10 16:16:09.660 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".id IS 'ID'; null
2022/11/10 16:16:09.687 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".role_id IS '角色ID'; null
2022/11/10 16:16:09.714 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".user_id IS '用户ID'; null
2022/11/10 16:16:09.750 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".company_id IS '公司ID'; null
2022/11/10 16:16:09.776 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".created_at IS '创建时间'; null
2022/11/10 16:16:09.803 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".updated_at IS '更新时间'; null
2022/11/10 16:16:09.831 [D] [hook.go:130] performance COMMENT ON COLUMN public."role_user".deleted_at IS '删除时间'; null
2022/11/10 16:16:09.857 [D] [hook.go:130] performance CREATE TABLE IF NOT EXISTS "positions" ("id" bigserial, "company_id" bigint, "name" text, "parent_id" bigint, "path" text, "level" bigint, "remarks" text, "created_at" timestamptz, "updated_at" timestamptz, "deleted_at" timestamptz, PRIMARY KEY ("id")) null
2022/11/10 16:16:09.873 [I] [???:0] performance http server Running on http://:8082
2022/11/10 16:16:10.621 [E] [asm_amd64.s:1594] performance kafka: client has run out of available brokers to talk to (Is your cluster reachable?) []
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-dev get pods | grep -q sg-local-storage
kubectl -n mmm-suplus-test get pods | grep -q performance-back
if [ "$?" == "1" ];then
kubectl create -f /tmp/local/sg-local-storage/sg-storage.yaml --record
kubectl -n mmm-suplus-dev get svc | grep -q sg-local-storage
kubectl create -f /tmp/test/performance-back/performance-back.yaml --record
kubectl -n mmm-suplus-test get svc | grep -q performance-back
if [ "$?" == "0" ];then
echo "sg-local-storage service install success!"
echo "performance-back service install success!"
else
echo "sg-local-storage service install fail!"
echo "performance-back service install fail!"
fi
kubectl -n mmm-suplus-dev get pods | grep -q sg-local-storage
kubectl -n mmm-suplus-test get pods | grep -q performance-back
if [ "$?" == "0" ];then
echo "sg-local-storage deployment install success!"
echo "performance-back deployment install success!"
else
echo "sg-local-storage deployment install fail!"
echo "performance-back deployment install fail!"
fi
else
kubectl delete -f /tmp/local/sg-local-storage/sg-storage.yaml
kubectl -n mmm-suplus-dev get svc | grep -q sg-local-storage
kubectl delete -f /tmp/test/performance-back/performance-back.yaml
kubectl -n mmm-suplus-test get svc | grep -q performance-back
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-dev get svc | grep -q sg-local-storage
kubectl -n mmm-suplus-test get svc | grep -q performance-back
done
kubectl -n mmm-suplus-dev get pods | grep -q sg-local-storage
kubectl -n mmm-suplus-test get pods | grep -q performance-back
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-dev get pods | grep -q sg-local-storage
kubectl -n mmm-suplus-test get pods | grep -q performance-back
done
kubectl create -f /tmp/local/sg-local-storage/sg-storage.yaml --record
kubectl -n mmm-suplus-dev get svc | grep -q sg-local-storage
kubectl create -f /tmp/test/performance-back/performance-back.yaml --record
kubectl -n mmm-suplus-test get svc | grep -q performance-back
if [ "$?" == "0" ];then
echo "sg-local-storage service update success!"
echo "performance-back service update success!"
else
echo "sg-local-storage service update fail!"
echo "performance-back service update fail!"
fi
kubectl -n mmm-suplus-dev get pods | grep -q sg-local-storage
kubectl -n mmm-suplus-test get pods | grep -q performance-back
if [ "$?" == "0" ];then
echo "sg-local-storage deployment update success!"
echo "performance-back deployment update success!"
else
echo "sg-local-storage deployment update fail!"
echo "performance-back deployment update fail!"
fi
fi
\ No newline at end of file
... ...
apiVersion: v1
kind: Service
metadata:
name: sg-local-storage
namespace: mmm-suplus-dev
name: performance-back
namespace: mmm-suplus-test
labels:
k8s-app: sg-local-storage
k8s-app: performance-back
spec:
ports:
- name: "http"
port: 80
targetPort: 8080
targetPort: 8082
- name: "https"
port: 443
targetPort: 443
selector:
k8s-app: sg-local-storage
k8s-app: performance-back
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: sg-local-storage
namespace: mmm-suplus-dev
name: performance-back
namespace: mmm-suplus-test
labels:
k8s-app: sg-local-storage
k8s-app: performance-back
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: sg-local-storage
k8s-app: performance-back
spec:
affinity:
nodeAffinity:
... ... @@ -46,17 +46,15 @@ spec:
- cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
- cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
containers:
- name: sg-local-storage
image: 192.168.0.243:5000/mmm/sg-storage:local
- name: performance-back
image: 192.168.0.243:5000/mmm/performance-back:dev
imagePullPolicy: Always
ports:
- containerPort: 8080
- containerPort: 8082
- containerPort: 443
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
- mountPath: /go/src/sg-storage/uploads
name: sgstorage-pvc1
env:
- name: LOG_LEVEL
value: "debug"
... ... @@ -67,7 +65,7 @@ spec:
- name: ERROR_BASE_CODE_MULTIPLE
value: "1000"
- name: POSTGRESQL_DB_NAME
value: "sg_storage_local"
value: "performance_test"
- name: ENABLE_HTTPS
value: "true"
- name: POSTGRESQL_USER
... ... @@ -100,9 +98,23 @@ spec:
configMapKeyRef:
name: suplus-config
key: redis.port
- name: KAFKA_HOSTS
valueFrom:
configMapKeyRef:
name: suplus-config
key: kafka.host
- name: KAFKA_PERFORMANCE_ID
valueFrom:
configMapKeyRef:
name: suplus-config
key: kafkaperformance.id
- name: KAFKA_BUSINESS_TOPIC
value: "mmm_business_test"
- name: UCENTER_SERVICE_HOST
value: "https://suplus-ucenter-test.fjmaimaimai.com"
- name: BUSINESS_ADMIN_SERVICE_HOST
value: "https://suplus-business-admin-test.fjmaimaimai.com"
volumes:
- name: accesslogs
emptyDir: {}
- name: sgstorage-pvc1
persistentVolumeClaim:
claimName: sgstorage-pvc
\ No newline at end of file
\ No newline at end of file
... ...
... ... @@ -6,6 +6,7 @@ require (
github.com/Shopify/sarama v1.25.0
github.com/beego/beego/v2 v2.0.5
github.com/bwmarrin/snowflake v0.3.0
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/go-pg/pg/v10 v10.10.7
github.com/linmadan/egglib-go v0.0.0-20210827085852-177fa745932d
)
... ...
... ... @@ -111,6 +111,7 @@ github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGii
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
... ...
不能预览此文件类型
package command
type LoginCommand struct {
Code string `json:"code" valid:"Required"` //授权code
PlatformId int `json:"platformId" valid:"Required"` //登录平台ID,28-绩效管理后台 29-员工绩效
}
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/auth/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type AuthService struct {
}
// Login PC端登录
func (service *AuthService) Login(loginCommand *command.LoginCommand) (interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if errStart := transactionContext.StartTransaction(); errStart != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, errStart.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
//统一用户中心登录
authCodeReply, err := factory.UCenterApi().AuthCode(loginCommand.Code)
if err != nil || !authCodeReply.IsOk() {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统一用户中心认证失败")
}
//用户权限校验
userAuthReply, err := factory.BusinessAdminApi().GetUserAuth(authCodeReply.Data.MUid, loginCommand.PlatformId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户鉴权失败")
}
if !userAuthReply.IsOk() {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, userAuthReply.Message())
}
//获取公司数据
companyRepository := factory.CreateCompanyRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
company, err := companyRepository.FindOne(map[string]interface{}{
"id": authCodeReply.Data.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司数据失败")
}
userRepository := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
user, err := userRepository.FindOne(map[string]interface{}{
"id": authCodeReply.Data.MUid,
"companyId": company.Id,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司数据失败")
}
if user.Status != domain.UserStatusEnable {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户被禁用")
}
userAuth := &domain.UserAuth{
UserId: user.Id,
CompanyId: user.CompanyId,
Phone: user.Account,
PlatformId: loginCommand.PlatformId,
Name: user.Name,
AdminType: user.AdminType,
}
accessToken, err := userAuth.CreateAccessToken()
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"access": map[string]interface{}{
"accessToken": accessToken,
"expiresIn": domain.JWTExpiresSecond,
},
}, nil
}
... ...
package service
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"testing"
)
func TestAdminToken(t *testing.T) {
domain.JWTExpiresSecond = 3600 * 24 * 365
userAuth := &domain.UserAuth{
UserId: 3325567738895360,
CompanyId: 507,
Phone: "18559023318",
PlatformId: 28,
Name: "庄敏学",
AdminType: 2,
}
fmt.Println(userAuth.CreateAccessToken())
}
func TestFontToken(t *testing.T) {
domain.JWTExpiresSecond = 3600 * 24 * 365
userAuth := &domain.UserAuth{
UserId: 3325567738895360,
CompanyId: 507,
Phone: "18559023318",
PlatformId: 29,
Name: "庄敏学",
AdminType: 2,
}
fmt.Println(userAuth.CreateAccessToken())
}
... ...
package command
//AddCompanyCommand 数据来源 企业平台 推送的消息
//新建公司
// AddCompanyCommand 数据来源 企业平台 推送的消息
// 新建公司
type SaveCompanyCommand struct {
//新添加的公司
Comapany struct {
Company struct {
Id int64 `json:"id" `
Logo string `json:"logo"` // 公司logo
Name string `json:"name"` // 公司名称
... ...
... ... @@ -20,38 +20,38 @@ type SyncDataCompanyService struct {
// // add:添加,edit:编辑,setCompanyCharge:更改公司主管,changeAdmin换管理员
// Action string `json:"action"`
// // 具体的对象JSON数据
// Datas json.RawMessage `json:"data"`
// Data json.RawMessage `json:"data"`
// }
//从BusinessAdmins 接收消息,变更公司数据
// 从BusinessAdmins 接收消息,变更公司数据
func (c SyncDataCompanyService) FromBusinessAdmin(param *domain.MessageBody) error {
action := param.Module + "/" + param.Action
var err error
switch action {
case "company/add":
var param1 command.SaveCompanyCommand
err = json.Unmarshal(param.Datas, &param1)
err = json.Unmarshal(param.Data, &param1)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = c.addCompany(&param1)
case "company/edit":
var param2 command.SaveCompanyCommand
err = json.Unmarshal(param.Datas, &param2)
err = json.Unmarshal(param.Data, &param2)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = c.editCompany(&param2)
case "company/setCompanyCharge":
var param3 command.SetCompanyCharge
err = json.Unmarshal(param.Datas, &param3)
err = json.Unmarshal(param.Data, &param3)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = c.setCompanyCharge(&param3)
case "company/changeAdmin":
var param3 command.ChangeAdminCommand
err = json.Unmarshal(param.Datas, &param3)
err = json.Unmarshal(param.Data, &param3)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -63,9 +63,9 @@ func (c SyncDataCompanyService) FromBusinessAdmin(param *domain.MessageBody) err
return err
}
//addCompany
//从BusinessAdmins 接收消息 添加公司
//module="company" action="add"
// addCompany
// 从BusinessAdmins 接收消息 添加公司
// module="company" action="add"
func (c SyncDataCompanyService) addCompany(param *command.SaveCompanyCommand) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -79,14 +79,14 @@ func (c SyncDataCompanyService) addCompany(param *command.SaveCompanyCommand) er
}()
nowTime := time.Now()
newCompany := domain.Company{
Id: param.Comapany.Id,
Logo: param.Comapany.Logo,
Name: param.Comapany.Name,
Status: param.Comapany.Status,
UpdateAt: nowTime,
CreateAt: nowTime,
Id: param.Company.Id,
Logo: param.Company.Logo,
Name: param.Company.Name,
Status: param.Company.Status,
UpdatedAt: nowTime,
CreatedAt: nowTime,
ChargeUserIds: []int64{},
DeleteAt: nil,
DeletedAt: nil,
}
newUser := domain.User{
... ... @@ -97,9 +97,9 @@ func (c SyncDataCompanyService) addCompany(param *command.SaveCompanyCommand) er
AdminType: param.User.AdminType,
Name: param.User.Name,
Status: param.User.Status,
UpdateAt: nowTime,
DeleteAt: nil,
CreateAt: nowTime,
UpdatedAt: nowTime,
DeletedAt: nil,
CreatedAt: nowTime,
}
companyRepo := factory.CreateCompanyRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -121,9 +121,9 @@ func (c SyncDataCompanyService) addCompany(param *command.SaveCompanyCommand) er
return nil
}
//editCompany
//从BusinessAdmins 接收消息 更新公司
//module="company" action="edit"
// editCompany
// 从BusinessAdmins 接收消息 更新公司
// module="company" action="edit"
func (c SyncDataCompanyService) editCompany(param *command.SaveCompanyCommand) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -144,7 +144,7 @@ func (c SyncDataCompanyService) editCompany(param *command.SaveCompanyCommand) e
_, companyList, err := companyRepo.Find(map[string]interface{}{
"limit": 1,
"id": param.Comapany.Id,
"id": param.Company.Id,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -165,22 +165,22 @@ func (c SyncDataCompanyService) editCompany(param *command.SaveCompanyCommand) e
newCompany = companyList[0]
} else {
newCompany = &domain.Company{
CreateAt: nowTime,
CreatedAt: nowTime,
}
}
if len(userList) > 0 {
newUser = userList[0]
} else {
newUser = &domain.User{
CreateAt: nowTime,
CreatedAt: nowTime,
}
}
newCompany.Id = param.Comapany.Id
newCompany.Logo = param.Comapany.Logo
newCompany.Name = param.Comapany.Name
newCompany.Status = param.Comapany.Status
newCompany.UpdateAt = nowTime
newCompany.Id = param.Company.Id
newCompany.Logo = param.Company.Logo
newCompany.Name = param.Company.Name
newCompany.Status = param.Company.Status
newCompany.UpdatedAt = nowTime
newUser.Id = param.User.Id
newUser.Account = param.User.Phone
... ... @@ -189,7 +189,7 @@ func (c SyncDataCompanyService) editCompany(param *command.SaveCompanyCommand) e
newUser.AdminType = param.User.AdminType
newUser.Name = param.User.Name
newUser.Status = param.User.Status
newUser.UpdateAt = nowTime
newUser.UpdatedAt = nowTime
if len(companyList) > 0 {
_, err = companyRepo.Update(newCompany)
if err != nil {
... ... @@ -218,7 +218,7 @@ func (c SyncDataCompanyService) editCompany(param *command.SaveCompanyCommand) e
return nil
}
//module="company" action="setCompanyCharge"
// module="company" action="setCompanyCharge"
func (srv SyncDataCompanyService) setCompanyCharge(param *command.SetCompanyCharge) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -245,7 +245,7 @@ func (srv SyncDataCompanyService) setCompanyCharge(param *command.SetCompanyChar
}
for i := range companyList {
companyList[i].ChargeUserIds = param.ChargeUserIds
companyList[i].UpdateAt = time.Now()
companyList[i].UpdatedAt = time.Now()
_, err = companyRepo.Update(companyList[i])
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -257,9 +257,9 @@ func (srv SyncDataCompanyService) setCompanyCharge(param *command.SetCompanyChar
return nil
}
//changeAdmin
//从BusinessAdmins 接收消息 变更主管
//module="company" action="changeAdmin"
// changeAdmin
// 从BusinessAdmins 接收消息 变更主管
// module="company" action="changeAdmin"
func (srv SyncDataCompanyService) changeAdmin(param *command.ChangeAdminCommand) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -287,7 +287,7 @@ func (srv SyncDataCompanyService) changeAdmin(param *command.ChangeAdminCommand)
//修改旧管理员 为普通用户
for i := range userList {
userList[i].AdminType = domain.UserTypeCommon
userList[i].UpdateAt = time.Now()
userList[i].UpdatedAt = time.Now()
_, err := userRepo.Update(userList[i])
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -305,7 +305,7 @@ func (srv SyncDataCompanyService) changeAdmin(param *command.ChangeAdminCommand)
//修改为管理员用户
for i := range userList2 {
userList[i].AdminType = domain.UserTypeManager
userList[i].UpdateAt = time.Now()
userList[i].UpdatedAt = time.Now()
_, err := userRepo.Update(userList[i])
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
... ... @@ -18,7 +18,7 @@ type SyncDataDepartmentService struct{}
// // add:添加,edit:编辑,batchDelete:批量删除,import:导入部门
// Action string `json:"action"`
// // 具体的对象JSON数据
// Datas json.RawMessage `json:"data"`
// Data json.RawMessage `json:"data"`
// }
func (srv SyncDataDepartmentService) FromBusinessAdmin(param *domain.MessageBody) error {
... ... @@ -27,28 +27,28 @@ func (srv SyncDataDepartmentService) FromBusinessAdmin(param *domain.MessageBody
switch action {
case "department/add":
var param1 command.AddDepartmentCommand
err = json.Unmarshal(param.Datas, &param1)
err = json.Unmarshal(param.Data, &param1)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = srv.addDepartment(&param1)
case "department/edit":
var param1 command.EditDepartmentCommand
err = json.Unmarshal(param.Datas, &param1)
err = json.Unmarshal(param.Data, &param1)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = srv.editDepartment(&param1)
case "department/batchDelete":
var param1 command.BatchDeleteCommand
err = json.Unmarshal(param.Datas, &param1)
err = json.Unmarshal(param.Data, &param1)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = srv.batchDeleteDepartment(&param1)
case "department/import":
var param1 []command.ImportDepartmentCommand
err = json.Unmarshal(param.Datas, &param1)
err = json.Unmarshal(param.Data, &param1)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -57,9 +57,9 @@ func (srv SyncDataDepartmentService) FromBusinessAdmin(param *domain.MessageBody
return err
}
//AddDepartment
//从BusinessAdmins 接收消息 添加部门
//module="department" action="add"
// AddDepartment
// 从BusinessAdmins 接收消息 添加部门
// module="department" action="add"
func (srv SyncDataDepartmentService) addDepartment(param *command.AddDepartmentCommand) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -81,9 +81,9 @@ func (srv SyncDataDepartmentService) addDepartment(param *command.AddDepartmentC
ParentId: param.ParentId,
ChargeUserIds: param.ChargeUserIds,
Path: param.Path,
CreateAt: nowTime,
UpdateAt: nowTime,
DeleteAt: nil,
CreatedAt: nowTime,
UpdatedAt: nowTime,
DeletedAt: nil,
}
departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
... ... @@ -99,9 +99,9 @@ func (srv SyncDataDepartmentService) addDepartment(param *command.AddDepartmentC
return nil
}
//EditDepartment
//从BusinessAdmins 接收消息 编辑部门
//module="department" action="edit"
// EditDepartment
// 从BusinessAdmins 接收消息 编辑部门
// module="department" action="edit"
func (srv SyncDataDepartmentService) editDepartment(param *command.EditDepartmentCommand) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -130,11 +130,19 @@ func (srv SyncDataDepartmentService) editDepartment(param *command.EditDepartmen
for i := range departmentList {
if departmentList[i].Id == param.Id {
departmentList[i].CompanyId = param.CompanyId
departmentList[i].Name = param.Name
departmentList[i].Name = param.Path
departmentList[i].ChargeUserIds = param.ChargeUserIds
departmentList[i].Level = param.Level
departmentList[i].ParentId = param.ParentId
if param.Name != "" {
departmentList[i].Name = param.Name
}
if param.Path != "" {
departmentList[i].Path = param.Path
}
if param.Level > 0 {
departmentList[i].Level = param.Level
}
if len(param.ChargeUserIds) > 0 {
departmentList[i].ChargeUserIds = param.ChargeUserIds
}
continue
}
... ... @@ -158,9 +166,9 @@ func (srv SyncDataDepartmentService) editDepartment(param *command.EditDepartmen
return nil
}
//batchDelete
//从BusinessAdmins 接收消息 删除部门
//module="department" action="batchDelete"
// batchDelete
// 从BusinessAdmins 接收消息 删除部门
// module="department" action="batchDelete"
func (srv SyncDataDepartmentService) batchDeleteDepartment(param *command.BatchDeleteCommand) error {
if len(param.Ids) == 0 {
return nil
... ... @@ -188,9 +196,9 @@ func (srv SyncDataDepartmentService) batchDeleteDepartment(param *command.BatchD
return nil
}
//importDepartment
//从BusinessAdmins 接收消息 导入部门数据
//module="department" action="import"
// importDepartment
// 从BusinessAdmins 接收消息 导入部门数据
// module="department" action="import"
func (srv SyncDataDepartmentService) importDepartment(param []command.ImportDepartmentCommand) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -215,9 +223,9 @@ func (srv SyncDataDepartmentService) importDepartment(param []command.ImportDepa
ParentId: param[i].ParentId,
ChargeUserIds: []int64{},
Path: param[i].Path,
CreateAt: nowTime,
UpdateAt: nowTime,
DeleteAt: nil,
CreatedAt: nowTime,
UpdatedAt: nowTime,
DeletedAt: nil,
}
_, err = departmentRepo.Insert(&newDepartment)
if err != nil {
... ...
package factory
import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/serviceGateway"
)
func UCenterApi() domain.UCenterApi {
return serviceGateway.NewHttpLibUCenterApiServiceGateway()
}
func BusinessAdminApi() domain.BusinessAdminApi {
return serviceGateway.NewHttpLibBusinessAdminServiceGateway()
}
... ...
... ... @@ -57,6 +57,14 @@ func CreateDepartmentRepository(options map[string]interface{}) domain.Departmen
return repository.NewDepartmentRepository(transactionContext)
}
func CreatePositionRepository(options map[string]interface{}) domain.PositionRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewPositionRepository(transactionContext)
}
func CreateRoleRepository(options map[string]interface{}) domain.RoleRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
... ...
package command
type BatchDeletePositionCommand struct {
Ids []int64 `json:"ids"`
}
... ...
package command
type SavePositionCommand struct {
//职位ID
Id int64 `json:"id"`
//公司ID
CompanyId int64 `json:"company_id"`
//职位名称
Name string `json:"name"`
//父级职位ID
ParentId int64 `json:"parent_id"`
//职位路径
Path string `json:"path"`
//职位层级
Level int `json:"level"`
}
... ...
package service
import (
"encoding/json"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/position/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type SyncDataPositionService struct{}
func (service SyncDataPositionService) FromBusinessAdmin(param *domain.MessageBody) error {
var err error
switch param.Action {
//新增-编辑职位
case "add", "edit":
createPositionCommand := &command.SavePositionCommand{}
err = json.Unmarshal(param.Data, createPositionCommand)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = service.CreateOrUpdatePosition(createPositionCommand)
//批量删除职位
case "batchDelete":
batchDeletePositionCommand := &command.BatchDeletePositionCommand{}
err = json.Unmarshal(param.Data, batchDeletePositionCommand)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = service.BatchDeletePosition(batchDeletePositionCommand)
}
return err
}
// CreateOrUpdatePosition 新增职位
func (service SyncDataPositionService) CreateOrUpdatePosition(positionCommand *command.SavePositionCommand) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
positionRepository := factory.CreatePositionRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
position := &domain.Position{
Id: positionCommand.Id,
CompanyId: positionCommand.CompanyId,
Name: positionCommand.Name,
ParentId: positionCommand.ParentId,
Path: positionCommand.Path,
Level: positionCommand.Level,
}
pdm, _ := positionRepository.FindOne(map[string]interface{}{"id": position.Id})
if pdm != nil && pdm.Id > 0 {
_, err = positionRepository.Update(position)
} else {
_, err = positionRepository.Insert(position)
}
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil
}
// BatchDeletePosition 批量删除职位
func (service SyncDataPositionService) BatchDeletePosition(batchDeletePositionCommand *command.BatchDeletePositionCommand) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
positionRepository := factory.CreatePositionRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
err = positionRepository.Remove(batchDeletePositionCommand.Ids)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil
}
... ...
... ... @@ -8,7 +8,29 @@ type SaveUserCommand struct {
AdminType int `json:"admin_type"` // 1普通员工 2 主管理员
Name string `json:"name"` // 用户姓名
Status int `json:"status"` // 用户状态(1正常 2禁用)
Email string `json:"email"` // 邮箱
UserDepartments []struct {
DepartmentId int `json:"department_id" `
} `json:"user_departments"` //用户的组织ids
UserPositions []struct {
PositionId int `json:"position_id"`
CompanyId int64 `json:"company_id"`
UserId int64 `json:"user_id"`
} `json:"user_positions"`
}
func (saveUserCommand *SaveUserCommand) DepartmentIds() []int {
ids := make([]int, 0)
for _, v := range saveUserCommand.UserDepartments {
ids = append(ids, v.DepartmentId)
}
return ids
}
func (saveUserCommand *SaveUserCommand) PositionIds() []int {
ids := make([]int, 0)
for _, v := range saveUserCommand.UserPositions {
ids = append(ids, v.PositionId)
}
return ids
}
... ...
... ... @@ -20,7 +20,7 @@ type SyncDataUserService struct{}
// // add:添加,edit:编辑,batchDelete:批量删除,batchForbid:批量禁用用户,batchRemove:批量更改用户部门,import:导入用户
// Action string `json:"action"`
// // 具体的对象JSON数据
// Datas json.RawMessage `json:"data"`
// Data json.RawMessage `json:"data"`
// }
func (srv SyncDataUserService) FromBusinessAdmin(param *domain.MessageBody) error {
... ... @@ -29,35 +29,35 @@ func (srv SyncDataUserService) FromBusinessAdmin(param *domain.MessageBody) erro
switch action {
case "employee/add":
var param1 command.SaveUserCommand
err = json.Unmarshal(param.Datas, &param1)
err = json.Unmarshal(param.Data, &param1)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = srv.AddUser(&param1)
case "employee/edit":
var param2 command.SaveUserCommand
err = json.Unmarshal(param.Datas, &param2)
err = json.Unmarshal(param.Data, &param2)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = srv.UpdateUser(&param2)
case "employee/batchDelete":
var param3 command.BatchDeleteCommand
err = json.Unmarshal(param.Datas, &param3)
err = json.Unmarshal(param.Data, &param3)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = srv.batchDelete(&param3)
case "company/batchForbid":
case "employee/batchForbid":
var param4 command.BatchForbidCommand
err = json.Unmarshal(param.Datas, &param4)
err = json.Unmarshal(param.Data, &param4)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = srv.batchForbid(&param4)
case "company/import":
case "employee/import":
var param4 command.ImportUserCommand
err = json.Unmarshal(param.Datas, &param4)
err = json.Unmarshal(param.Data, &param4)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -69,9 +69,9 @@ func (srv SyncDataUserService) FromBusinessAdmin(param *domain.MessageBody) erro
return err
}
//AddUser
//从BusinessAdmins 接收消息 添加用户
//module="employee" action="add"
// AddUser
// 从BusinessAdmins 接收消息 添加用户
// module="employee" action="add"
func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -83,10 +83,6 @@ func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error {
defer func() {
_ = transactionContext.RollbackTransaction()
}()
var departmentIds []int
for _, v := range param.UserDepartments {
departmentIds = append(departmentIds, v.DepartmentId)
}
nowTime := time.Now()
newUser := domain.User{
Id: param.Id,
... ... @@ -94,12 +90,13 @@ func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error {
AvatarUrl: param.Avatar,
CompanyId: param.CompanyId,
AdminType: param.AdminType,
DepartmentId: departmentIds,
DepartmentId: param.DepartmentIds(),
PositionId: param.PositionIds(),
Name: param.Name,
Email: param.Email,
Status: param.Status,
UpdateAt: nowTime,
DeleteAt: nil,
CreateAt: nowTime,
UpdatedAt: nowTime,
CreatedAt: nowTime,
}
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -114,9 +111,9 @@ func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error {
return nil
}
//UpdateUser
//从BusinessAdmins 接收消息 更新用户
//module="employee" action="edit"
// UpdateUser
// 从BusinessAdmins 接收消息 更新用户
// module="employee" action="edit"
func (srv SyncDataUserService) UpdateUser(param *command.SaveUserCommand) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -146,7 +143,7 @@ func (srv SyncDataUserService) UpdateUser(param *command.SaveUserCommand) error
newUser = userList[0]
} else {
newUser = &domain.User{
CreateAt: nowTime,
CreatedAt: nowTime,
}
}
newUser.Id = param.Id
... ... @@ -156,7 +153,10 @@ func (srv SyncDataUserService) UpdateUser(param *command.SaveUserCommand) error
newUser.AdminType = param.AdminType
newUser.Name = param.Name
newUser.Status = param.Status
newUser.UpdateAt = nowTime
newUser.PositionId = param.PositionIds()
newUser.DepartmentId = param.DepartmentIds()
newUser.UpdatedAt = nowTime
if len(userList) > 0 {
_, err = userRepo.Update(newUser)
if err != nil {
... ... @@ -174,9 +174,9 @@ func (srv SyncDataUserService) UpdateUser(param *command.SaveUserCommand) error
return nil
}
//batchDelete
//从BusinessAdmins 接收消息 删除用户
//module="employee" action="batchDelete"
// batchDelete
// 从BusinessAdmins 接收消息 删除用户
// module="employee" action="batchDelete"
func (srv SyncDataUserService) batchDelete(param *command.BatchDeleteCommand) error {
if len(param.Uids) == 0 {
return nil
... ... @@ -205,9 +205,9 @@ func (srv SyncDataUserService) batchDelete(param *command.BatchDeleteCommand) er
return nil
}
//batchForbid
//从BusinessAdmins 接收消息 禁用,启用用户
//module="employee" action="batchForbid"
// batchForbid
// 从BusinessAdmins 接收消息 禁用,启用用户
// module="employee" action="batchForbid"
func (srv SyncDataUserService) batchForbid(param *command.BatchForbidCommand) error {
if len(param.Uids) == 0 {
return nil
... ... @@ -245,9 +245,9 @@ func (srv SyncDataUserService) batchForbid(param *command.BatchForbidCommand) er
return nil
}
//importUser
//从BusinessAdmins 接收消息 导入用户数据
//module="employee" action="import"
// importUser
// 从BusinessAdmins 接收消息 导入用户数据
// module="employee" action="import"
func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -287,7 +287,7 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro
editUserList[i].Name = mVal.Name
editUserList[i].Status = mVal.Status
editUserList[i].CompanyId = mVal.CompanyId
editUserList[i].UpdateAt = nowTime
editUserList[i].UpdatedAt = nowTime
_, err = userRepo.Update(editUserList[i])
if err != nil {
return err
... ... @@ -305,9 +305,9 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro
AdminType: param.AddUsers[i].AdminType,
Name: param.AddUsers[i].Name,
Status: param.AddUsers[i].Status,
UpdateAt: nowTime,
DeleteAt: nil,
CreateAt: nowTime,
UpdatedAt: nowTime,
DeletedAt: nil,
CreatedAt: nowTime,
}
_, err := userRepo.Insert(&tempUser)
if err != nil {
... ...
package constant
import "os"
// 用户中心地址
var UCENTER_SERVICE_HOST = "http://suplus-ucenter-test.fjmaimaimai.com"
// var UCENTER_HOST = "https://suplus-ucenter-dev.fjmaimaimai.com" //统一用户中心地址
var UCENTER_SECRET = "cykbjnfqgctn"
var UCENTER_APP_KEY = "39aefef9e22744a3b2d2d3791824ae7b"
var UCENTER_CHECK_ALT = "rsF0pL!6DwjBO735"
// 企业平台地址
var BUSINESS_ADMIN_SERVICE_HOST = "http://suplus-business-admin-test.fjmaimaimai.com"
// 绩效管理平台ID
var PLATFORM_ADMIN_ID = 28
// 员工绩效平台ID
var PLATFORM_FONT_ID = 29
func init() {
if os.Getenv("UCENTER_SERVICE_HOST") != "" {
UCENTER_SERVICE_HOST = os.Getenv("UCENTER_SERVICE_HOST")
}
if os.Getenv("BUSINESS_ADMIN_SERVICE_HOST") != "" {
BUSINESS_ADMIN_SERVICE_HOST = os.Getenv("BUSINESS_ADMIN_SERVICE_HOST")
}
}
... ...
//go:build !local
// +build !local
package constant
... ... @@ -8,14 +9,14 @@ var KAFKA_HOSTS = "127.0.0.1:9092" // 1.116.151.79:9092
var KAFKA_GROUP_ID = "performance_dev"
var KAFKA_BUSINESS_ADMIN_TOPIC = "mmm-business-admin-dev"
var KAFKA_BUSINESS_TOPIC = "mmm-business-admin-dev"
func init() {
if os.Getenv("KAFKA_HOSTS") != "" {
KAFKA_HOSTS = os.Getenv("KAFKA_HOSTS")
}
if os.Getenv("KAFKA_BUSINESS_ADMIN_TOPIC") != "" {
KAFKA_BUSINESS_ADMIN_TOPIC = os.Getenv("KAFKA_BUSINESS_ADMIN_TOPIC")
if os.Getenv("KAFKA_BUSINESS_TOPIC") != "" {
KAFKA_BUSINESS_TOPIC = os.Getenv("KAFKA_BUSINESS_TOPIC")
}
if os.Getenv("KAFKA_GROUP_ID") != "" {
KAFKA_GROUP_ID = os.Getenv("KAFKA_GROUP_ID")
... ...
... ... @@ -2,7 +2,7 @@ package constant
import "os"
var POSTGRESQL_DB_NAME = "performance_dev"
var POSTGRESQL_DB_NAME = "performance_test"
var POSTGRESQL_USER = "postgres"
var POSTGRESQL_PASSWORD = "eagle1010"
var POSTGRESQL_HOST = "114.55.200.59"
... ...
package domain
import "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/serviceGateway/reply"
// UCenterApi 统一用户中心
type UCenterApi interface {
AuthCode(code string) (*reply.UCenterAuthCode, error)
}
// BusinessAdminApi 企业平台
type BusinessAdminApi interface {
GetUserAuth(userId int64, platformId int) (*reply.BusinessAdminUserAuth, error)
}
... ...
... ... @@ -3,14 +3,14 @@ package domain
import "time"
type Company struct {
Id int64 //公司编号
Logo string //公司logo
Name string //公司名称
ChargeUserIds []int64 //公司级别的部门主管uids
Status int //公司状态,1正常 2禁用
UpdateAt time.Time //更新时间
CreateAt time.Time //创建时间
DeleteAt *time.Time
Id int64 //公司编号
Logo string //公司logo
Name string //公司名称
ChargeUserIds []int64 //公司级别的部门主管uids
Status int //公司状态,1正常 2禁用
UpdatedAt time.Time //更新时间
CreatedAt time.Time //创建时间
DeletedAt *time.Time //删除时间
}
type CompanyRepository interface {
... ...
... ... @@ -10,10 +10,11 @@ type Department struct {
ParentId int64 // 组织父级id
ChargeUserIds []int64 // 主管uids
Path string // 组织路径
CreateAt time.Time // 创建时间
UpdateAt time.Time // 更新时间
DeleteAt *time.Time // 删除时间
CreatedAt time.Time // 创建时间
UpdatedAt time.Time // 更新时间
DeletedAt *time.Time // 删除时间
}
type DepartmentRepository interface {
Insert(param *Department) (*Department, error)
Update(param *Department) (*Department, error)
... ...
package domain
type Position struct {
//职位ID
Id int64 `json:"id"`
//公司ID
CompanyId int64 `json:"companyId"`
//职位名称
Name string `json:"name"`
//父级职位ID
ParentId int64 `json:"parentId"`
//职位路径
Path string `json:"path"`
//职位层级
Level int `json:"level"`
}
type PositionRepository interface {
Insert(position *Position) (*Position, error)
Update(position *Position) (*Position, error)
Remove(ids []int64) error
FindOne(queryOption map[string]interface{}) (*Position, error)
}
... ...
... ... @@ -10,13 +10,13 @@ type ReceivedMessage struct {
MessageType string `json:"MessageType"`
MessageBody string `json:"MessageBody"`
OccurredOn time.Time `json:"OccurredOn"`
CreateAt time.Time `json:"-"`
CreatedAt time.Time `json:"-"`
}
type MessageBody struct {
Module string `json:"module"`
Action string `json:"action"`
Datas json.RawMessage `json:"datas"` // 具体的对象JSON数据
Data json.RawMessage `json:"data"` // 具体的对象JSON数据
}
type ReceivedMessageRepository interface {
... ...
... ... @@ -12,15 +12,18 @@ type User struct {
Email string // 邮箱
Status int // 用户状态(1正常 2禁用)
DepartmentId []int // 用户归属的部门
UpdateAt time.Time // 更新时间
DeleteAt *time.Time
CreateAt time.Time
PositionId []int //用户职位
UpdatedAt time.Time // 更新时间
DeletedAt *time.Time
CreatedAt time.Time
}
//1普通员工 2 主管理员
// 1普通员工 2 主管理员
const (
UserTypeCommon int = 1
UserTypeManager int = 2
UserStatusEnable int = 1
)
type UserRepository interface {
... ...
package domain
import (
"errors"
"github.com/dgrijalva/jwt-go"
"time"
)
type UserAuth struct {
jwt.StandardClaims `json:"-"`
UserId int64 `json:"userId"`
CompanyId int64 `json:"companyId"`
Phone string `json:"phone"`
PlatformId int `json:"platformId"`
Name string `json:"name"`
AdminType int `json:"adminType"`
}
var issuer = "performance"
var secretKey = "Ma9HXITeliSYS43Z"
var JWTExpiresSecond = 3600 * 24
// CreateAccessToken 生成token
func (userAuth *UserAuth) CreateAccessToken() (string, error) {
userAuth.StandardClaims = jwt.StandardClaims{
ExpiresAt: time.Now().Add(time.Duration(JWTExpiresSecond) * time.Second).Unix(),
Issuer: issuer,
}
token := jwt.NewWithClaims(jwt.SigningMethodHS256, userAuth)
return token.SignedString([]byte(secretKey))
}
// ParseAccessToken 解析token
func (userAuth *UserAuth) ParseAccessToken(token string) (*UserAuth, error) {
user := &UserAuth{}
tokenClaims, err := jwt.ParseWithClaims(token, user, func(token *jwt.Token) (interface{}, error) {
return []byte(secretKey), nil
})
if err != nil || tokenClaims == nil {
return nil, errors.New("解析token失败")
}
if claim, ok := tokenClaims.Claims.(*UserAuth); ok && tokenClaims.Valid {
user.UserId = claim.UserId
user.CompanyId = claim.CompanyId
user.Phone = claim.Phone
user.PlatformId = claim.PlatformId
user.Name = claim.Name
user.AdminType = claim.AdminType
return user, nil
}
return user, errors.New("解析token失败")
}
... ...
... ... @@ -33,6 +33,7 @@ func init() {
&models.ReceivedMessage{},
&models.Role{},
&models.RoleUser{},
&models.Position{},
&models.EvaluationRule{},
&models.EvaluationTemplate{},
&models.EvaluationCycle{},
... ...
... ... @@ -9,7 +9,7 @@ type Company struct {
Name string //公司名称
ChargeUserIds []int64 //公司级别的部门主管uids
Status int //公司状态,1正常 2禁用
UpdateAt time.Time //更新时间
CreateAt time.Time //创建时间
DeleteAt *time.Time //删除时间
CreatedAt time.Time //创建时间
UpdatedAt time.Time //更新时间
DeletedAt *time.Time `pg:",soft_delete"` //删除时间
}
... ...
... ... @@ -8,12 +8,12 @@ type Department struct {
tableName struct{} `pg:"department"`
Id int64 `pg:"pk:id"` // 组织id
CompanyId int64 // 公司编号
Level int // 组织级别
Level int `pg:",use_zero"` // 组织级别
Name string // 组织名称
ParentId int64 // 组织父级id
ParentId int64 `pg:",use_zero"` // 组织父级id
ChargeUserIds []int64 // 主管uids
Path string // 组织路径
CreateAt time.Time // 创建时间
UpdateAt time.Time // 更新时间
DeleteAt *time.Time // 删除时间
CreatedAt time.Time // 创建时间
UpdatedAt time.Time // 更新时间
DeletedAt *time.Time `pg:",soft_delete"` // 删除时间
}
... ...
... ... @@ -8,5 +8,7 @@ type ReceivedMessage struct {
MessageType string
MessageBody string
OccurredOn time.Time
CreateAt time.Time
CreatedAt time.Time `pg:"default:now()"`
UpdatedAt time.Time `pg:"default:now()"`
DeletedAt *time.Time `pg:",soft_delete"`
}
... ...
package models
import "time"
type Position struct {
tableName struct{} `pg:"position"`
//职位ID
Id int64 `pg:",pk"`
//公司ID
CompanyId int64 `comment:"公司ID"`
//职位名称
Name string `comment:"职位名称"`
//父级职位ID
ParentId int64 `comment:"父级职位ID" pg:",use_zero"`
//职位路径
Path string `comment:"职位路径"`
//职位层级
Level int `comment:"职位层级" pg:",use_zero"`
//创建时间
CreatedAt time.Time `comment:"创建时间" pg:"default:now()"`
//更新时间
UpdatedAt time.Time `comment:"更新时间" pg:"default:now()"`
//删除时间
DeletedAt *time.Time `comment:"删除时间" pg:",soft_delete"`
}
... ...
... ... @@ -11,5 +11,5 @@ type Role struct {
CompanyId int64 `comment:"公司ID"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
DeletedAt *time.Time `comment:"删除时间" pg:",soft_delete"`
}
... ...
... ... @@ -10,5 +10,5 @@ type RoleUser struct {
CompanyId int64 `comment:"公司ID"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
DeletedAt *time.Time `comment:"删除时间" pg:",soft_delete"`
}
... ...
... ... @@ -13,7 +13,8 @@ type User struct {
Email string // 邮箱
Status int // 用户状态(1正常 2禁用)
DepartmentId []int // 用户归属的部门
UpdateAt time.Time // 更新时间
CreateAt time.Time // 创建时间
DeleteAt *time.Time // 删除时间
PositionId []int // 用户职位
CreatedAt time.Time // 创建时间
UpdatedAt time.Time // 更新时间
DeletedAt *time.Time `pg:",soft_delete"` // 删除时间
}
... ...
... ... @@ -28,9 +28,9 @@ func (repo *CompanyRepository) Insert(u *domain.Company) (*domain.Company, error
Name: u.Name,
Status: u.Status,
ChargeUserIds: u.ChargeUserIds,
UpdateAt: u.UpdateAt,
CreateAt: u.CreateAt,
DeleteAt: u.DeleteAt,
UpdatedAt: u.UpdatedAt,
CreatedAt: u.CreatedAt,
DeletedAt: u.DeletedAt,
}
tx := repo.transactionContext.PgTx
_, err := tx.Model(&companyModel).Insert()
... ... @@ -48,9 +48,9 @@ func (repo *CompanyRepository) Update(u *domain.Company) (*domain.Company, error
Name: u.Name,
Status: u.Status,
ChargeUserIds: u.ChargeUserIds,
UpdateAt: u.UpdateAt,
CreateAt: u.CreateAt,
DeleteAt: u.DeleteAt,
UpdatedAt: u.UpdatedAt,
CreatedAt: u.CreatedAt,
DeletedAt: u.DeletedAt,
}
tx := repo.transactionContext.PgTx
_, err := tx.Model(&companyModel).WherePK().Update()
... ... @@ -62,7 +62,7 @@ func (repo *CompanyRepository) Update(u *domain.Company) (*domain.Company, error
func (repo *CompanyRepository) Remove(u *domain.Company) (*domain.Company, error) {
nowTime := time.Now()
u.DeleteAt = &nowTime
u.DeletedAt = &nowTime
_, err := repo.Update(u)
return u, err
}
... ... @@ -113,12 +113,12 @@ func (repo *CompanyRepository) Find(queryOptions map[string]interface{}) (int, [
func (repo *CompanyRepository) TransformToCompanyDomain(m *models.Company) *domain.Company {
return &domain.Company{
Id: m.Id,
Logo: m.Logo,
Name: m.Name,
Status: m.Status,
UpdateAt: m.UpdateAt,
CreateAt: m.CreateAt,
DeleteAt: m.DeleteAt,
Id: m.Id,
Logo: m.Logo,
Name: m.Name,
Status: m.Status,
UpdatedAt: m.UpdatedAt,
CreatedAt: m.CreatedAt,
DeletedAt: m.DeletedAt,
}
}
... ...
package repository
import (
"time"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
... ... @@ -30,9 +28,9 @@ func (repo *DepartmentRepository) Insert(u *domain.Department) (*domain.Departme
ParentId: u.ParentId,
ChargeUserIds: u.ChargeUserIds,
Path: u.Path,
CreateAt: u.CreateAt,
UpdateAt: u.UpdateAt,
DeleteAt: nil,
CreatedAt: u.CreatedAt,
UpdatedAt: u.UpdatedAt,
DeletedAt: nil,
}
tx := repo.transactionContext.PgTx
_, err := tx.Model(&departmentModel).Insert()
... ... @@ -52,9 +50,9 @@ func (repo *DepartmentRepository) Update(u *domain.Department) (*domain.Departme
ParentId: u.ParentId,
ChargeUserIds: u.ChargeUserIds,
Path: u.Path,
CreateAt: u.CreateAt,
UpdateAt: u.UpdateAt,
DeleteAt: u.DeleteAt,
CreatedAt: u.CreatedAt,
UpdatedAt: u.UpdatedAt,
DeletedAt: u.DeletedAt,
}
tx := repo.transactionContext.PgTx
_, err := tx.Model(&departmentModel).WherePK().Update()
... ... @@ -65,13 +63,11 @@ func (repo *DepartmentRepository) Update(u *domain.Department) (*domain.Departme
}
func (repo *DepartmentRepository) Remove(ids []int64) error {
nowTime := time.Now()
tx := repo.transactionContext.PgTx
uModel := models.Department{}
_, err := tx.Model(&uModel).
Set("delete_at", nowTime).
Where("id in (?)", pg.In(ids)).
Update()
Delete()
return err
}
... ... @@ -95,14 +91,14 @@ func (repo *DepartmentRepository) FindOne(queryOptions map[string]interface{}) (
func (repo *DepartmentRepository) Find(queryOptions map[string]interface{}) (int, []*domain.Department, error) {
tx := repo.transactionContext.PgTx
dparmentModel := []models.Department{}
var dparmentModel []models.Department
query := tx.Model(&dparmentModel).
Limit(20)
if v, ok := queryOptions["id"]; ok {
query.Where("id=?", v)
}
if v, ok := queryOptions["ids"]; ok {
query.Where("id in(?)", pg.In(v))
query.Where("id in (?)", pg.In(v))
}
if v, ok := queryOptions["limit"]; ok {
query.Limit(v.(int))
... ... @@ -131,8 +127,8 @@ func (repo *DepartmentRepository) TransformToCompanyDomain(u *models.Department)
ParentId: u.ParentId,
ChargeUserIds: u.ChargeUserIds,
Path: u.Path,
CreateAt: u.CreateAt,
UpdateAt: u.UpdateAt,
DeleteAt: u.DeleteAt,
CreatedAt: u.CreatedAt,
UpdatedAt: u.UpdatedAt,
DeletedAt: u.DeletedAt,
}
}
... ...
package repository
import (
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
"time"
)
type PositionRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func NewPositionRepository(tx *pgTransaction.TransactionContext) *PositionRepository {
return &PositionRepository{
transactionContext: tx,
}
}
// Insert 新增职位
func (repository *PositionRepository) Insert(position *domain.Position) (*domain.Position, error) {
model := &models.Position{
Id: position.Id,
CompanyId: position.CompanyId,
Name: position.Name,
ParentId: position.ParentId,
Path: position.Path,
Level: position.Level,
}
_, err := repository.transactionContext.PgTx.Model(model).Insert()
return position, err
}
// Update 更新
func (repository *PositionRepository) Update(position *domain.Position) (*domain.Position, error) {
model := &models.Position{
Id: position.Id,
CompanyId: position.CompanyId,
Name: position.Name,
ParentId: position.ParentId,
Path: position.Path,
Level: position.Level,
UpdatedAt: time.Now(),
}
_, err := repository.transactionContext.PgTx.Model(model).WherePK().Update()
return position, err
}
// Remove 删除
func (repository *PositionRepository) Remove(ids []int64) error {
_, err := repository.transactionContext.PgTx.Model(&models.Position{}).Where("id in (?)", pg.In(ids)).Delete()
return err
}
func (repository *PositionRepository) FindOne(queryOption map[string]interface{}) (*domain.Position, error) {
position := &models.Position{}
query := repository.transactionContext.PgTx.Model(position)
if id, ok := queryOption["id"]; ok {
query.Where("id = ?", id)
}
err := query.First()
if err != nil {
return nil, err
}
return repository.transferToDomain(position), nil
}
func (repository *PositionRepository) transferToDomain(model *models.Position) *domain.Position {
return &domain.Position{
Id: model.Id,
CompanyId: model.CompanyId,
Name: model.Name,
ParentId: model.ParentId,
Path: model.Path,
Level: model.Level,
}
}
... ...
... ... @@ -27,7 +27,7 @@ func (repo *ReceivedMessageRepository) SaveMessage(param *domain.ReceivedMessage
MessageType: param.MessageType,
MessageBody: param.MessageBody,
OccurredOn: param.OccurredOn,
CreateAt: time.Now(),
CreatedAt: time.Now(),
}
tx := repo.transactionContext.PgTx
_, err := tx.Model(message).
... ... @@ -50,7 +50,7 @@ func (repo *ReceivedMessageRepository) FindMessage(messageId int64) (*domain.Rec
MessageType: receivedMessageModel.MessageType,
MessageBody: receivedMessageModel.MessageBody,
OccurredOn: receivedMessageModel.OccurredOn,
CreateAt: receivedMessageModel.CreateAt,
CreatedAt: receivedMessageModel.CreatedAt,
}
return message, nil
... ...
package repository
import (
"time"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
... ... @@ -30,9 +28,9 @@ func (repo *UserRepository) Insert(user *domain.User) (*domain.User, error) {
AdminType: user.AdminType,
Name: user.Name,
Status: user.Status,
UpdateAt: user.UpdateAt,
CreateAt: user.CreateAt,
DeleteAt: user.DeleteAt,
UpdatedAt: user.UpdatedAt,
CreatedAt: user.CreatedAt,
DeletedAt: user.DeletedAt,
}
tx := repo.transactionContext.PgTx
_, err := tx.Model(&userModel).Insert()
... ... @@ -53,9 +51,9 @@ func (repo *UserRepository) Update(user *domain.User) (*domain.User, error) {
Name: user.Name,
Email: user.Email,
Status: user.Status,
UpdateAt: user.UpdateAt,
CreateAt: user.CreateAt,
DeleteAt: user.DeleteAt,
UpdatedAt: user.UpdatedAt,
CreatedAt: user.CreatedAt,
DeletedAt: user.DeletedAt,
}
tx := repo.transactionContext.PgTx
_, err := tx.Model(&userModel).WherePK().Update()
... ... @@ -66,13 +64,9 @@ func (repo *UserRepository) Update(user *domain.User) (*domain.User, error) {
}
func (repo *UserRepository) Remove(userId []int64) error {
nowTime := time.Now()
tx := repo.transactionContext.PgTx
uModel := models.User{}
_, err := tx.Model(&uModel).
Set("delete_at", nowTime).
Where("id in (?)", pg.In(userId)).
Update()
_, err := tx.Model(&uModel).Where("id in (?)", pg.In(userId)).Delete()
return err
}
... ... @@ -83,6 +77,9 @@ func (repo *UserRepository) FindOne(queryOptions map[string]interface{}) (*domai
if v, ok := queryOptions["id"]; ok {
query.Where("id=?", v)
}
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", v)
}
err := query.First()
if err == pg.ErrNoRows {
return nil, ErrNoRows
... ... @@ -97,8 +94,7 @@ func (repo *UserRepository) FindOne(queryOptions map[string]interface{}) (*domai
func (repo *UserRepository) Find(queryOptions map[string]interface{}) (int, []*domain.User, error) {
tx := repo.transactionContext.PgTx
userModel := []models.User{}
query := tx.Model(&userModel).Where("delete_at isnull").
Limit(20)
query := tx.Model(&userModel).Limit(20)
if v, ok := queryOptions["id"]; ok {
query.Where("id=?", v)
}
... ... @@ -142,8 +138,8 @@ func (repo *UserRepository) TransformToUserDomain(user *models.User) *domain.Use
Name: user.Name,
Email: user.Email,
Status: user.Status,
UpdateAt: user.UpdateAt,
CreateAt: user.CreateAt,
DeleteAt: user.DeleteAt,
UpdatedAt: user.UpdatedAt,
CreatedAt: user.CreatedAt,
DeletedAt: user.DeletedAt,
}
}
... ...
package serviceGateway
import (
"crypto/tls"
"encoding/json"
"github.com/beego/beego/v2/client/httplib"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
"io/ioutil"
"net/http"
"reflect"
"strings"
"time"
)
type httpLibBaseServiceGateway struct {
baseURL string
connectTimeout time.Duration
readWriteTimeout time.Duration
request *httplib.BeegoHTTPRequest
params map[string]interface{}
body string
}
func (client *httpLibBaseServiceGateway) CreateRequest(method, url string) {
client.request = httplib.NewBeegoRequest(client.baseURL+url, strings.ToUpper(method))
client.request.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
}
// 设置请求参数
func (client *httpLibBaseServiceGateway) SetParams(params map[string]string) {
if len(params) > 0 {
for key, value := range params {
client.request.Param(key, value)
client.params[key] = value
}
}
}
// 设置请求参数
func (client *httpLibBaseServiceGateway) SetParam(key, value string) {
client.request.Param(key, value)
client.params[key] = value
}
// 设置body
func (client *httpLibBaseServiceGateway) SetBody(body interface{}) {
//判断是否为string
ty := reflect.TypeOf(body)
if ty.Name() == "string" {
client.request.Body(body)
client.body = body.(string)
} else {
mBytes, _ := json.Marshal(body)
client.request.Body(mBytes)
client.body = string(mBytes)
}
client.request.Header("Content-Type", "application/json")
client.request.Header("Accept", "application/json")
}
// 设置头信息
func (client *httpLibBaseServiceGateway) SetHeader(key, value string) {
client.request.Header(key, value)
}
// 设置多个头部信息
func (client *httpLibBaseServiceGateway) SetHeaders(headers map[string]string) {
if len(headers) > 0 {
for key, value := range headers {
client.request.Header(key, value)
}
}
}
// 设置超时时间
func (client *httpLibBaseServiceGateway) SetTimeout(connectTimeout, readWriteTimeout time.Duration) {
client.request.SetTimeout(connectTimeout, readWriteTimeout)
}
// 设置cookie
func (client *httpLibBaseServiceGateway) SetCookie(cookie *http.Cookie) {
client.request.SetCookie(cookie)
}
// 设置UserAgent
func (client *httpLibBaseServiceGateway) SetUserAgent(userAgent string) {
client.request.SetUserAgent(userAgent)
}
// 请求结果返回结构体
func (client *httpLibBaseServiceGateway) ToJson(result interface{}) error {
response, err := client.request.Response()
if err != nil {
return err
}
client.addOptionLog(response)
mBytes, err := ioutil.ReadAll(response.Body)
if err != nil {
return err
}
err = json.Unmarshal(mBytes, result)
//增加返回数据日志
log.Logger.Debug(response.Request.Method+" "+response.Request.URL.String()+"----response----", tool_funs.SimpleStructToMap(result))
return err
}
// 请求结果返回string
func (client *httpLibBaseServiceGateway) ToString() (string, error) {
response, err := client.request.Response()
if err != nil {
return "", err
}
client.addOptionLog(response)
mBytes, err := ioutil.ReadAll(response.Body)
//增加返回数据日志
log.Logger.Debug(response.Request.Method + " " + response.Request.URL.String() + "----response----" + string(mBytes))
return string(mBytes), err
}
// 请求结果返回bytes
func (client *httpLibBaseServiceGateway) ToBytes() ([]byte, error) {
response, err := client.request.Response()
if err != nil {
return nil, err
}
client.addOptionLog(response)
mBytes, _ := ioutil.ReadAll(response.Body)
//增加返回数据日志
log.Logger.Debug(response.Request.Method + " " + response.Request.URL.String() + "----response----" + string(mBytes))
return mBytes, nil
}
// 添加options日志
func (client *httpLibBaseServiceGateway) addOptionLog(response *http.Response) {
logTxt := response.Request.Method + " " + response.Request.URL.String()
if response.Request.Method != http.MethodGet {
contentType := client.request.GetRequest().Header.Get("Content-Type")
if strings.Contains(strings.ToLower(contentType), "json") {
log.Logger.Debug(logTxt+" ----options----", map[string]interface{}{"body": client.body})
} else {
log.Logger.Debug(logTxt+" ----options----", map[string]interface{}{"params": client.params})
}
}
}
... ...
package serviceGateway
import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/serviceGateway/reply"
"net/http"
)
type HttpLibBusinessAdminServiceGateway struct {
httpLibBaseServiceGateway
}
// GetUserAuth 请求企业平台确认用户是否可以使用
func (serviceGateway *HttpLibBusinessAdminServiceGateway) GetUserAuth(userId int64, platformId int) (*reply.BusinessAdminUserAuth, error) {
businessAdminUserAuth := &reply.BusinessAdminUserAuth{}
serviceGateway.CreateRequest(http.MethodPost, "/auth/get-user-auth")
serviceGateway.SetBody(map[string]interface{}{
"userId": userId,
"platformId": platformId,
})
err := serviceGateway.ToJson(businessAdminUserAuth)
return businessAdminUserAuth, err
}
func NewHttpLibBusinessAdminServiceGateway() *HttpLibBusinessAdminServiceGateway {
return &HttpLibBusinessAdminServiceGateway{
httpLibBaseServiceGateway{
baseURL: constant.BUSINESS_ADMIN_SERVICE_HOST,
},
}
}
... ...
package serviceGateway
import (
"crypto/sha1"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/serviceGateway/reply"
"net/http"
"net/url"
"time"
)
type HttpLibUCenterApiServiceGateway struct {
httpLibBaseServiceGateway
}
func (serviceGateway *HttpLibUCenterApiServiceGateway) buildHeaders() map[string]string {
nowTime := fmt.Sprint(time.Now().Unix())
str := fmt.Sprintf("%s%s%s", nowTime, constant.UCENTER_SECRET, constant.UCENTER_CHECK_ALT)
bt := sha1.Sum([]byte(str))
checksum := fmt.Sprintf("%x", bt)
return map[string]string{
"appKey": constant.UCENTER_APP_KEY,
"nonce": "",
"curTime": nowTime,
"checkSum": checksum,
}
}
// AuthCode PC端登录
func (serviceGateway *HttpLibUCenterApiServiceGateway) AuthCode(code string) (*reply.UCenterAuthCode, error) {
authCodeReply := &reply.UCenterAuthCode{}
serviceGateway.CreateRequest(http.MethodPost, "/auth/serverLogin")
serviceGateway.SetBody(map[string]interface{}{
"type": 3,
"secret": url.QueryEscape(code),
})
serviceGateway.SetHeaders(serviceGateway.buildHeaders())
err := serviceGateway.ToJson(authCodeReply)
return authCodeReply, err
}
func NewHttpLibUCenterApiServiceGateway() *HttpLibUCenterApiServiceGateway {
return &HttpLibUCenterApiServiceGateway{
httpLibBaseServiceGateway{baseURL: constant.UCENTER_SERVICE_HOST},
}
}
... ...
package reply
type BaseReply struct {
Code int `json:"code"`
Msg string `json:"msg"`
}
func (msg *BaseReply) IsOk() bool {
if msg.Code != 0 {
return false
}
return true
}
... ...
package reply
type BusinessAdminUserAuth struct {
BaseReply
Data struct {
UserAuth bool `json:"userAuth"`
} `json:"data"`
}
func (businessAdminUserAuth *BusinessAdminUserAuth) Message() string {
if businessAdminUserAuth.Code == 10001 {
return "用户不存在"
}
if businessAdminUserAuth.Code == 10002 {
return "登录凭证已过期,请重新登陆"
}
if businessAdminUserAuth.Code == 10003 {
return "验证码不能为空"
}
if businessAdminUserAuth.Code == 10004 {
return "登录凭证不能为空"
}
if businessAdminUserAuth.Code == 10005 {
return "密码不能为空"
}
if businessAdminUserAuth.Code == 10006 {
return "当前账号已被禁用"
}
if businessAdminUserAuth.Code == 10007 {
return "该企业已被禁用,无法正常访问!重新选择其他企业进入,或退出登录。"
}
if businessAdminUserAuth.Code == 10008 {
return "抱歉,企业管理员未帮您开通权限。如需访问,请联系企业管理员"
}
if businessAdminUserAuth.Code == 10009 {
return "密码错误"
}
if businessAdminUserAuth.Code == 10010 {
return "验证码错误"
}
return "你没有权限进入系统,请联系管理员"
}
... ...
package reply
type UCenterAuthCode struct {
BaseReply
Data struct {
Id int64 `json:"id"` //统一用户中心的id,对应本系统中users表的open_id
Phone string `json:"phone"` //手机号 ,账号
NickName string `json:"nickname"` //昵称
Avatar string `json:"avatar"` //头像
ImToken string `json:"imtoken"` //网易云imtoken
AccId int64 `json:"accid"` //网易云id
CustomerAccount int64 `json:"customerAccount"` //客服id
CompanyId int64 `json:"companyId"` //总后台的公司id ,对应company表中的admin_company_id
MUid int64 `json:"muid"` //企业平台的用户id,对应本系统中users表的id
} `json:"data"`
}
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/auth/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/auth/service"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type AuthController struct {
beego.BaseController
}
// Login PC端登录
func (controller *AuthController) Login() {
authService := &service.AuthService{}
loginCommand := &command.LoginCommand{}
_ = controller.Unmarshal(loginCommand)
resp, err := authService.Login(loginCommand)
controller.Response(resp, err)
}
func (controller *AuthController) User() {
userAuth := controller.Ctx.Input.GetData(domain.UserAuth{}).(*domain.UserAuth)
controller.Response(map[string]interface{}{
"user": userAuth,
}, nil)
}
... ...
package controllers
import (
"github.com/beego/beego/v2/server/web"
"github.com/beego/beego/v2/server/web/context"
)
type HelloController struct {
web.Controller
}
func (c *HelloController) Say() {
c.JSONResp(map[string]string{
"msg": "hello",
})
}
func SayHello(c *context.Context) {
c.JSONResp(map[string]string{
"msg": "hello",
})
}
package controllers
import (
"github.com/beego/beego/v2/server/web"
"os"
)
type LoggerController struct {
web.Controller
}
func (controller *LoggerController) Output() {
bytes, _ := os.ReadFile("./debug.log")
controller.Ctx.WriteString(string(bytes))
}
... ...
package middlewares
import (
"github.com/beego/beego/v2/server/web/context"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
func CheckAdminToken() func(ctx *context.Context) {
return func(ctx *context.Context) {
adminToken := ctx.Input.Header("x-admin-token")
userAuth, err := (&domain.UserAuth{}).ParseAccessToken(adminToken)
if err != nil || userAuth.UserId <= 0 {
forbidden(ctx)
return
}
if userAuth.PlatformId != constant.PLATFORM_ADMIN_ID {
forbidden(ctx)
return
}
ctx.Input.SetData(domain.UserAuth{}, userAuth)
}
}
func forbidden(ctx *context.Context) {
resp := map[string]interface{}{
"code": 902,
"msg": "Authorization过期或无效,需要进行重新获取令牌",
}
_ = ctx.Output.JSON(resp, false, false)
}
... ...
package middlewares
import (
"github.com/beego/beego/v2/server/web/context"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
func CheckFontToken() func(ctx *context.Context) {
return func(ctx *context.Context) {
adminToken := ctx.Input.Header("x-font-token")
userAuth, err := (&domain.UserAuth{}).ParseAccessToken(adminToken)
if err != nil || userAuth.UserId <= 0 {
forbidden(ctx)
return
}
if userAuth.PlatformId != constant.PLATFORM_FONT_ID {
forbidden(ctx)
return
}
ctx.Input.SetData(domain.UserAuth{}, userAuth)
}
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
func init() {
web.Router("/login", &controllers.AuthController{}, "Post:Login")
web.InsertFilter("/auth/admin/*", web.BeforeExec, middlewares.CheckAdminToken())
web.Router("/auth/admin/user", &controllers.AuthController{}, "Get:User")
web.InsertFilter("/auth/font/*", web.BeforeExec, middlewares.CheckFontToken())
web.Router("/auth/font/user", &controllers.AuthController{}, "Get:User")
}
... ...
... ... @@ -6,10 +6,6 @@ import (
)
func init() {
h1 := web.NewNamespace("/v1/demo",
web.NSCtrlGet("/hello", (*controllers.HelloController).Say),
web.NSCtrlGet("/hello2", (*controllers.HelloController).Say),
// web.NSGet("/hello1", controllers.SayHello),
)
web.AddNamespace(h1)
//日志输出
web.Router("/log", &controllers.LoggerController{}, "Get:Output")
}
... ...
... ... @@ -2,6 +2,7 @@ package handle
import (
"encoding/json"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/position/service"
"strconv"
"github.com/Shopify/sarama"
... ... @@ -15,13 +16,12 @@ import (
func SyncDataBusinessAdmin(msgData *sarama.ConsumerMessage) error {
var receivedMsg domain.ReceivedMessage
log.Logger.Debug(string(msgData.Value))
err := json.Unmarshal(msgData.Value, &receivedMsg)
if err != nil {
log.Logger.Error("解析ReceivedMessage 失败" + err.Error())
return err
}
log.Logger.Debug("解析message:", map[string]interface{}{"data": receivedMsg})
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return err
... ... @@ -60,7 +60,9 @@ func SyncDataBusinessAdmin(msgData *sarama.ConsumerMessage) error {
err = companySrv.FromBusinessAdmin(&msgBody)
if err != nil {
log.Logger.Error("处理company消息失败"+err.Error(), map[string]interface{}{
"data": msgBody,
"module": msgBody.Module,
"action": msgBody.Action,
"data": string(msgBody.Data),
})
return err
}
... ... @@ -69,7 +71,9 @@ func SyncDataBusinessAdmin(msgData *sarama.ConsumerMessage) error {
err = departmentSrv.FromBusinessAdmin(&msgBody)
if err != nil {
log.Logger.Error("处理department消息失败"+err.Error(), map[string]interface{}{
"data": msgBody,
"module": msgBody.Module,
"action": msgBody.Action,
"data": string(msgBody.Data),
})
return err
}
... ... @@ -78,7 +82,20 @@ func SyncDataBusinessAdmin(msgData *sarama.ConsumerMessage) error {
err = employeeSrv.FromBusinessAdmin(&msgBody)
if err != nil {
log.Logger.Error("处理employee消息失败"+err.Error(), map[string]interface{}{
"data": msgBody,
"module": msgBody.Module,
"action": msgBody.Action,
"data": string(msgBody.Data),
})
return err
}
case "position":
positionSrv := service.SyncDataPositionService{}
err = positionSrv.FromBusinessAdmin(&msgBody)
if err != nil {
log.Logger.Error("处理position消息失败"+err.Error(), map[string]interface{}{
"module": msgBody.Module,
"action": msgBody.Action,
"data": string(msgBody.Data),
})
return err
}
... ...
... ... @@ -6,20 +6,20 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/consumer/handle"
"strings"
)
func Run() {
messageHandlerMap := make(map[string]func(message *sarama.ConsumerMessage) error)
messageHandlerMap["demo-v1"] = Demo
//messageHandlerMap["demo-v1"] = Demo
//"指定topic" => 对应的处理方法
messageHandlerMap["mmm-business-admin-dev"] = handle.SyncDataBusinessAdmin
err := saramaConsumer.StartConsume(constant.KAFKA_HOSTS, constant.SERVICE_NAME, messageHandlerMap, log.Logger)
messageHandlerMap[constant.KAFKA_BUSINESS_TOPIC] = handle.SyncDataBusinessAdmin
hosts := strings.Split(constant.KAFKA_HOSTS, ",")
var host string
if len(hosts) > 0 {
host = hosts[0]
}
log.Logger.Debug("kafka host: " + host + " topic:" + constant.KAFKA_BUSINESS_TOPIC + " group id:" + constant.KAFKA_GROUP_ID)
err := saramaConsumer.StartConsume(host, constant.KAFKA_GROUP_ID, messageHandlerMap, log.Logger)
log.Logger.Error(err.Error())
}
func Demo(message *sarama.ConsumerMessage) error {
k := string(message.Key)
v := string(message.Value)
log.Logger.Debug("message===>" + k + ":" + v)
return nil
}
... ...