feat: initial commit for muyu-apiserver
Go service with gateway, RPC, model layers and k8s deploy configs. Made-with: Cursor
This commit is contained in:
commit
71a2d912e2
31
.gitignore
vendored
Normal file
31
.gitignore
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
# Binaries
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
/bin/
|
||||
/output/
|
||||
|
||||
# Test
|
||||
*.test
|
||||
*.out
|
||||
coverage.txt
|
||||
|
||||
# Dependency
|
||||
/vendor/
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Env
|
||||
.env
|
||||
.env.local
|
||||
12
cmd/genhash/main.go
Normal file
12
cmd/genhash/main.go
Normal file
@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
hash, _ := bcrypt.GenerateFromPassword([]byte("admin123"), bcrypt.DefaultCost)
|
||||
fmt.Println(string(hash))
|
||||
}
|
||||
7
deploy/Dockerfile.gateway
Normal file
7
deploy/Dockerfile.gateway
Normal file
@ -0,0 +1,7 @@
|
||||
FROM alpine:3.19
|
||||
RUN apk add --no-cache ca-certificates tzdata
|
||||
WORKDIR /app
|
||||
COPY deploy/bin/gateway .
|
||||
COPY deploy/etc/gateway.yaml etc/gateway.yaml
|
||||
EXPOSE 8888
|
||||
CMD ["./gateway", "-f", "etc/gateway.yaml"]
|
||||
7
deploy/Dockerfile.inventory
Normal file
7
deploy/Dockerfile.inventory
Normal file
@ -0,0 +1,7 @@
|
||||
FROM alpine:3.19
|
||||
RUN apk add --no-cache ca-certificates tzdata
|
||||
WORKDIR /app
|
||||
COPY deploy/bin/inventory .
|
||||
COPY deploy/etc/inventory.yaml etc/inventory.yaml
|
||||
EXPOSE 9002
|
||||
CMD ["./inventory", "-f", "etc/inventory.yaml"]
|
||||
7
deploy/Dockerfile.system
Normal file
7
deploy/Dockerfile.system
Normal file
@ -0,0 +1,7 @@
|
||||
FROM alpine:3.19
|
||||
RUN apk add --no-cache ca-certificates tzdata
|
||||
WORKDIR /app
|
||||
COPY deploy/bin/system .
|
||||
COPY deploy/etc/system.yaml etc/system.yaml
|
||||
EXPOSE 9001
|
||||
CMD ["./system", "-f", "etc/system.yaml"]
|
||||
115
deploy/docker-compose.yaml
Normal file
115
deploy/docker-compose.yaml
Normal file
@ -0,0 +1,115 @@
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:8.0
|
||||
container_name: muyu-mysql
|
||||
restart: always
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: muyu2026
|
||||
MYSQL_DATABASE: muyu_wms
|
||||
TZ: Asia/Shanghai
|
||||
ports:
|
||||
- "3306:3306"
|
||||
volumes:
|
||||
- ./mysql/init.sql:/docker-entrypoint-initdb.d/init.sql
|
||||
- ../data/mysql:/var/lib/mysql
|
||||
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
||||
healthcheck:
|
||||
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
container_name: muyu-redis
|
||||
restart: always
|
||||
ports:
|
||||
- "6379:6379"
|
||||
volumes:
|
||||
- ../data/redis:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
etcd:
|
||||
image: quay.io/coreos/etcd:v3.5.17
|
||||
container_name: muyu-etcd
|
||||
restart: always
|
||||
command:
|
||||
- etcd
|
||||
- --name=default
|
||||
- --data-dir=/etcd-data
|
||||
- --listen-client-urls=http://0.0.0.0:2379
|
||||
- --advertise-client-urls=http://etcd:2379
|
||||
- --listen-peer-urls=http://0.0.0.0:2380
|
||||
- --initial-advertise-peer-urls=http://etcd:2380
|
||||
- --initial-cluster=default=http://etcd:2380
|
||||
- --initial-cluster-state=new
|
||||
ports:
|
||||
- "2379:2379"
|
||||
healthcheck:
|
||||
test: ["CMD", "etcdctl", "endpoint", "health"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
system-rpc:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: deploy/Dockerfile.system
|
||||
container_name: muyu-system-rpc
|
||||
restart: always
|
||||
depends_on:
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
etcd:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
|
||||
inventory-rpc:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: deploy/Dockerfile.inventory
|
||||
container_name: muyu-inventory-rpc
|
||||
restart: always
|
||||
depends_on:
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
etcd:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
|
||||
gateway:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: deploy/Dockerfile.gateway
|
||||
container_name: muyu-gateway
|
||||
restart: always
|
||||
ports:
|
||||
- "8888:8888"
|
||||
depends_on:
|
||||
- system-rpc
|
||||
- inventory-rpc
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
container_name: muyu-nginx
|
||||
restart: always
|
||||
ports:
|
||||
- "8080:80"
|
||||
volumes:
|
||||
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
- ../../muyu-portal/dist:/usr/share/nginx/html
|
||||
- ../data/uploads:/usr/share/nginx/uploads
|
||||
depends_on:
|
||||
- gateway
|
||||
26
deploy/etc/gateway.yaml
Normal file
26
deploy/etc/gateway.yaml
Normal file
@ -0,0 +1,26 @@
|
||||
Name: gateway-api
|
||||
Host: 0.0.0.0
|
||||
Port: 8888
|
||||
|
||||
Auth:
|
||||
AccessSecret: muyu-wms-jwt-secret-key-2026
|
||||
AccessExpire: 7200
|
||||
|
||||
SystemRpc:
|
||||
Etcd:
|
||||
Hosts:
|
||||
- etcd:2379
|
||||
Key: system.rpc
|
||||
NonBlock: true
|
||||
|
||||
InventoryRpc:
|
||||
Etcd:
|
||||
Hosts:
|
||||
- etcd:2379
|
||||
Key: inventory.rpc
|
||||
NonBlock: true
|
||||
|
||||
Log:
|
||||
ServiceName: gateway-api
|
||||
Mode: console
|
||||
Level: info
|
||||
17
deploy/etc/inventory.yaml
Normal file
17
deploy/etc/inventory.yaml
Normal file
@ -0,0 +1,17 @@
|
||||
Name: inventory.rpc
|
||||
ListenOn: 0.0.0.0:9002
|
||||
|
||||
Etcd:
|
||||
Hosts:
|
||||
- etcd:2379
|
||||
Key: inventory.rpc
|
||||
|
||||
DataSource: root:muyu2026@tcp(mysql:3306)/muyu_wms?charset=utf8mb4&parseTime=true&loc=Asia%2FShanghai
|
||||
|
||||
Cache:
|
||||
- Host: redis:6379
|
||||
|
||||
Log:
|
||||
ServiceName: inventory-rpc
|
||||
Mode: console
|
||||
Level: info
|
||||
17
deploy/etc/system.yaml
Normal file
17
deploy/etc/system.yaml
Normal file
@ -0,0 +1,17 @@
|
||||
Name: system.rpc
|
||||
ListenOn: 0.0.0.0:9001
|
||||
|
||||
Etcd:
|
||||
Hosts:
|
||||
- etcd:2379
|
||||
Key: system.rpc
|
||||
|
||||
DataSource: root:muyu2026@tcp(mysql:3306)/muyu_wms?charset=utf8mb4&parseTime=true&loc=Asia%2FShanghai
|
||||
|
||||
Cache:
|
||||
- Host: redis:6379
|
||||
|
||||
Log:
|
||||
ServiceName: system-rpc
|
||||
Mode: console
|
||||
Level: info
|
||||
312
deploy/mysql/init.sql
Normal file
312
deploy/mysql/init.sql
Normal file
@ -0,0 +1,312 @@
|
||||
-- Muyu Warehouse Management System - Database Init Script
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
SET CHARACTER SET utf8mb4;
|
||||
|
||||
CREATE DATABASE IF NOT EXISTS `muyu_wms` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
USE `muyu_wms`;
|
||||
|
||||
-- ==================== System Management Tables ====================
|
||||
|
||||
CREATE TABLE `sys_user` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`user_id` VARCHAR(32) NOT NULL,
|
||||
`username` VARCHAR(50) NOT NULL,
|
||||
`password` VARCHAR(255) NOT NULL,
|
||||
`salt` VARCHAR(32) NOT NULL,
|
||||
`real_name` VARCHAR(50) NOT NULL DEFAULT '',
|
||||
`phone` VARCHAR(20) NOT NULL DEFAULT '',
|
||||
`email` VARCHAR(100) NOT NULL DEFAULT '',
|
||||
`avatar` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
`status` TINYINT NOT NULL DEFAULT 1 COMMENT '1:enabled 0:disabled',
|
||||
`last_login_time` DATETIME DEFAULT NULL,
|
||||
`last_login_ip` VARCHAR(50) NOT NULL DEFAULT '',
|
||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`deleted_at` DATETIME DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_user_id` (`user_id`),
|
||||
UNIQUE KEY `uk_username` (`username`),
|
||||
KEY `idx_status` (`status`),
|
||||
KEY `idx_deleted_at` (`deleted_at`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE `sys_role` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`role_id` VARCHAR(32) NOT NULL,
|
||||
`role_name` VARCHAR(50) NOT NULL,
|
||||
`role_key` VARCHAR(50) NOT NULL,
|
||||
`role_desc` VARCHAR(200) NOT NULL DEFAULT '',
|
||||
`sort_order` INT NOT NULL DEFAULT 0,
|
||||
`status` TINYINT NOT NULL DEFAULT 1 COMMENT '1:enabled 0:disabled',
|
||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_role_id` (`role_id`),
|
||||
UNIQUE KEY `uk_role_key` (`role_key`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE `sys_user_role` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`user_id` VARCHAR(32) NOT NULL,
|
||||
`role_id` VARCHAR(32) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_user_role` (`user_id`, `role_id`),
|
||||
KEY `idx_role_id` (`role_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE `sys_menu` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`menu_id` VARCHAR(32) NOT NULL,
|
||||
`parent_id` VARCHAR(32) NOT NULL DEFAULT '',
|
||||
`menu_name` VARCHAR(50) NOT NULL,
|
||||
`menu_type` TINYINT NOT NULL DEFAULT 1 COMMENT '1:directory 2:menu 3:button',
|
||||
`path` VARCHAR(200) NOT NULL DEFAULT '',
|
||||
`component` VARCHAR(200) NOT NULL DEFAULT '',
|
||||
`permission` VARCHAR(100) NOT NULL DEFAULT '',
|
||||
`icon` VARCHAR(50) NOT NULL DEFAULT '',
|
||||
`sort_order` INT NOT NULL DEFAULT 0,
|
||||
`visible` TINYINT NOT NULL DEFAULT 1 COMMENT '1:visible 0:hidden',
|
||||
`status` TINYINT NOT NULL DEFAULT 1 COMMENT '1:enabled 0:disabled',
|
||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_menu_id` (`menu_id`),
|
||||
KEY `idx_parent_id` (`parent_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE `sys_role_menu` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`role_id` VARCHAR(32) NOT NULL,
|
||||
`menu_id` VARCHAR(32) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_role_menu` (`role_id`, `menu_id`),
|
||||
KEY `idx_menu_id` (`menu_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE `sys_operation_log` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`log_id` VARCHAR(32) NOT NULL,
|
||||
`user_id` VARCHAR(32) NOT NULL DEFAULT '',
|
||||
`username` VARCHAR(50) NOT NULL DEFAULT '',
|
||||
`module` VARCHAR(50) NOT NULL DEFAULT '',
|
||||
`operation` VARCHAR(20) NOT NULL DEFAULT '',
|
||||
`method` VARCHAR(10) NOT NULL DEFAULT '',
|
||||
`path` VARCHAR(200) NOT NULL DEFAULT '',
|
||||
`request_body` TEXT,
|
||||
`response_body` TEXT,
|
||||
`ip` VARCHAR(50) NOT NULL DEFAULT '',
|
||||
`user_agent` VARCHAR(500) NOT NULL DEFAULT '',
|
||||
`duration` INT NOT NULL DEFAULT 0 COMMENT 'milliseconds',
|
||||
`status` TINYINT NOT NULL DEFAULT 1 COMMENT '1:success 0:fail',
|
||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_log_id` (`log_id`),
|
||||
KEY `idx_user_id` (`user_id`),
|
||||
KEY `idx_module` (`module`),
|
||||
KEY `idx_created_at` (`created_at`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE `sys_config` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`config_id` VARCHAR(32) NOT NULL,
|
||||
`config_key` VARCHAR(50) NOT NULL,
|
||||
`config_value` TEXT,
|
||||
`config_name` VARCHAR(100) NOT NULL DEFAULT '',
|
||||
`config_group` VARCHAR(50) NOT NULL DEFAULT '',
|
||||
`remark` TEXT,
|
||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_config_id` (`config_id`),
|
||||
UNIQUE KEY `uk_config_key` (`config_key`),
|
||||
KEY `idx_config_group` (`config_group`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- ==================== Inventory Management Tables ====================
|
||||
|
||||
CREATE TABLE `inv_product` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`product_id` VARCHAR(32) NOT NULL,
|
||||
`product_name` VARCHAR(100) NOT NULL,
|
||||
`image_url` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
`spec` VARCHAR(100) NOT NULL DEFAULT '',
|
||||
`color` VARCHAR(50) NOT NULL DEFAULT '',
|
||||
`unit_pieces` INT NOT NULL DEFAULT 0,
|
||||
`unit_rolls` INT NOT NULL DEFAULT 0,
|
||||
`stock_quantity` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
|
||||
`location` VARCHAR(100) NOT NULL DEFAULT '',
|
||||
`cost_price` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
|
||||
`sales_price` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
|
||||
`remark` TEXT,
|
||||
`status` TINYINT NOT NULL DEFAULT 1 COMMENT '1:enabled 0:disabled',
|
||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`deleted_at` DATETIME DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_product_id` (`product_id`),
|
||||
UNIQUE KEY `uk_product_name` (`product_name`),
|
||||
KEY `idx_color` (`color`),
|
||||
KEY `idx_location` (`location`),
|
||||
KEY `idx_status` (`status`),
|
||||
KEY `idx_deleted_at` (`deleted_at`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE `inv_stock_import_log` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`import_id` VARCHAR(32) NOT NULL,
|
||||
`file_name` VARCHAR(200) NOT NULL DEFAULT '',
|
||||
`total_count` INT NOT NULL DEFAULT 0,
|
||||
`success_count` INT NOT NULL DEFAULT 0,
|
||||
`fail_count` INT NOT NULL DEFAULT 0,
|
||||
`error_msg` TEXT,
|
||||
`operator` VARCHAR(50) NOT NULL DEFAULT '',
|
||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_import_id` (`import_id`),
|
||||
KEY `idx_created_at` (`created_at`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE `inv_stock_check` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`check_id` VARCHAR(32) NOT NULL,
|
||||
`check_no` VARCHAR(32) NOT NULL,
|
||||
`check_date` DATE NOT NULL,
|
||||
`checker` VARCHAR(50) NOT NULL DEFAULT '',
|
||||
`status` TINYINT NOT NULL DEFAULT 0 COMMENT '0:draft 1:in_progress 2:completed',
|
||||
`remark` TEXT,
|
||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_check_id` (`check_id`),
|
||||
UNIQUE KEY `uk_check_no` (`check_no`),
|
||||
KEY `idx_status` (`status`),
|
||||
KEY `idx_check_date` (`check_date`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE `inv_stock_check_detail` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`detail_id` VARCHAR(32) NOT NULL,
|
||||
`check_id` VARCHAR(32) NOT NULL,
|
||||
`product_id` VARCHAR(32) NOT NULL,
|
||||
`system_quantity` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
|
||||
`actual_quantity` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
|
||||
`diff_quantity` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
|
||||
`diff_amount` DECIMAL(12,2) NOT NULL DEFAULT 0.00,
|
||||
`remark` TEXT,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_detail_id` (`detail_id`),
|
||||
KEY `idx_check_id` (`check_id`),
|
||||
KEY `idx_product_id` (`product_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE `inv_stock_adjust` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`adjust_id` VARCHAR(32) NOT NULL,
|
||||
`adjust_no` VARCHAR(32) NOT NULL,
|
||||
`adjust_date` DATE NOT NULL,
|
||||
`adjust_reason` VARCHAR(50) NOT NULL DEFAULT '',
|
||||
`operator` VARCHAR(50) NOT NULL DEFAULT '',
|
||||
`approver` VARCHAR(50) NOT NULL DEFAULT '',
|
||||
`status` TINYINT NOT NULL DEFAULT 0 COMMENT '0:pending 1:approved 2:rejected',
|
||||
`remark` TEXT,
|
||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_adjust_id` (`adjust_id`),
|
||||
UNIQUE KEY `uk_adjust_no` (`adjust_no`),
|
||||
KEY `idx_status` (`status`),
|
||||
KEY `idx_adjust_date` (`adjust_date`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE `inv_stock_adjust_detail` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`detail_id` VARCHAR(32) NOT NULL,
|
||||
`adjust_id` VARCHAR(32) NOT NULL,
|
||||
`product_id` VARCHAR(32) NOT NULL,
|
||||
`before_quantity` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
|
||||
`adjust_quantity` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
|
||||
`after_quantity` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
|
||||
`remark` TEXT,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_detail_id` (`detail_id`),
|
||||
KEY `idx_adjust_id` (`adjust_id`),
|
||||
KEY `idx_product_id` (`product_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Casbin policy storage
|
||||
CREATE TABLE `casbin_rule` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`ptype` VARCHAR(100) NOT NULL DEFAULT '',
|
||||
`v0` VARCHAR(100) NOT NULL DEFAULT '',
|
||||
`v1` VARCHAR(100) NOT NULL DEFAULT '',
|
||||
`v2` VARCHAR(100) NOT NULL DEFAULT '',
|
||||
`v3` VARCHAR(100) NOT NULL DEFAULT '',
|
||||
`v4` VARCHAR(100) NOT NULL DEFAULT '',
|
||||
`v5` VARCHAR(100) NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_casbin` (`ptype`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- ==================== Initial Data ====================
|
||||
|
||||
-- Default admin user (password: admin123, bcrypt hashed)
|
||||
INSERT INTO `sys_user` (`user_id`, `username`, `password`, `salt`, `real_name`, `status`)
|
||||
VALUES ('u_admin_001', 'admin', '$2a$10$S5XPWRXUnexAt9KJw2CefeHMa6aude7j5dm5qgWM1YMQAAwRgsGXa', 'bcrypt', 'System Admin', 1);
|
||||
|
||||
-- Default roles
|
||||
INSERT INTO `sys_role` (`role_id`, `role_name`, `role_key`, `role_desc`, `sort_order`, `status`) VALUES
|
||||
('r_001', '系统管理员', 'admin', 'Full system access', 1, 1),
|
||||
('r_002', '仓库管理员', 'warehouse', 'Warehouse management access', 2, 1),
|
||||
('r_003', '普通用户', 'user', 'Basic read access', 3, 1);
|
||||
|
||||
-- Assign admin role to admin user
|
||||
INSERT INTO `sys_user_role` (`user_id`, `role_id`) VALUES ('u_admin_001', 'r_001');
|
||||
|
||||
-- Default menus
|
||||
INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `menu_name`, `menu_type`, `path`, `component`, `permission`, `icon`, `sort_order`, `visible`, `status`) VALUES
|
||||
-- Dashboard
|
||||
('m_001', '', '首页', 1, '/dashboard', './Dashboard', '', 'DashboardOutlined', 1, 1, 1),
|
||||
-- System Management
|
||||
('m_100', '', '系统管理', 1, '/system', '', '', 'SettingOutlined', 100, 1, 1),
|
||||
('m_101', 'm_100', '用户管理', 2, '/system/users', './System/Users', 'system:user:list', 'UserOutlined', 1, 1, 1),
|
||||
('m_102', 'm_100', '角色管理', 2, '/system/roles', './System/Roles', 'system:role:list', 'TeamOutlined', 2, 1, 1),
|
||||
('m_103', 'm_100', '菜单管理', 2, '/system/menus', './System/Menus', 'system:menu:list', 'MenuOutlined', 3, 1, 1),
|
||||
('m_104', 'm_100', '操作日志', 2, '/system/logs', './System/Logs', 'system:log:list', 'FileTextOutlined', 4, 1, 1),
|
||||
('m_105', 'm_100', '系统配置', 2, '/system/configs', './System/Configs', 'system:config:list', 'ToolOutlined', 5, 1, 1),
|
||||
-- Inventory Management
|
||||
('m_200', '', '库存管理', 1, '/inventory', '', '', 'DatabaseOutlined', 200, 1, 1),
|
||||
('m_201', 'm_200', '产品档案', 2, '/inventory/products', './Inventory/Products', 'inventory:product:list', 'AppstoreOutlined', 1, 1, 1),
|
||||
('m_202', 'm_200', '库存查询', 2, '/inventory/stocks', './Inventory/Stocks', 'inventory:stock:list', 'SearchOutlined', 2, 1, 1),
|
||||
('m_203', 'm_200', '库存统计', 2, '/inventory/stats', './Inventory/Stats', 'inventory:stock:stats', 'BarChartOutlined', 3, 1, 1),
|
||||
('m_204', 'm_200', '库存盘点', 2, '/inventory/checks', './Inventory/Checks', 'inventory:check:list', 'AuditOutlined', 4, 1, 1),
|
||||
('m_205', 'm_200', '库存调整', 2, '/inventory/adjusts', './Inventory/Adjusts', 'inventory:adjust:list', 'SwapOutlined', 5, 1, 1),
|
||||
('m_206', 'm_200', 'Excel导入', 2, '/inventory/import', './Inventory/Import', 'inventory:import:exec', 'ImportOutlined', 6, 1, 1);
|
||||
|
||||
-- Assign all menus to admin role
|
||||
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`)
|
||||
SELECT 'r_001', `menu_id` FROM `sys_menu`;
|
||||
|
||||
-- Assign inventory menus to warehouse role
|
||||
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`) VALUES
|
||||
('r_002', 'm_001'),
|
||||
('r_002', 'm_200'), ('r_002', 'm_201'), ('r_002', 'm_202'),
|
||||
('r_002', 'm_203'), ('r_002', 'm_204'), ('r_002', 'm_205'), ('r_002', 'm_206');
|
||||
|
||||
-- Default Casbin policies
|
||||
INSERT INTO `casbin_rule` (`ptype`, `v0`, `v1`, `v2`) VALUES
|
||||
('p', 'admin', '/api/v1/*', '*'),
|
||||
('p', 'warehouse', '/api/v1/auth/*', '*'),
|
||||
('p', 'warehouse', '/api/v1/inventory/*', '*'),
|
||||
('p', 'user', '/api/v1/auth/*', '*'),
|
||||
('p', 'user', '/api/v1/inventory/products', 'GET'),
|
||||
('p', 'user', '/api/v1/inventory/stocks', 'GET'),
|
||||
('p', 'user', '/api/v1/inventory/stocks/*', 'GET');
|
||||
|
||||
-- Default system configs
|
||||
INSERT INTO `sys_config` (`config_id`, `config_key`, `config_value`, `config_name`, `config_group`, `remark`) VALUES
|
||||
('c_001', 'sys_name', 'muyuqingfeng仓储管理系统', 'System Name', 'basic', 'System display name'),
|
||||
('c_002', 'sys_logo', '', 'System Logo', 'basic', 'System logo URL'),
|
||||
('c_003', 'upload_max_size', '10', 'Upload Max Size (MB)', 'upload', 'Maximum file upload size'),
|
||||
('c_004', 'upload_allowed_types', 'jpg,jpeg,png,gif,xlsx,xls,csv', 'Allowed Upload Types', 'upload', 'Allowed file extensions');
|
||||
34
deploy/nginx/nginx.conf
Normal file
34
deploy/nginx/nginx.conf
Normal file
@ -0,0 +1,34 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Frontend SPA
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# API proxy
|
||||
location /api/ {
|
||||
proxy_pass http://gateway:8888;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Upload files
|
||||
location /uploads/ {
|
||||
alias /usr/share/nginx/uploads/;
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# Static assets cache
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
}
|
||||
3
gateway/etc/gateway-api.yaml
Normal file
3
gateway/etc/gateway-api.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
Name: gateway-api
|
||||
Host: 0.0.0.0
|
||||
Port: 8888
|
||||
26
gateway/etc/gateway.yaml
Normal file
26
gateway/etc/gateway.yaml
Normal file
@ -0,0 +1,26 @@
|
||||
Name: gateway-api
|
||||
Host: 0.0.0.0
|
||||
Port: 8888
|
||||
|
||||
Auth:
|
||||
AccessSecret: muyu-wms-jwt-secret-key-2026
|
||||
AccessExpire: 7200
|
||||
|
||||
SystemRpc:
|
||||
Etcd:
|
||||
Hosts:
|
||||
- 127.0.0.1:2379
|
||||
Key: system.rpc
|
||||
NonBlock: true
|
||||
|
||||
InventoryRpc:
|
||||
Etcd:
|
||||
Hosts:
|
||||
- 127.0.0.1:2379
|
||||
Key: inventory.rpc
|
||||
NonBlock: true
|
||||
|
||||
Log:
|
||||
ServiceName: gateway-api
|
||||
Mode: console
|
||||
Level: info
|
||||
638
gateway/gateway.api
Normal file
638
gateway/gateway.api
Normal file
@ -0,0 +1,638 @@
|
||||
syntax = "v1"
|
||||
|
||||
info (
|
||||
title: "Muyu WMS Gateway API"
|
||||
desc: "Warehouse Management System API Gateway"
|
||||
author: "muyu"
|
||||
version: "1.0"
|
||||
)
|
||||
|
||||
// ==================== Common Types ====================
|
||||
type IdResp {
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
type PageReq {
|
||||
Page int64 `form:"page,default=1"`
|
||||
PageSize int64 `form:"pageSize,default=20"`
|
||||
}
|
||||
|
||||
// ==================== Auth Types ====================
|
||||
type (
|
||||
LoginReq {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
LoginResp {
|
||||
Token string `json:"token"`
|
||||
UserInfo UserInfo `json:"userInfo"`
|
||||
}
|
||||
ChangePasswordReq {
|
||||
OldPassword string `json:"oldPassword"`
|
||||
NewPassword string `json:"newPassword"`
|
||||
}
|
||||
)
|
||||
|
||||
// ==================== User Types ====================
|
||||
type (
|
||||
UserInfo {
|
||||
UserId string `json:"userId"`
|
||||
Username string `json:"username"`
|
||||
RealName string `json:"realName"`
|
||||
Phone string `json:"phone"`
|
||||
Email string `json:"email"`
|
||||
Avatar string `json:"avatar"`
|
||||
Status int64 `json:"status"`
|
||||
RoleId string `json:"roleId"`
|
||||
RoleName string `json:"roleName"`
|
||||
LastLoginTime string `json:"lastLoginTime"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
}
|
||||
CreateUserReq {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
RealName string `json:"realName"`
|
||||
Phone string `json:"phone,optional"`
|
||||
Email string `json:"email,optional"`
|
||||
RoleId string `json:"roleId"`
|
||||
}
|
||||
UpdateUserReq {
|
||||
RealName string `json:"realName,optional"`
|
||||
Phone string `json:"phone,optional"`
|
||||
Email string `json:"email,optional"`
|
||||
RoleId string `json:"roleId,optional"`
|
||||
Avatar string `json:"avatar,optional"`
|
||||
}
|
||||
UpdateUserStatusReq {
|
||||
Status int64 `json:"status"`
|
||||
}
|
||||
ListUserReq {
|
||||
Page int64 `form:"page,default=1"`
|
||||
PageSize int64 `form:"pageSize,default=20"`
|
||||
Username string `form:"username,optional"`
|
||||
RealName string `form:"realName,optional"`
|
||||
Phone string `form:"phone,optional"`
|
||||
Status int64 `form:"status,optional,default=-1"`
|
||||
}
|
||||
ListUserResp {
|
||||
Total int64 `json:"total"`
|
||||
List []UserInfo `json:"list"`
|
||||
}
|
||||
)
|
||||
|
||||
// ==================== Role Types ====================
|
||||
type (
|
||||
RoleInfo {
|
||||
RoleId string `json:"roleId"`
|
||||
RoleName string `json:"roleName"`
|
||||
RoleKey string `json:"roleKey"`
|
||||
RoleDesc string `json:"roleDesc"`
|
||||
SortOrder int64 `json:"sortOrder"`
|
||||
Status int64 `json:"status"`
|
||||
MenuIds []string `json:"menuIds"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
}
|
||||
CreateRoleReq {
|
||||
RoleName string `json:"roleName"`
|
||||
RoleKey string `json:"roleKey"`
|
||||
RoleDesc string `json:"roleDesc,optional"`
|
||||
SortOrder int64 `json:"sortOrder,optional"`
|
||||
}
|
||||
UpdateRoleReq {
|
||||
RoleName string `json:"roleName,optional"`
|
||||
RoleKey string `json:"roleKey,optional"`
|
||||
RoleDesc string `json:"roleDesc,optional"`
|
||||
SortOrder int64 `json:"sortOrder,optional"`
|
||||
}
|
||||
SetRolePermissionsReq {
|
||||
MenuIds []string `json:"menuIds"`
|
||||
}
|
||||
ListRoleReq {
|
||||
Page int64 `form:"page,default=1"`
|
||||
PageSize int64 `form:"pageSize,default=20"`
|
||||
RoleName string `form:"roleName,optional"`
|
||||
Status int64 `form:"status,optional,default=-1"`
|
||||
}
|
||||
ListRoleResp {
|
||||
Total int64 `json:"total"`
|
||||
List []RoleInfo `json:"list"`
|
||||
}
|
||||
)
|
||||
|
||||
// ==================== Menu Types ====================
|
||||
type (
|
||||
MenuInfo {
|
||||
MenuId string `json:"menuId"`
|
||||
ParentId string `json:"parentId"`
|
||||
MenuName string `json:"menuName"`
|
||||
MenuType int64 `json:"menuType"`
|
||||
Path string `json:"path"`
|
||||
Component string `json:"component"`
|
||||
Permission string `json:"permission"`
|
||||
Icon string `json:"icon"`
|
||||
SortOrder int64 `json:"sortOrder"`
|
||||
Visible int64 `json:"visible"`
|
||||
Status int64 `json:"status"`
|
||||
Children []MenuInfo `json:"children"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
}
|
||||
CreateMenuReq {
|
||||
ParentId string `json:"parentId,optional"`
|
||||
MenuName string `json:"menuName"`
|
||||
MenuType int64 `json:"menuType"`
|
||||
Path string `json:"path,optional"`
|
||||
Component string `json:"component,optional"`
|
||||
Permission string `json:"permission,optional"`
|
||||
Icon string `json:"icon,optional"`
|
||||
SortOrder int64 `json:"sortOrder,optional"`
|
||||
}
|
||||
UpdateMenuReq {
|
||||
ParentId string `json:"parentId,optional"`
|
||||
MenuName string `json:"menuName,optional"`
|
||||
MenuType int64 `json:"menuType,optional"`
|
||||
Path string `json:"path,optional"`
|
||||
Component string `json:"component,optional"`
|
||||
Permission string `json:"permission,optional"`
|
||||
Icon string `json:"icon,optional"`
|
||||
SortOrder int64 `json:"sortOrder,optional"`
|
||||
Visible int64 `json:"visible,optional"`
|
||||
}
|
||||
ListMenuResp {
|
||||
List []MenuInfo `json:"list"`
|
||||
}
|
||||
)
|
||||
|
||||
// ==================== Operation Log Types ====================
|
||||
type (
|
||||
OperationLogInfo {
|
||||
LogId string `json:"logId"`
|
||||
UserId string `json:"userId"`
|
||||
Username string `json:"username"`
|
||||
Module string `json:"module"`
|
||||
Operation string `json:"operation"`
|
||||
Method string `json:"method"`
|
||||
Path string `json:"path"`
|
||||
Ip string `json:"ip"`
|
||||
Duration int64 `json:"duration"`
|
||||
Status int64 `json:"status"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
}
|
||||
ListLogReq {
|
||||
Page int64 `form:"page,default=1"`
|
||||
PageSize int64 `form:"pageSize,default=20"`
|
||||
Username string `form:"username,optional"`
|
||||
Module string `form:"module,optional"`
|
||||
Operation string `form:"operation,optional"`
|
||||
StartTime string `form:"startTime,optional"`
|
||||
EndTime string `form:"endTime,optional"`
|
||||
}
|
||||
ListLogResp {
|
||||
Total int64 `json:"total"`
|
||||
List []OperationLogInfo `json:"list"`
|
||||
}
|
||||
)
|
||||
|
||||
// ==================== Config Types ====================
|
||||
type (
|
||||
ConfigInfo {
|
||||
ConfigId string `json:"configId"`
|
||||
ConfigKey string `json:"configKey"`
|
||||
ConfigValue string `json:"configValue"`
|
||||
ConfigName string `json:"configName"`
|
||||
ConfigGroup string `json:"configGroup"`
|
||||
Remark string `json:"remark"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
}
|
||||
UpdateConfigReq {
|
||||
ConfigValue string `json:"configValue"`
|
||||
}
|
||||
ListConfigResp {
|
||||
List []ConfigInfo `json:"list"`
|
||||
}
|
||||
)
|
||||
|
||||
// ==================== Product Types ====================
|
||||
type (
|
||||
ProductInfo {
|
||||
ProductId string `json:"productId"`
|
||||
ProductName string `json:"productName"`
|
||||
ImageUrl string `json:"imageUrl"`
|
||||
Spec string `json:"spec"`
|
||||
Color string `json:"color"`
|
||||
UnitPieces int64 `json:"unitPieces"`
|
||||
UnitRolls int64 `json:"unitRolls"`
|
||||
StockQuantity string `json:"stockQuantity"`
|
||||
Location string `json:"location"`
|
||||
CostPrice string `json:"costPrice"`
|
||||
SalesPrice string `json:"salesPrice"`
|
||||
Remark string `json:"remark"`
|
||||
Status int64 `json:"status"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
}
|
||||
CreateProductReq {
|
||||
ProductName string `json:"productName"`
|
||||
ImageUrl string `json:"imageUrl,optional"`
|
||||
Spec string `json:"spec,optional"`
|
||||
Color string `json:"color,optional"`
|
||||
UnitPieces int64 `json:"unitPieces,optional"`
|
||||
UnitRolls int64 `json:"unitRolls,optional"`
|
||||
StockQuantity string `json:"stockQuantity,optional"`
|
||||
Location string `json:"location,optional"`
|
||||
CostPrice string `json:"costPrice,optional"`
|
||||
SalesPrice string `json:"salesPrice,optional"`
|
||||
Remark string `json:"remark,optional"`
|
||||
}
|
||||
UpdateProductReq {
|
||||
ProductName string `json:"productName,optional"`
|
||||
ImageUrl string `json:"imageUrl,optional"`
|
||||
Spec string `json:"spec,optional"`
|
||||
Color string `json:"color,optional"`
|
||||
UnitPieces int64 `json:"unitPieces,optional"`
|
||||
UnitRolls int64 `json:"unitRolls,optional"`
|
||||
StockQuantity string `json:"stockQuantity,optional"`
|
||||
Location string `json:"location,optional"`
|
||||
CostPrice string `json:"costPrice,optional"`
|
||||
SalesPrice string `json:"salesPrice,optional"`
|
||||
Remark string `json:"remark,optional"`
|
||||
}
|
||||
ListProductReq {
|
||||
Page int64 `form:"page,default=1"`
|
||||
PageSize int64 `form:"pageSize,default=20"`
|
||||
ProductName string `form:"productName,optional"`
|
||||
Spec string `form:"spec,optional"`
|
||||
Color string `form:"color,optional"`
|
||||
Location string `form:"location,optional"`
|
||||
Status int64 `form:"status,optional,default=-1"`
|
||||
}
|
||||
ListProductResp {
|
||||
Total int64 `json:"total"`
|
||||
List []ProductInfo `json:"list"`
|
||||
}
|
||||
ImportProductResp {
|
||||
TotalCount int64 `json:"totalCount"`
|
||||
SuccessCount int64 `json:"successCount"`
|
||||
FailCount int64 `json:"failCount"`
|
||||
ErrorMsg string `json:"errorMsg"`
|
||||
ImportId string `json:"importId"`
|
||||
}
|
||||
)
|
||||
|
||||
// ==================== Stock Statistics Types ====================
|
||||
type (
|
||||
StockSummaryResp {
|
||||
ProductCount int64 `json:"productCount"`
|
||||
TotalPieces int64 `json:"totalPieces"`
|
||||
TotalRolls int64 `json:"totalRolls"`
|
||||
TotalCostValue string `json:"totalCostValue"`
|
||||
TotalSalesValue string `json:"totalSalesValue"`
|
||||
}
|
||||
StockGroupItem {
|
||||
Name string `json:"name"`
|
||||
Count int64 `json:"count"`
|
||||
Quantity string `json:"quantity"`
|
||||
}
|
||||
StockGroupResp {
|
||||
List []StockGroupItem `json:"list"`
|
||||
}
|
||||
)
|
||||
|
||||
// ==================== Stock Check Types ====================
|
||||
type (
|
||||
StockCheckInfo {
|
||||
CheckId string `json:"checkId"`
|
||||
CheckNo string `json:"checkNo"`
|
||||
CheckDate string `json:"checkDate"`
|
||||
Checker string `json:"checker"`
|
||||
Status int64 `json:"status"`
|
||||
Remark string `json:"remark"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
Details []StockCheckDetailInfo `json:"details"`
|
||||
}
|
||||
StockCheckDetailInfo {
|
||||
DetailId string `json:"detailId"`
|
||||
CheckId string `json:"checkId"`
|
||||
ProductId string `json:"productId"`
|
||||
ProductName string `json:"productName"`
|
||||
SystemQuantity string `json:"systemQuantity"`
|
||||
ActualQuantity string `json:"actualQuantity"`
|
||||
DiffQuantity string `json:"diffQuantity"`
|
||||
DiffAmount string `json:"diffAmount"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
CreateStockCheckReq {
|
||||
CheckDate string `json:"checkDate"`
|
||||
Checker string `json:"checker"`
|
||||
Remark string `json:"remark,optional"`
|
||||
Details []StockCheckDetailReq `json:"details"`
|
||||
}
|
||||
StockCheckDetailReq {
|
||||
ProductId string `json:"productId"`
|
||||
ActualQuantity string `json:"actualQuantity"`
|
||||
Remark string `json:"remark,optional"`
|
||||
}
|
||||
UpdateStockCheckReq {
|
||||
Remark string `json:"remark,optional"`
|
||||
Details []StockCheckDetailReq `json:"details"`
|
||||
}
|
||||
ListStockCheckReq {
|
||||
Page int64 `form:"page,default=1"`
|
||||
PageSize int64 `form:"pageSize,default=20"`
|
||||
CheckNo string `form:"checkNo,optional"`
|
||||
Status int64 `form:"status,optional,default=-1"`
|
||||
StartDate string `form:"startDate,optional"`
|
||||
EndDate string `form:"endDate,optional"`
|
||||
}
|
||||
ListStockCheckResp {
|
||||
Total int64 `json:"total"`
|
||||
List []StockCheckInfo `json:"list"`
|
||||
}
|
||||
)
|
||||
|
||||
// ==================== Stock Adjust Types ====================
|
||||
type (
|
||||
StockAdjustInfo {
|
||||
AdjustId string `json:"adjustId"`
|
||||
AdjustNo string `json:"adjustNo"`
|
||||
AdjustDate string `json:"adjustDate"`
|
||||
AdjustReason string `json:"adjustReason"`
|
||||
Operator string `json:"operator"`
|
||||
Approver string `json:"approver"`
|
||||
Status int64 `json:"status"`
|
||||
Remark string `json:"remark"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
Details []StockAdjustDetailInfo `json:"details"`
|
||||
}
|
||||
StockAdjustDetailInfo {
|
||||
DetailId string `json:"detailId"`
|
||||
AdjustId string `json:"adjustId"`
|
||||
ProductId string `json:"productId"`
|
||||
ProductName string `json:"productName"`
|
||||
BeforeQuantity string `json:"beforeQuantity"`
|
||||
AdjustQuantity string `json:"adjustQuantity"`
|
||||
AfterQuantity string `json:"afterQuantity"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
CreateStockAdjustReq {
|
||||
AdjustDate string `json:"adjustDate"`
|
||||
AdjustReason string `json:"adjustReason"`
|
||||
Remark string `json:"remark,optional"`
|
||||
Details []StockAdjustDetailReq `json:"details"`
|
||||
}
|
||||
StockAdjustDetailReq {
|
||||
ProductId string `json:"productId"`
|
||||
AdjustQuantity string `json:"adjustQuantity"`
|
||||
Remark string `json:"remark,optional"`
|
||||
}
|
||||
ApproveStockAdjustReq {
|
||||
Action int64 `json:"action"`
|
||||
}
|
||||
ListStockAdjustReq {
|
||||
Page int64 `form:"page,default=1"`
|
||||
PageSize int64 `form:"pageSize,default=20"`
|
||||
AdjustNo string `form:"adjustNo,optional"`
|
||||
AdjustReason string `form:"adjustReason,optional"`
|
||||
Status int64 `form:"status,optional,default=-1"`
|
||||
StartDate string `form:"startDate,optional"`
|
||||
EndDate string `form:"endDate,optional"`
|
||||
}
|
||||
ListStockAdjustResp {
|
||||
Total int64 `json:"total"`
|
||||
List []StockAdjustInfo `json:"list"`
|
||||
}
|
||||
)
|
||||
|
||||
// ==================== Services ====================
|
||||
// Auth - No JWT required
|
||||
@server (
|
||||
prefix: /api/v1/auth
|
||||
group: auth
|
||||
)
|
||||
service gateway-api {
|
||||
@handler LoginHandler
|
||||
post /login (LoginReq) returns (LoginResp)
|
||||
}
|
||||
|
||||
// Auth - JWT required
|
||||
@server (
|
||||
prefix: /api/v1/auth
|
||||
group: auth
|
||||
jwt: Auth
|
||||
)
|
||||
service gateway-api {
|
||||
@handler LogoutHandler
|
||||
post /logout returns (IdResp)
|
||||
|
||||
@handler GetUserInfoHandler
|
||||
get /info returns (UserInfo)
|
||||
|
||||
@handler ChangePasswordHandler
|
||||
put /password (ChangePasswordReq) returns (IdResp)
|
||||
}
|
||||
|
||||
// System - User Management
|
||||
@server (
|
||||
prefix: /api/v1/system
|
||||
group: system/user
|
||||
jwt: Auth
|
||||
middleware: AuthorityMiddleware
|
||||
)
|
||||
service gateway-api {
|
||||
@handler ListUserHandler
|
||||
get /users (ListUserReq) returns (ListUserResp)
|
||||
|
||||
@handler GetUserHandler
|
||||
get /users/:id returns (UserInfo)
|
||||
|
||||
@handler CreateUserHandler
|
||||
post /users (CreateUserReq) returns (IdResp)
|
||||
|
||||
@handler UpdateUserHandler
|
||||
put /users/:id (UpdateUserReq) returns (IdResp)
|
||||
|
||||
@handler DeleteUserHandler
|
||||
delete /users/:id returns (IdResp)
|
||||
|
||||
@handler UpdateUserStatusHandler
|
||||
put /users/:id/status (UpdateUserStatusReq) returns (IdResp)
|
||||
}
|
||||
|
||||
// System - Role Management
|
||||
@server (
|
||||
prefix: /api/v1/system
|
||||
group: system/role
|
||||
jwt: Auth
|
||||
middleware: AuthorityMiddleware
|
||||
)
|
||||
service gateway-api {
|
||||
@handler ListRoleHandler
|
||||
get /roles (ListRoleReq) returns (ListRoleResp)
|
||||
|
||||
@handler GetRoleHandler
|
||||
get /roles/:id returns (RoleInfo)
|
||||
|
||||
@handler CreateRoleHandler
|
||||
post /roles (CreateRoleReq) returns (IdResp)
|
||||
|
||||
@handler UpdateRoleHandler
|
||||
put /roles/:id (UpdateRoleReq) returns (IdResp)
|
||||
|
||||
@handler DeleteRoleHandler
|
||||
delete /roles/:id returns (IdResp)
|
||||
|
||||
@handler SetRolePermissionsHandler
|
||||
put /roles/:id/permissions (SetRolePermissionsReq) returns (IdResp)
|
||||
}
|
||||
|
||||
// System - Menu Management
|
||||
@server (
|
||||
prefix: /api/v1/system
|
||||
group: system/menu
|
||||
jwt: Auth
|
||||
middleware: AuthorityMiddleware
|
||||
)
|
||||
service gateway-api {
|
||||
@handler ListMenuHandler
|
||||
get /menus returns (ListMenuResp)
|
||||
|
||||
@handler GetMenuHandler
|
||||
get /menus/:id returns (MenuInfo)
|
||||
|
||||
@handler CreateMenuHandler
|
||||
post /menus (CreateMenuReq) returns (IdResp)
|
||||
|
||||
@handler UpdateMenuHandler
|
||||
put /menus/:id (UpdateMenuReq) returns (IdResp)
|
||||
|
||||
@handler DeleteMenuHandler
|
||||
delete /menus/:id returns (IdResp)
|
||||
}
|
||||
|
||||
// System - Operation Logs
|
||||
@server (
|
||||
prefix: /api/v1/system
|
||||
group: system/log
|
||||
jwt: Auth
|
||||
middleware: AuthorityMiddleware
|
||||
)
|
||||
service gateway-api {
|
||||
@handler ListLogHandler
|
||||
get /logs (ListLogReq) returns (ListLogResp)
|
||||
}
|
||||
|
||||
// System - Config
|
||||
@server (
|
||||
prefix: /api/v1/system
|
||||
group: system/config
|
||||
jwt: Auth
|
||||
middleware: AuthorityMiddleware
|
||||
)
|
||||
service gateway-api {
|
||||
@handler ListConfigHandler
|
||||
get /configs returns (ListConfigResp)
|
||||
|
||||
@handler UpdateConfigHandler
|
||||
put /configs/:key (UpdateConfigReq) returns (IdResp)
|
||||
}
|
||||
|
||||
// Inventory - Product Management
|
||||
@server (
|
||||
prefix: /api/v1/inventory
|
||||
group: inventory/product
|
||||
jwt: Auth
|
||||
middleware: AuthorityMiddleware
|
||||
)
|
||||
service gateway-api {
|
||||
@handler ListProductHandler
|
||||
get /products (ListProductReq) returns (ListProductResp)
|
||||
|
||||
@handler GetProductHandler
|
||||
get /products/:id returns (ProductInfo)
|
||||
|
||||
@handler CreateProductHandler
|
||||
post /products (CreateProductReq) returns (IdResp)
|
||||
|
||||
@handler UpdateProductHandler
|
||||
put /products/:id (UpdateProductReq) returns (IdResp)
|
||||
|
||||
@handler DeleteProductHandler
|
||||
delete /products/:id returns (IdResp)
|
||||
|
||||
@handler ImportProductHandler
|
||||
post /products/import returns (ImportProductResp)
|
||||
|
||||
@handler ExportProductHandler
|
||||
get /products/export
|
||||
}
|
||||
|
||||
// Inventory - Stock Query & Statistics
|
||||
@server (
|
||||
prefix: /api/v1/inventory
|
||||
group: inventory/stock
|
||||
jwt: Auth
|
||||
middleware: AuthorityMiddleware
|
||||
)
|
||||
service gateway-api {
|
||||
@handler ListStockHandler
|
||||
get /stocks (ListProductReq) returns (ListProductResp)
|
||||
|
||||
@handler GetStockSummaryHandler
|
||||
get /stocks/summary returns (StockSummaryResp)
|
||||
|
||||
@handler GetStockByColorHandler
|
||||
get /stocks/by-color returns (StockGroupResp)
|
||||
|
||||
@handler GetStockByLocationHandler
|
||||
get /stocks/by-location returns (StockGroupResp)
|
||||
}
|
||||
|
||||
// Inventory - Stock Check
|
||||
@server (
|
||||
prefix: /api/v1/inventory
|
||||
group: inventory/check
|
||||
jwt: Auth
|
||||
middleware: AuthorityMiddleware
|
||||
)
|
||||
service gateway-api {
|
||||
@handler ListStockCheckHandler
|
||||
get /checks (ListStockCheckReq) returns (ListStockCheckResp)
|
||||
|
||||
@handler GetStockCheckHandler
|
||||
get /checks/:id returns (StockCheckInfo)
|
||||
|
||||
@handler CreateStockCheckHandler
|
||||
post /checks (CreateStockCheckReq) returns (IdResp)
|
||||
|
||||
@handler UpdateStockCheckHandler
|
||||
put /checks/:id (UpdateStockCheckReq) returns (IdResp)
|
||||
|
||||
@handler ConfirmStockCheckHandler
|
||||
post /checks/:id/confirm returns (IdResp)
|
||||
}
|
||||
|
||||
// Inventory - Stock Adjust
|
||||
@server (
|
||||
prefix: /api/v1/inventory
|
||||
group: inventory/adjust
|
||||
jwt: Auth
|
||||
middleware: AuthorityMiddleware
|
||||
)
|
||||
service gateway-api {
|
||||
@handler ListStockAdjustHandler
|
||||
get /adjusts (ListStockAdjustReq) returns (ListStockAdjustResp)
|
||||
|
||||
@handler GetStockAdjustHandler
|
||||
get /adjusts/:id returns (StockAdjustInfo)
|
||||
|
||||
@handler CreateStockAdjustHandler
|
||||
post /adjusts (CreateStockAdjustReq) returns (IdResp)
|
||||
|
||||
@handler ApproveStockAdjustHandler
|
||||
post /adjusts/:id/approve (ApproveStockAdjustReq) returns (IdResp)
|
||||
}
|
||||
|
||||
56
gateway/gateway.go
Normal file
56
gateway/gateway.go
Normal file
@ -0,0 +1,56 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"muyu-apiserver/gateway/internal/config"
|
||||
"muyu-apiserver/gateway/internal/handler"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/gateway-api.yaml", "the config file")
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data interface{} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
conf.MustLoad(*configFile, &c)
|
||||
|
||||
server := rest.MustNewServer(c.RestConf, rest.WithCors())
|
||||
defer server.Stop()
|
||||
|
||||
httpx.SetErrorHandlerCtx(func(ctx context.Context, err error) (int, interface{}) {
|
||||
s, ok := status.FromError(err)
|
||||
if ok {
|
||||
return http.StatusOK, &Response{Code: int(s.Code()), Msg: s.Message()}
|
||||
}
|
||||
return http.StatusOK, &Response{Code: 1001, Msg: err.Error()}
|
||||
})
|
||||
|
||||
httpx.SetOkHandler(func(ctx context.Context, a interface{}) interface{} {
|
||||
return &Response{Code: 0, Msg: "success", Data: a}
|
||||
})
|
||||
|
||||
ctx := svc.NewServiceContext(c)
|
||||
handler.RegisterHandlers(server, ctx)
|
||||
|
||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||
server.Start()
|
||||
}
|
||||
19
gateway/internal/config/config.go
Normal file
19
gateway/internal/config/config.go
Normal file
@ -0,0 +1,19 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
Auth struct {
|
||||
AccessSecret string
|
||||
AccessExpire int64
|
||||
}
|
||||
SystemRpc zrpc.RpcClientConf
|
||||
InventoryRpc zrpc.RpcClientConf
|
||||
}
|
||||
31
gateway/internal/handler/auth/changePasswordHandler.go
Normal file
31
gateway/internal/handler/auth/changePasswordHandler.go
Normal file
@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package auth
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/auth"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func ChangePasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ChangePasswordReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := auth.NewChangePasswordLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ChangePassword(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
24
gateway/internal/handler/auth/getUserInfoHandler.go
Normal file
24
gateway/internal/handler/auth/getUserInfoHandler.go
Normal file
@ -0,0 +1,24 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package auth
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/auth"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func GetUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := auth.NewGetUserInfoLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetUserInfo()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
31
gateway/internal/handler/auth/loginHandler.go
Normal file
31
gateway/internal/handler/auth/loginHandler.go
Normal file
@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package auth
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/auth"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func LoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.LoginReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := auth.NewLoginLogic(r.Context(), svcCtx)
|
||||
resp, err := l.Login(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
24
gateway/internal/handler/auth/logoutHandler.go
Normal file
24
gateway/internal/handler/auth/logoutHandler.go
Normal file
@ -0,0 +1,24 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package auth
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/auth"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func LogoutHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := auth.NewLogoutLogic(r.Context(), svcCtx)
|
||||
resp, err := l.Logout()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package adjust
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/adjust"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func ApproveStockAdjustHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ApproveStockAdjustReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := adjust.NewApproveStockAdjustLogic(ctx, svcCtx)
|
||||
resp, err := l.ApproveStockAdjust(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package adjust
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/adjust"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func CreateStockAdjustHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateStockAdjustReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := adjust.NewCreateStockAdjustLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CreateStockAdjust(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package adjust
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/adjust"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func GetStockAdjustHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := adjust.NewGetStockAdjustLogic(ctx, svcCtx)
|
||||
resp, err := l.GetStockAdjust()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package adjust
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/adjust"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func ListStockAdjustHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ListStockAdjustReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := adjust.NewListStockAdjustLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ListStockAdjust(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/check"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func ConfirmStockCheckHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := check.NewConfirmStockCheckLogic(ctx, svcCtx)
|
||||
resp, err := l.ConfirmStockCheck()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package check
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/check"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func CreateStockCheckHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateStockCheckReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := check.NewCreateStockCheckLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CreateStockCheck(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/check"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func GetStockCheckHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := check.NewGetStockCheckLogic(ctx, svcCtx)
|
||||
resp, err := l.GetStockCheck()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package check
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/check"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func ListStockCheckHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ListStockCheckReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := check.NewListStockCheckLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ListStockCheck(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/check"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func UpdateStockCheckHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateStockCheckReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := check.NewUpdateStockCheckLogic(ctx, svcCtx)
|
||||
resp, err := l.UpdateStockCheck(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package product
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/product"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func CreateProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateProductReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := product.NewCreateProductLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CreateProduct(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/product"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func DeleteProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := product.NewDeleteProductLogic(ctx, svcCtx)
|
||||
resp, err := l.DeleteProduct()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package product
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/product"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func ExportProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := product.NewExportProductLogic(r.Context(), svcCtx)
|
||||
err := l.ExportProduct()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/product"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func GetProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := product.NewGetProductLogic(ctx, svcCtx)
|
||||
resp, err := l.GetProduct()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package product
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/product"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func ImportProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := product.NewImportProductLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ImportProduct()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package product
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/product"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func ListProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ListProductReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := product.NewListProductLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ListProduct(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/product"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func UpdateProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateProductReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := product.NewUpdateProductLogic(ctx, svcCtx)
|
||||
resp, err := l.UpdateProduct(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package stock
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/stock"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func GetStockByColorHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := stock.NewGetStockByColorLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetStockByColor()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package stock
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/stock"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func GetStockByLocationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := stock.NewGetStockByLocationLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetStockByLocation()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package stock
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/stock"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func GetStockSummaryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := stock.NewGetStockSummaryLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetStockSummary()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
31
gateway/internal/handler/inventory/stock/listStockHandler.go
Normal file
31
gateway/internal/handler/inventory/stock/listStockHandler.go
Normal file
@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package stock
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/inventory/stock"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func ListStockHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ListProductReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := stock.NewListStockLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ListStock(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
347
gateway/internal/handler/routes.go
Normal file
347
gateway/internal/handler/routes.go
Normal file
@ -0,0 +1,347 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.9.2
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
auth "muyu-apiserver/gateway/internal/handler/auth"
|
||||
inventoryadjust "muyu-apiserver/gateway/internal/handler/inventory/adjust"
|
||||
inventorycheck "muyu-apiserver/gateway/internal/handler/inventory/check"
|
||||
inventoryproduct "muyu-apiserver/gateway/internal/handler/inventory/product"
|
||||
inventorystock "muyu-apiserver/gateway/internal/handler/inventory/stock"
|
||||
systemconfig "muyu-apiserver/gateway/internal/handler/system/config"
|
||||
systemlog "muyu-apiserver/gateway/internal/handler/system/log"
|
||||
systemmenu "muyu-apiserver/gateway/internal/handler/system/menu"
|
||||
systemrole "muyu-apiserver/gateway/internal/handler/system/role"
|
||||
systemuser "muyu-apiserver/gateway/internal/handler/system/user"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/login",
|
||||
Handler: auth.LoginHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/api/v1/auth"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/info",
|
||||
Handler: auth.GetUserInfoHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/logout",
|
||||
Handler: auth.LogoutHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPut,
|
||||
Path: "/password",
|
||||
Handler: auth.ChangePasswordHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/v1/auth"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.AuthorityMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/adjusts",
|
||||
Handler: inventoryadjust.ListStockAdjustHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/adjusts",
|
||||
Handler: inventoryadjust.CreateStockAdjustHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/adjusts/:id",
|
||||
Handler: inventoryadjust.GetStockAdjustHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/adjusts/:id/approve",
|
||||
Handler: inventoryadjust.ApproveStockAdjustHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/v1/inventory"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.AuthorityMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/checks",
|
||||
Handler: inventorycheck.ListStockCheckHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/checks",
|
||||
Handler: inventorycheck.CreateStockCheckHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/checks/:id",
|
||||
Handler: inventorycheck.GetStockCheckHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPut,
|
||||
Path: "/checks/:id",
|
||||
Handler: inventorycheck.UpdateStockCheckHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/checks/:id/confirm",
|
||||
Handler: inventorycheck.ConfirmStockCheckHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/v1/inventory"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.AuthorityMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/products",
|
||||
Handler: inventoryproduct.ListProductHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/products",
|
||||
Handler: inventoryproduct.CreateProductHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/products/:id",
|
||||
Handler: inventoryproduct.GetProductHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPut,
|
||||
Path: "/products/:id",
|
||||
Handler: inventoryproduct.UpdateProductHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodDelete,
|
||||
Path: "/products/:id",
|
||||
Handler: inventoryproduct.DeleteProductHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/products/export",
|
||||
Handler: inventoryproduct.ExportProductHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/products/import",
|
||||
Handler: inventoryproduct.ImportProductHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/v1/inventory"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.AuthorityMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/stocks",
|
||||
Handler: inventorystock.ListStockHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/stocks/by-color",
|
||||
Handler: inventorystock.GetStockByColorHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/stocks/by-location",
|
||||
Handler: inventorystock.GetStockByLocationHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/stocks/summary",
|
||||
Handler: inventorystock.GetStockSummaryHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/v1/inventory"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.AuthorityMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/configs",
|
||||
Handler: systemconfig.ListConfigHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPut,
|
||||
Path: "/configs/:key",
|
||||
Handler: systemconfig.UpdateConfigHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/v1/system"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.AuthorityMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/logs",
|
||||
Handler: systemlog.ListLogHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/v1/system"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.AuthorityMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/menus",
|
||||
Handler: systemmenu.ListMenuHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/menus",
|
||||
Handler: systemmenu.CreateMenuHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/menus/:id",
|
||||
Handler: systemmenu.GetMenuHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPut,
|
||||
Path: "/menus/:id",
|
||||
Handler: systemmenu.UpdateMenuHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodDelete,
|
||||
Path: "/menus/:id",
|
||||
Handler: systemmenu.DeleteMenuHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/v1/system"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.AuthorityMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/roles",
|
||||
Handler: systemrole.ListRoleHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/roles",
|
||||
Handler: systemrole.CreateRoleHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/roles/:id",
|
||||
Handler: systemrole.GetRoleHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPut,
|
||||
Path: "/roles/:id",
|
||||
Handler: systemrole.UpdateRoleHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodDelete,
|
||||
Path: "/roles/:id",
|
||||
Handler: systemrole.DeleteRoleHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPut,
|
||||
Path: "/roles/:id/permissions",
|
||||
Handler: systemrole.SetRolePermissionsHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/v1/system"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.AuthorityMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/users",
|
||||
Handler: systemuser.ListUserHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/users",
|
||||
Handler: systemuser.CreateUserHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/users/:id",
|
||||
Handler: systemuser.GetUserHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPut,
|
||||
Path: "/users/:id",
|
||||
Handler: systemuser.UpdateUserHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodDelete,
|
||||
Path: "/users/:id",
|
||||
Handler: systemuser.DeleteUserHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPut,
|
||||
Path: "/users/:id/status",
|
||||
Handler: systemuser.UpdateUserStatusHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/v1/system"),
|
||||
)
|
||||
}
|
||||
24
gateway/internal/handler/system/config/listConfigHandler.go
Normal file
24
gateway/internal/handler/system/config/listConfigHandler.go
Normal file
@ -0,0 +1,24 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/system/config"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func ListConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := config.NewListConfigLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ListConfig()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/system/config"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func UpdateConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateConfigReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), "pathKey", pathvar.Vars(r)["key"])
|
||||
l := config.NewUpdateConfigLogic(ctx, svcCtx)
|
||||
resp, err := l.UpdateConfig(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
31
gateway/internal/handler/system/log/listLogHandler.go
Normal file
31
gateway/internal/handler/system/log/listLogHandler.go
Normal file
@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package log
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/system/log"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func ListLogHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ListLogReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := log.NewListLogLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ListLog(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
31
gateway/internal/handler/system/menu/createMenuHandler.go
Normal file
31
gateway/internal/handler/system/menu/createMenuHandler.go
Normal file
@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package menu
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/system/menu"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func CreateMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateMenuReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := menu.NewCreateMenuLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CreateMenu(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
24
gateway/internal/handler/system/menu/deleteMenuHandler.go
Normal file
24
gateway/internal/handler/system/menu/deleteMenuHandler.go
Normal file
@ -0,0 +1,24 @@
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/system/menu"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func DeleteMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := menu.NewDeleteMenuLogic(ctx, svcCtx)
|
||||
resp, err := l.DeleteMenu()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
24
gateway/internal/handler/system/menu/getMenuHandler.go
Normal file
24
gateway/internal/handler/system/menu/getMenuHandler.go
Normal file
@ -0,0 +1,24 @@
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/system/menu"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func GetMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := menu.NewGetMenuLogic(ctx, svcCtx)
|
||||
resp, err := l.GetMenu()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
24
gateway/internal/handler/system/menu/listMenuHandler.go
Normal file
24
gateway/internal/handler/system/menu/listMenuHandler.go
Normal file
@ -0,0 +1,24 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package menu
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/system/menu"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func ListMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := menu.NewListMenuLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ListMenu()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
31
gateway/internal/handler/system/menu/updateMenuHandler.go
Normal file
31
gateway/internal/handler/system/menu/updateMenuHandler.go
Normal file
@ -0,0 +1,31 @@
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/system/menu"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func UpdateMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateMenuReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := menu.NewUpdateMenuLogic(ctx, svcCtx)
|
||||
resp, err := l.UpdateMenu(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
31
gateway/internal/handler/system/role/createRoleHandler.go
Normal file
31
gateway/internal/handler/system/role/createRoleHandler.go
Normal file
@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package role
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/system/role"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func CreateRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateRoleReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := role.NewCreateRoleLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CreateRole(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
24
gateway/internal/handler/system/role/deleteRoleHandler.go
Normal file
24
gateway/internal/handler/system/role/deleteRoleHandler.go
Normal file
@ -0,0 +1,24 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/system/role"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func DeleteRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := role.NewDeleteRoleLogic(ctx, svcCtx)
|
||||
resp, err := l.DeleteRole()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
24
gateway/internal/handler/system/role/getRoleHandler.go
Normal file
24
gateway/internal/handler/system/role/getRoleHandler.go
Normal file
@ -0,0 +1,24 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/system/role"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func GetRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := role.NewGetRoleLogic(ctx, svcCtx)
|
||||
resp, err := l.GetRole()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
31
gateway/internal/handler/system/role/listRoleHandler.go
Normal file
31
gateway/internal/handler/system/role/listRoleHandler.go
Normal file
@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package role
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/system/role"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func ListRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ListRoleReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := role.NewListRoleLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ListRole(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/system/role"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func SetRolePermissionsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.SetRolePermissionsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := role.NewSetRolePermissionsLogic(ctx, svcCtx)
|
||||
resp, err := l.SetRolePermissions(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
31
gateway/internal/handler/system/role/updateRoleHandler.go
Normal file
31
gateway/internal/handler/system/role/updateRoleHandler.go
Normal file
@ -0,0 +1,31 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/system/role"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func UpdateRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateRoleReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := role.NewUpdateRoleLogic(ctx, svcCtx)
|
||||
resp, err := l.UpdateRole(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
31
gateway/internal/handler/system/user/createUserHandler.go
Normal file
31
gateway/internal/handler/system/user/createUserHandler.go
Normal file
@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/system/user"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func CreateUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateUserReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewCreateUserLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CreateUser(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
24
gateway/internal/handler/system/user/deleteUserHandler.go
Normal file
24
gateway/internal/handler/system/user/deleteUserHandler.go
Normal file
@ -0,0 +1,24 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/system/user"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func DeleteUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := user.NewDeleteUserLogic(ctx, svcCtx)
|
||||
resp, err := l.DeleteUser()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
24
gateway/internal/handler/system/user/getUserHandler.go
Normal file
24
gateway/internal/handler/system/user/getUserHandler.go
Normal file
@ -0,0 +1,24 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/system/user"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
)
|
||||
|
||||
func GetUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := user.NewGetUserLogic(ctx, svcCtx)
|
||||
resp, err := l.GetUser()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
31
gateway/internal/handler/system/user/listUserHandler.go
Normal file
31
gateway/internal/handler/system/user/listUserHandler.go
Normal file
@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"muyu-apiserver/gateway/internal/logic/system/user"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func ListUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ListUserReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewListUserLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ListUser(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
31
gateway/internal/handler/system/user/updateUserHandler.go
Normal file
31
gateway/internal/handler/system/user/updateUserHandler.go
Normal file
@ -0,0 +1,31 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/system/user"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func UpdateUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateUserReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := user.NewUpdateUserLogic(ctx, svcCtx)
|
||||
resp, err := l.UpdateUser(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
"muyu-apiserver/gateway/internal/logic/system/user"
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
)
|
||||
|
||||
func UpdateUserStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateUserStatusReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||
l := user.NewUpdateUserStatusLogic(ctx, svcCtx)
|
||||
resp, err := l.UpdateUserStatus(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
41
gateway/internal/logic/auth/changePasswordLogic.go
Normal file
41
gateway/internal/logic/auth/changePasswordLogic.go
Normal file
@ -0,0 +1,41 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/system/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ChangePasswordLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewChangePasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChangePasswordLogic {
|
||||
return &ChangePasswordLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ChangePasswordLogic) ChangePassword(req *types.ChangePasswordReq) (resp *types.IdResp, err error) {
|
||||
userId := ctxdata.GetUserId(l.ctx)
|
||||
|
||||
_, err = l.svcCtx.SystemRpc.ChangePassword(l.ctx, &pb.ChangePasswordReq{
|
||||
UserId: userId,
|
||||
OldPassword: req.OldPassword,
|
||||
NewPassword: req.NewPassword,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.IdResp{Id: userId}, nil
|
||||
}
|
||||
80
gateway/internal/logic/auth/getUserInfoLogic.go
Normal file
80
gateway/internal/logic/auth/getUserInfoLogic.go
Normal file
@ -0,0 +1,80 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/system/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetUserInfoLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoLogic {
|
||||
return &GetUserInfoLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
type UserInfoWithMenus struct {
|
||||
types.UserInfo
|
||||
MenuPaths []string `json:"menuPaths"`
|
||||
}
|
||||
|
||||
func (l *GetUserInfoLogic) GetUserInfo() (*UserInfoWithMenus, error) {
|
||||
userId := ctxdata.GetUserId(l.ctx)
|
||||
|
||||
rpcResp, err := l.svcCtx.SystemRpc.GetUser(l.ctx, &pb.GetUserReq{
|
||||
UserId: userId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get user's role menus
|
||||
var menuPaths []string
|
||||
if rpcResp.RoleId != "" {
|
||||
role, _ := l.svcCtx.SystemRpc.GetRole(l.ctx, &pb.GetRoleReq{RoleId: rpcResp.RoleId})
|
||||
if role != nil && len(role.MenuIds) > 0 {
|
||||
menuList, _ := l.svcCtx.SystemRpc.ListMenu(l.ctx, &pb.ListMenuReq{})
|
||||
if menuList != nil {
|
||||
menuIdSet := make(map[string]bool)
|
||||
for _, id := range role.MenuIds {
|
||||
menuIdSet[id] = true
|
||||
}
|
||||
for _, m := range menuList.List {
|
||||
if menuIdSet[m.MenuId] && m.Path != "" {
|
||||
menuPaths = append(menuPaths, m.Path)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &UserInfoWithMenus{
|
||||
UserInfo: types.UserInfo{
|
||||
UserId: rpcResp.UserId,
|
||||
Username: rpcResp.Username,
|
||||
RealName: rpcResp.RealName,
|
||||
Phone: rpcResp.Phone,
|
||||
Email: rpcResp.Email,
|
||||
Avatar: rpcResp.Avatar,
|
||||
Status: rpcResp.Status,
|
||||
RoleId: rpcResp.RoleId,
|
||||
RoleName: rpcResp.RoleName,
|
||||
LastLoginTime: rpcResp.LastLoginTime,
|
||||
CreatedAt: rpcResp.CreatedAt,
|
||||
UpdatedAt: rpcResp.UpdatedAt,
|
||||
},
|
||||
MenuPaths: menuPaths,
|
||||
}, nil
|
||||
}
|
||||
57
gateway/internal/logic/auth/loginLogic.go
Normal file
57
gateway/internal/logic/auth/loginLogic.go
Normal file
@ -0,0 +1,57 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
jwtpkg "muyu-apiserver/pkg/jwt"
|
||||
"muyu-apiserver/rpc/system/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type LoginLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
|
||||
return &LoginLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LoginLogic) Login(req *types.LoginReq) (resp *types.LoginResp, err error) {
|
||||
rpcResp, err := l.svcCtx.SystemRpc.Login(l.ctx, &pb.LoginReq{
|
||||
Username: req.Username,
|
||||
Password: req.Password,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
token, err := jwtpkg.GenerateToken(
|
||||
l.svcCtx.Config.Auth.AccessSecret,
|
||||
l.svcCtx.Config.Auth.AccessExpire,
|
||||
rpcResp.UserId,
|
||||
rpcResp.RoleKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.LoginResp{
|
||||
Token: token,
|
||||
UserInfo: types.UserInfo{
|
||||
UserId: rpcResp.UserId,
|
||||
Username: rpcResp.Username,
|
||||
RealName: rpcResp.RealName,
|
||||
Avatar: rpcResp.Avatar,
|
||||
RoleName: rpcResp.RoleName,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
28
gateway/internal/logic/auth/logoutLogic.go
Normal file
28
gateway/internal/logic/auth/logoutLogic.go
Normal file
@ -0,0 +1,28 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type LogoutLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewLogoutLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogoutLogic {
|
||||
return &LogoutLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LogoutLogic) Logout() (resp *types.IdResp, err error) {
|
||||
return &types.IdResp{Id: ""}, nil
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package adjust
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/inventory/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ApproveStockAdjustLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewApproveStockAdjustLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApproveStockAdjustLogic {
|
||||
return &ApproveStockAdjustLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ApproveStockAdjustLogic) ApproveStockAdjust(req *types.ApproveStockAdjustReq) (resp *types.IdResp, err error) {
|
||||
id := ctxdata.GetPathId(l.ctx)
|
||||
userId := ctxdata.GetUserId(l.ctx)
|
||||
|
||||
_, err = l.svcCtx.InventoryRpc.ApproveStockAdjust(l.ctx, &pb.ApproveStockAdjustReq{
|
||||
AdjustId: id,
|
||||
Approver: userId,
|
||||
Action: req.Action,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.IdResp{Id: id}, nil
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package adjust
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/inventory/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateStockAdjustLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCreateStockAdjustLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateStockAdjustLogic {
|
||||
return &CreateStockAdjustLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateStockAdjustLogic) CreateStockAdjust(req *types.CreateStockAdjustReq) (resp *types.IdResp, err error) {
|
||||
userId := ctxdata.GetUserId(l.ctx)
|
||||
|
||||
details := make([]*pb.StockAdjustDetailReq, 0, len(req.Details))
|
||||
for _, d := range req.Details {
|
||||
details = append(details, &pb.StockAdjustDetailReq{
|
||||
ProductId: d.ProductId,
|
||||
AdjustQuantity: d.AdjustQuantity,
|
||||
Remark: d.Remark,
|
||||
})
|
||||
}
|
||||
|
||||
rpcResp, err := l.svcCtx.InventoryRpc.CreateStockAdjust(l.ctx, &pb.CreateStockAdjustReq{
|
||||
AdjustDate: req.AdjustDate,
|
||||
AdjustReason: req.AdjustReason,
|
||||
Operator: userId,
|
||||
Remark: req.Remark,
|
||||
Details: details,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.IdResp{Id: rpcResp.Id}, nil
|
||||
}
|
||||
@ -0,0 +1,65 @@
|
||||
package adjust
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/inventory/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetStockAdjustLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetStockAdjustLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetStockAdjustLogic {
|
||||
return &GetStockAdjustLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetStockAdjustLogic) GetStockAdjust() (resp *types.StockAdjustInfo, err error) {
|
||||
id := ctxdata.GetPathId(l.ctx)
|
||||
|
||||
rpcResp, err := l.svcCtx.InventoryRpc.GetStockAdjust(l.ctx, &pb.GetStockAdjustReq{
|
||||
AdjustId: id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
details := make([]types.StockAdjustDetailInfo, 0, len(rpcResp.Details))
|
||||
for _, d := range rpcResp.Details {
|
||||
details = append(details, types.StockAdjustDetailInfo{
|
||||
DetailId: d.DetailId,
|
||||
AdjustId: d.AdjustId,
|
||||
ProductId: d.ProductId,
|
||||
ProductName: d.ProductName,
|
||||
BeforeQuantity: d.BeforeQuantity,
|
||||
AdjustQuantity: d.AdjustQuantity,
|
||||
AfterQuantity: d.AfterQuantity,
|
||||
Remark: d.Remark,
|
||||
})
|
||||
}
|
||||
|
||||
return &types.StockAdjustInfo{
|
||||
AdjustId: rpcResp.AdjustId,
|
||||
AdjustNo: rpcResp.AdjustNo,
|
||||
AdjustDate: rpcResp.AdjustDate,
|
||||
AdjustReason: rpcResp.AdjustReason,
|
||||
Operator: rpcResp.Operator,
|
||||
Approver: rpcResp.Approver,
|
||||
Status: rpcResp.Status,
|
||||
Remark: rpcResp.Remark,
|
||||
CreatedAt: rpcResp.CreatedAt,
|
||||
UpdatedAt: rpcResp.UpdatedAt,
|
||||
Details: details,
|
||||
}, nil
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
package adjust
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/rpc/inventory/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ListStockAdjustLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewListStockAdjustLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListStockAdjustLogic {
|
||||
return &ListStockAdjustLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ListStockAdjustLogic) ListStockAdjust(req *types.ListStockAdjustReq) (resp *types.ListStockAdjustResp, err error) {
|
||||
rpcResp, err := l.svcCtx.InventoryRpc.ListStockAdjust(l.ctx, &pb.ListStockAdjustReq{
|
||||
Page: req.Page,
|
||||
PageSize: req.PageSize,
|
||||
AdjustNo: req.AdjustNo,
|
||||
AdjustReason: req.AdjustReason,
|
||||
Status: req.Status,
|
||||
StartDate: req.StartDate,
|
||||
EndDate: req.EndDate,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]types.StockAdjustInfo, 0, len(rpcResp.List))
|
||||
for _, a := range rpcResp.List {
|
||||
details := make([]types.StockAdjustDetailInfo, 0, len(a.Details))
|
||||
for _, d := range a.Details {
|
||||
details = append(details, types.StockAdjustDetailInfo{
|
||||
DetailId: d.DetailId,
|
||||
AdjustId: d.AdjustId,
|
||||
ProductId: d.ProductId,
|
||||
ProductName: d.ProductName,
|
||||
BeforeQuantity: d.BeforeQuantity,
|
||||
AdjustQuantity: d.AdjustQuantity,
|
||||
AfterQuantity: d.AfterQuantity,
|
||||
Remark: d.Remark,
|
||||
})
|
||||
}
|
||||
|
||||
list = append(list, types.StockAdjustInfo{
|
||||
AdjustId: a.AdjustId,
|
||||
AdjustNo: a.AdjustNo,
|
||||
AdjustDate: a.AdjustDate,
|
||||
AdjustReason: a.AdjustReason,
|
||||
Operator: a.Operator,
|
||||
Approver: a.Approver,
|
||||
Status: a.Status,
|
||||
Remark: a.Remark,
|
||||
CreatedAt: a.CreatedAt,
|
||||
UpdatedAt: a.UpdatedAt,
|
||||
Details: details,
|
||||
})
|
||||
}
|
||||
|
||||
return &types.ListStockAdjustResp{
|
||||
Total: rpcResp.Total,
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/inventory/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ConfirmStockCheckLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewConfirmStockCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ConfirmStockCheckLogic {
|
||||
return &ConfirmStockCheckLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ConfirmStockCheckLogic) ConfirmStockCheck() (resp *types.IdResp, err error) {
|
||||
id := ctxdata.GetPathId(l.ctx)
|
||||
userId := ctxdata.GetUserId(l.ctx)
|
||||
|
||||
_, err = l.svcCtx.InventoryRpc.ConfirmStockCheck(l.ctx, &pb.ConfirmStockCheckReq{
|
||||
CheckId: id,
|
||||
Operator: userId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.IdResp{Id: id}, nil
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/rpc/inventory/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateStockCheckLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCreateStockCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateStockCheckLogic {
|
||||
return &CreateStockCheckLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateStockCheckLogic) CreateStockCheck(req *types.CreateStockCheckReq) (resp *types.IdResp, err error) {
|
||||
details := make([]*pb.StockCheckDetailReq, 0, len(req.Details))
|
||||
for _, d := range req.Details {
|
||||
details = append(details, &pb.StockCheckDetailReq{
|
||||
ProductId: d.ProductId,
|
||||
ActualQuantity: d.ActualQuantity,
|
||||
Remark: d.Remark,
|
||||
})
|
||||
}
|
||||
|
||||
rpcResp, err := l.svcCtx.InventoryRpc.CreateStockCheck(l.ctx, &pb.CreateStockCheckReq{
|
||||
CheckDate: req.CheckDate,
|
||||
Checker: req.Checker,
|
||||
Remark: req.Remark,
|
||||
Details: details,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.IdResp{Id: rpcResp.Id}, nil
|
||||
}
|
||||
64
gateway/internal/logic/inventory/check/getStockCheckLogic.go
Normal file
64
gateway/internal/logic/inventory/check/getStockCheckLogic.go
Normal file
@ -0,0 +1,64 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/inventory/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetStockCheckLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetStockCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetStockCheckLogic {
|
||||
return &GetStockCheckLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetStockCheckLogic) GetStockCheck() (resp *types.StockCheckInfo, err error) {
|
||||
id := ctxdata.GetPathId(l.ctx)
|
||||
|
||||
rpcResp, err := l.svcCtx.InventoryRpc.GetStockCheck(l.ctx, &pb.GetStockCheckReq{
|
||||
CheckId: id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
details := make([]types.StockCheckDetailInfo, 0, len(rpcResp.Details))
|
||||
for _, d := range rpcResp.Details {
|
||||
details = append(details, types.StockCheckDetailInfo{
|
||||
DetailId: d.DetailId,
|
||||
CheckId: d.CheckId,
|
||||
ProductId: d.ProductId,
|
||||
ProductName: d.ProductName,
|
||||
SystemQuantity: d.SystemQuantity,
|
||||
ActualQuantity: d.ActualQuantity,
|
||||
DiffQuantity: d.DiffQuantity,
|
||||
DiffAmount: d.DiffAmount,
|
||||
Remark: d.Remark,
|
||||
})
|
||||
}
|
||||
|
||||
return &types.StockCheckInfo{
|
||||
CheckId: rpcResp.CheckId,
|
||||
CheckNo: rpcResp.CheckNo,
|
||||
CheckDate: rpcResp.CheckDate,
|
||||
Checker: rpcResp.Checker,
|
||||
Status: rpcResp.Status,
|
||||
Remark: rpcResp.Remark,
|
||||
CreatedAt: rpcResp.CreatedAt,
|
||||
UpdatedAt: rpcResp.UpdatedAt,
|
||||
Details: details,
|
||||
}, nil
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/rpc/inventory/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ListStockCheckLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewListStockCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListStockCheckLogic {
|
||||
return &ListStockCheckLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ListStockCheckLogic) ListStockCheck(req *types.ListStockCheckReq) (resp *types.ListStockCheckResp, err error) {
|
||||
rpcResp, err := l.svcCtx.InventoryRpc.ListStockCheck(l.ctx, &pb.ListStockCheckReq{
|
||||
Page: req.Page,
|
||||
PageSize: req.PageSize,
|
||||
CheckNo: req.CheckNo,
|
||||
Status: req.Status,
|
||||
StartDate: req.StartDate,
|
||||
EndDate: req.EndDate,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]types.StockCheckInfo, 0, len(rpcResp.List))
|
||||
for _, c := range rpcResp.List {
|
||||
details := make([]types.StockCheckDetailInfo, 0, len(c.Details))
|
||||
for _, d := range c.Details {
|
||||
details = append(details, types.StockCheckDetailInfo{
|
||||
DetailId: d.DetailId,
|
||||
CheckId: d.CheckId,
|
||||
ProductId: d.ProductId,
|
||||
ProductName: d.ProductName,
|
||||
SystemQuantity: d.SystemQuantity,
|
||||
ActualQuantity: d.ActualQuantity,
|
||||
DiffQuantity: d.DiffQuantity,
|
||||
DiffAmount: d.DiffAmount,
|
||||
Remark: d.Remark,
|
||||
})
|
||||
}
|
||||
|
||||
list = append(list, types.StockCheckInfo{
|
||||
CheckId: c.CheckId,
|
||||
CheckNo: c.CheckNo,
|
||||
CheckDate: c.CheckDate,
|
||||
Checker: c.Checker,
|
||||
Status: c.Status,
|
||||
Remark: c.Remark,
|
||||
CreatedAt: c.CreatedAt,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
Details: details,
|
||||
})
|
||||
}
|
||||
|
||||
return &types.ListStockCheckResp{
|
||||
Total: rpcResp.Total,
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/inventory/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateStockCheckLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateStockCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateStockCheckLogic {
|
||||
return &UpdateStockCheckLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateStockCheckLogic) UpdateStockCheck(req *types.UpdateStockCheckReq) (resp *types.IdResp, err error) {
|
||||
id := ctxdata.GetPathId(l.ctx)
|
||||
|
||||
details := make([]*pb.StockCheckDetailReq, 0, len(req.Details))
|
||||
for _, d := range req.Details {
|
||||
details = append(details, &pb.StockCheckDetailReq{
|
||||
ProductId: d.ProductId,
|
||||
ActualQuantity: d.ActualQuantity,
|
||||
Remark: d.Remark,
|
||||
})
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.InventoryRpc.UpdateStockCheck(l.ctx, &pb.UpdateStockCheckReq{
|
||||
CheckId: id,
|
||||
Remark: req.Remark,
|
||||
Details: details,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.IdResp{Id: id}, nil
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/rpc/inventory/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateProductLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCreateProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateProductLogic {
|
||||
return &CreateProductLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateProductLogic) CreateProduct(req *types.CreateProductReq) (resp *types.IdResp, err error) {
|
||||
rpcResp, err := l.svcCtx.InventoryRpc.CreateProduct(l.ctx, &pb.CreateProductReq{
|
||||
ProductName: req.ProductName,
|
||||
ImageUrl: req.ImageUrl,
|
||||
Spec: req.Spec,
|
||||
Color: req.Color,
|
||||
UnitPieces: req.UnitPieces,
|
||||
UnitRolls: req.UnitRolls,
|
||||
StockQuantity: req.StockQuantity,
|
||||
Location: req.Location,
|
||||
CostPrice: req.CostPrice,
|
||||
SalesPrice: req.SalesPrice,
|
||||
Remark: req.Remark,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.IdResp{Id: rpcResp.Id}, nil
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/inventory/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DeleteProductLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewDeleteProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteProductLogic {
|
||||
return &DeleteProductLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeleteProductLogic) DeleteProduct() (resp *types.IdResp, err error) {
|
||||
id := ctxdata.GetPathId(l.ctx)
|
||||
|
||||
_, err = l.svcCtx.InventoryRpc.DeleteProduct(l.ctx, &pb.DeleteProductReq{
|
||||
ProductId: id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.IdResp{Id: id}, nil
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ExportProductLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewExportProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ExportProductLogic {
|
||||
return &ExportProductLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ExportProductLogic) ExportProduct() error {
|
||||
return errors.New("export product requires response writer, will be implemented in handler layer")
|
||||
}
|
||||
55
gateway/internal/logic/inventory/product/getProductLogic.go
Normal file
55
gateway/internal/logic/inventory/product/getProductLogic.go
Normal file
@ -0,0 +1,55 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/inventory/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetProductLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductLogic {
|
||||
return &GetProductLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetProductLogic) GetProduct() (resp *types.ProductInfo, err error) {
|
||||
id := ctxdata.GetPathId(l.ctx)
|
||||
|
||||
rpcResp, err := l.svcCtx.InventoryRpc.GetProduct(l.ctx, &pb.GetProductReq{
|
||||
ProductId: id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.ProductInfo{
|
||||
ProductId: rpcResp.ProductId,
|
||||
ProductName: rpcResp.ProductName,
|
||||
ImageUrl: rpcResp.ImageUrl,
|
||||
Spec: rpcResp.Spec,
|
||||
Color: rpcResp.Color,
|
||||
UnitPieces: rpcResp.UnitPieces,
|
||||
UnitRolls: rpcResp.UnitRolls,
|
||||
StockQuantity: rpcResp.StockQuantity,
|
||||
Location: rpcResp.Location,
|
||||
CostPrice: rpcResp.CostPrice,
|
||||
SalesPrice: rpcResp.SalesPrice,
|
||||
Remark: rpcResp.Remark,
|
||||
Status: rpcResp.Status,
|
||||
CreatedAt: rpcResp.CreatedAt,
|
||||
UpdatedAt: rpcResp.UpdatedAt,
|
||||
}, nil
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ImportProductLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewImportProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ImportProductLogic {
|
||||
return &ImportProductLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ImportProductLogic) ImportProduct() (resp *types.ImportProductResp, err error) {
|
||||
return nil, errors.New("import product requires file upload handling, will be implemented in handler layer")
|
||||
}
|
||||
66
gateway/internal/logic/inventory/product/listProductLogic.go
Normal file
66
gateway/internal/logic/inventory/product/listProductLogic.go
Normal file
@ -0,0 +1,66 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/rpc/inventory/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ListProductLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewListProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListProductLogic {
|
||||
return &ListProductLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ListProductLogic) ListProduct(req *types.ListProductReq) (resp *types.ListProductResp, err error) {
|
||||
rpcResp, err := l.svcCtx.InventoryRpc.ListProduct(l.ctx, &pb.ListProductReq{
|
||||
Page: req.Page,
|
||||
PageSize: req.PageSize,
|
||||
ProductName: req.ProductName,
|
||||
Spec: req.Spec,
|
||||
Color: req.Color,
|
||||
Location: req.Location,
|
||||
Status: req.Status,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]types.ProductInfo, 0, len(rpcResp.List))
|
||||
for _, p := range rpcResp.List {
|
||||
list = append(list, types.ProductInfo{
|
||||
ProductId: p.ProductId,
|
||||
ProductName: p.ProductName,
|
||||
ImageUrl: p.ImageUrl,
|
||||
Spec: p.Spec,
|
||||
Color: p.Color,
|
||||
UnitPieces: p.UnitPieces,
|
||||
UnitRolls: p.UnitRolls,
|
||||
StockQuantity: p.StockQuantity,
|
||||
Location: p.Location,
|
||||
CostPrice: p.CostPrice,
|
||||
SalesPrice: p.SalesPrice,
|
||||
Remark: p.Remark,
|
||||
Status: p.Status,
|
||||
CreatedAt: p.CreatedAt,
|
||||
UpdatedAt: p.UpdatedAt,
|
||||
})
|
||||
}
|
||||
|
||||
return &types.ListProductResp{
|
||||
Total: rpcResp.Total,
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/inventory/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateProductLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateProductLogic {
|
||||
return &UpdateProductLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateProductLogic) UpdateProduct(req *types.UpdateProductReq) (resp *types.IdResp, err error) {
|
||||
id := ctxdata.GetPathId(l.ctx)
|
||||
|
||||
_, err = l.svcCtx.InventoryRpc.UpdateProduct(l.ctx, &pb.UpdateProductReq{
|
||||
ProductId: id,
|
||||
ProductName: req.ProductName,
|
||||
ImageUrl: req.ImageUrl,
|
||||
Spec: req.Spec,
|
||||
Color: req.Color,
|
||||
UnitPieces: req.UnitPieces,
|
||||
UnitRolls: req.UnitRolls,
|
||||
StockQuantity: req.StockQuantity,
|
||||
Location: req.Location,
|
||||
CostPrice: req.CostPrice,
|
||||
SalesPrice: req.SalesPrice,
|
||||
Remark: req.Remark,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.IdResp{Id: id}, nil
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
package stock
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/rpc/inventory/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetStockByColorLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetStockByColorLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetStockByColorLogic {
|
||||
return &GetStockByColorLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetStockByColorLogic) GetStockByColor() (resp *types.StockGroupResp, err error) {
|
||||
rpcResp, err := l.svcCtx.InventoryRpc.GetStockGroup(l.ctx, &pb.StockGroupReq{
|
||||
GroupBy: "color",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]types.StockGroupItem, 0, len(rpcResp.List))
|
||||
for _, item := range rpcResp.List {
|
||||
list = append(list, types.StockGroupItem{
|
||||
Name: item.Name,
|
||||
Count: item.Count,
|
||||
Quantity: item.Quantity,
|
||||
})
|
||||
}
|
||||
|
||||
return &types.StockGroupResp{
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
package stock
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/rpc/inventory/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetStockByLocationLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetStockByLocationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetStockByLocationLogic {
|
||||
return &GetStockByLocationLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetStockByLocationLogic) GetStockByLocation() (resp *types.StockGroupResp, err error) {
|
||||
rpcResp, err := l.svcCtx.InventoryRpc.GetStockGroup(l.ctx, &pb.StockGroupReq{
|
||||
GroupBy: "location",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]types.StockGroupItem, 0, len(rpcResp.List))
|
||||
for _, item := range rpcResp.List {
|
||||
list = append(list, types.StockGroupItem{
|
||||
Name: item.Name,
|
||||
Count: item.Count,
|
||||
Quantity: item.Quantity,
|
||||
})
|
||||
}
|
||||
|
||||
return &types.StockGroupResp{
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package stock
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/rpc/inventory/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetStockSummaryLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetStockSummaryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetStockSummaryLogic {
|
||||
return &GetStockSummaryLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetStockSummaryLogic) GetStockSummary() (resp *types.StockSummaryResp, err error) {
|
||||
rpcResp, err := l.svcCtx.InventoryRpc.GetStockSummary(l.ctx, &pb.StockSummaryReq{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.StockSummaryResp{
|
||||
ProductCount: rpcResp.ProductCount,
|
||||
TotalPieces: rpcResp.TotalPieces,
|
||||
TotalRolls: rpcResp.TotalRolls,
|
||||
TotalCostValue: rpcResp.TotalCostValue,
|
||||
TotalSalesValue: rpcResp.TotalSalesValue,
|
||||
}, nil
|
||||
}
|
||||
66
gateway/internal/logic/inventory/stock/listStockLogic.go
Normal file
66
gateway/internal/logic/inventory/stock/listStockLogic.go
Normal file
@ -0,0 +1,66 @@
|
||||
package stock
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/rpc/inventory/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ListStockLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewListStockLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListStockLogic {
|
||||
return &ListStockLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ListStockLogic) ListStock(req *types.ListProductReq) (resp *types.ListProductResp, err error) {
|
||||
rpcResp, err := l.svcCtx.InventoryRpc.ListProduct(l.ctx, &pb.ListProductReq{
|
||||
Page: req.Page,
|
||||
PageSize: req.PageSize,
|
||||
ProductName: req.ProductName,
|
||||
Spec: req.Spec,
|
||||
Color: req.Color,
|
||||
Location: req.Location,
|
||||
Status: req.Status,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]types.ProductInfo, 0, len(rpcResp.List))
|
||||
for _, p := range rpcResp.List {
|
||||
list = append(list, types.ProductInfo{
|
||||
ProductId: p.ProductId,
|
||||
ProductName: p.ProductName,
|
||||
ImageUrl: p.ImageUrl,
|
||||
Spec: p.Spec,
|
||||
Color: p.Color,
|
||||
UnitPieces: p.UnitPieces,
|
||||
UnitRolls: p.UnitRolls,
|
||||
StockQuantity: p.StockQuantity,
|
||||
Location: p.Location,
|
||||
CostPrice: p.CostPrice,
|
||||
SalesPrice: p.SalesPrice,
|
||||
Remark: p.Remark,
|
||||
Status: p.Status,
|
||||
CreatedAt: p.CreatedAt,
|
||||
UpdatedAt: p.UpdatedAt,
|
||||
})
|
||||
}
|
||||
|
||||
return &types.ListProductResp{
|
||||
Total: rpcResp.Total,
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
49
gateway/internal/logic/system/config/listConfigLogic.go
Normal file
49
gateway/internal/logic/system/config/listConfigLogic.go
Normal file
@ -0,0 +1,49 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/rpc/system/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ListConfigLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewListConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListConfigLogic {
|
||||
return &ListConfigLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ListConfigLogic) ListConfig() (resp *types.ListConfigResp, err error) {
|
||||
rpcResp, err := l.svcCtx.SystemRpc.ListConfig(l.ctx, &pb.ListConfigReq{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]types.ConfigInfo, 0, len(rpcResp.List))
|
||||
for _, c := range rpcResp.List {
|
||||
list = append(list, types.ConfigInfo{
|
||||
ConfigId: c.ConfigId,
|
||||
ConfigKey: c.ConfigKey,
|
||||
ConfigValue: c.ConfigValue,
|
||||
ConfigName: c.ConfigName,
|
||||
ConfigGroup: c.ConfigGroup,
|
||||
Remark: c.Remark,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
})
|
||||
}
|
||||
|
||||
return &types.ListConfigResp{
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
40
gateway/internal/logic/system/config/updateConfigLogic.go
Normal file
40
gateway/internal/logic/system/config/updateConfigLogic.go
Normal file
@ -0,0 +1,40 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/system/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateConfigLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateConfigLogic {
|
||||
return &UpdateConfigLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateConfigLogic) UpdateConfig(req *types.UpdateConfigReq) (resp *types.IdResp, err error) {
|
||||
key := ctxdata.GetPathKey(l.ctx)
|
||||
|
||||
_, err = l.svcCtx.SystemRpc.UpdateConfig(l.ctx, &pb.UpdateConfigReq{
|
||||
ConfigKey: key,
|
||||
ConfigValue: req.ConfigValue,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.IdResp{Id: key}, nil
|
||||
}
|
||||
62
gateway/internal/logic/system/log/listLogLogic.go
Normal file
62
gateway/internal/logic/system/log/listLogLogic.go
Normal file
@ -0,0 +1,62 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/rpc/system/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ListLogLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewListLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogLogic {
|
||||
return &ListLogLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ListLogLogic) ListLog(req *types.ListLogReq) (resp *types.ListLogResp, err error) {
|
||||
rpcResp, err := l.svcCtx.SystemRpc.ListOperationLog(l.ctx, &pb.ListLogReq{
|
||||
Page: req.Page,
|
||||
PageSize: req.PageSize,
|
||||
Username: req.Username,
|
||||
Module: req.Module,
|
||||
Operation: req.Operation,
|
||||
StartTime: req.StartTime,
|
||||
EndTime: req.EndTime,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]types.OperationLogInfo, 0, len(rpcResp.List))
|
||||
for _, item := range rpcResp.List {
|
||||
list = append(list, types.OperationLogInfo{
|
||||
LogId: item.LogId,
|
||||
UserId: item.UserId,
|
||||
Username: item.Username,
|
||||
Module: item.Module,
|
||||
Operation: item.Operation,
|
||||
Method: item.Method,
|
||||
Path: item.Path,
|
||||
Ip: item.Ip,
|
||||
Duration: item.Duration,
|
||||
Status: item.Status,
|
||||
CreatedAt: item.CreatedAt,
|
||||
})
|
||||
}
|
||||
|
||||
return &types.ListLogResp{
|
||||
Total: rpcResp.Total,
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
43
gateway/internal/logic/system/menu/createMenuLogic.go
Normal file
43
gateway/internal/logic/system/menu/createMenuLogic.go
Normal file
@ -0,0 +1,43 @@
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/rpc/system/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateMenuLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCreateMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateMenuLogic {
|
||||
return &CreateMenuLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateMenuLogic) CreateMenu(req *types.CreateMenuReq) (resp *types.IdResp, err error) {
|
||||
rpcResp, err := l.svcCtx.SystemRpc.CreateMenu(l.ctx, &pb.CreateMenuReq{
|
||||
ParentId: req.ParentId,
|
||||
MenuName: req.MenuName,
|
||||
MenuType: req.MenuType,
|
||||
Path: req.Path,
|
||||
Component: req.Component,
|
||||
Permission: req.Permission,
|
||||
Icon: req.Icon,
|
||||
SortOrder: req.SortOrder,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.IdResp{Id: rpcResp.Id}, nil
|
||||
}
|
||||
39
gateway/internal/logic/system/menu/deleteMenuLogic.go
Normal file
39
gateway/internal/logic/system/menu/deleteMenuLogic.go
Normal file
@ -0,0 +1,39 @@
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/system/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DeleteMenuLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewDeleteMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteMenuLogic {
|
||||
return &DeleteMenuLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeleteMenuLogic) DeleteMenu() (resp *types.IdResp, err error) {
|
||||
id := ctxdata.GetPathId(l.ctx)
|
||||
|
||||
_, err = l.svcCtx.SystemRpc.DeleteMenu(l.ctx, &pb.DeleteMenuReq{
|
||||
MenuId: id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.IdResp{Id: id}, nil
|
||||
}
|
||||
69
gateway/internal/logic/system/menu/getMenuLogic.go
Normal file
69
gateway/internal/logic/system/menu/getMenuLogic.go
Normal file
@ -0,0 +1,69 @@
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/system/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetMenuLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenuLogic {
|
||||
return &GetMenuLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetMenuLogic) GetMenu() (resp *types.MenuInfo, err error) {
|
||||
id := ctxdata.GetPathId(l.ctx)
|
||||
|
||||
rpcResp, err := l.svcCtx.SystemRpc.GetMenu(l.ctx, &pb.GetMenuReq{
|
||||
MenuId: id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return convertMenuInfo(rpcResp), nil
|
||||
}
|
||||
|
||||
func convertMenuInfo(m *pb.MenuInfo) *types.MenuInfo {
|
||||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
children := make([]types.MenuInfo, 0, len(m.Children))
|
||||
for _, c := range m.Children {
|
||||
if c != nil {
|
||||
children = append(children, *convertMenuInfo(c))
|
||||
}
|
||||
}
|
||||
|
||||
return &types.MenuInfo{
|
||||
MenuId: m.MenuId,
|
||||
ParentId: m.ParentId,
|
||||
MenuName: m.MenuName,
|
||||
MenuType: m.MenuType,
|
||||
Path: m.Path,
|
||||
Component: m.Component,
|
||||
Permission: m.Permission,
|
||||
Icon: m.Icon,
|
||||
SortOrder: m.SortOrder,
|
||||
Visible: m.Visible,
|
||||
Status: m.Status,
|
||||
Children: children,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
43
gateway/internal/logic/system/menu/listMenuLogic.go
Normal file
43
gateway/internal/logic/system/menu/listMenuLogic.go
Normal file
@ -0,0 +1,43 @@
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/rpc/system/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ListMenuLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewListMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListMenuLogic {
|
||||
return &ListMenuLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ListMenuLogic) ListMenu() (resp *types.ListMenuResp, err error) {
|
||||
rpcResp, err := l.svcCtx.SystemRpc.ListMenu(l.ctx, &pb.ListMenuReq{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]types.MenuInfo, 0, len(rpcResp.List))
|
||||
for _, m := range rpcResp.List {
|
||||
if m != nil {
|
||||
list = append(list, *convertMenuInfo(m))
|
||||
}
|
||||
}
|
||||
|
||||
return &types.ListMenuResp{
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
48
gateway/internal/logic/system/menu/updateMenuLogic.go
Normal file
48
gateway/internal/logic/system/menu/updateMenuLogic.go
Normal file
@ -0,0 +1,48 @@
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/system/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateMenuLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateMenuLogic {
|
||||
return &UpdateMenuLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateMenuLogic) UpdateMenu(req *types.UpdateMenuReq) (resp *types.IdResp, err error) {
|
||||
id := ctxdata.GetPathId(l.ctx)
|
||||
|
||||
_, err = l.svcCtx.SystemRpc.UpdateMenu(l.ctx, &pb.UpdateMenuReq{
|
||||
MenuId: id,
|
||||
ParentId: req.ParentId,
|
||||
MenuName: req.MenuName,
|
||||
MenuType: req.MenuType,
|
||||
Path: req.Path,
|
||||
Component: req.Component,
|
||||
Permission: req.Permission,
|
||||
Icon: req.Icon,
|
||||
SortOrder: req.SortOrder,
|
||||
Visible: req.Visible,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.IdResp{Id: id}, nil
|
||||
}
|
||||
39
gateway/internal/logic/system/role/createRoleLogic.go
Normal file
39
gateway/internal/logic/system/role/createRoleLogic.go
Normal file
@ -0,0 +1,39 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/rpc/system/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateRoleLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCreateRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateRoleLogic {
|
||||
return &CreateRoleLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateRoleLogic) CreateRole(req *types.CreateRoleReq) (resp *types.IdResp, err error) {
|
||||
rpcResp, err := l.svcCtx.SystemRpc.CreateRole(l.ctx, &pb.CreateRoleReq{
|
||||
RoleName: req.RoleName,
|
||||
RoleKey: req.RoleKey,
|
||||
RoleDesc: req.RoleDesc,
|
||||
SortOrder: req.SortOrder,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.IdResp{Id: rpcResp.Id}, nil
|
||||
}
|
||||
39
gateway/internal/logic/system/role/deleteRoleLogic.go
Normal file
39
gateway/internal/logic/system/role/deleteRoleLogic.go
Normal file
@ -0,0 +1,39 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/system/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DeleteRoleLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewDeleteRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteRoleLogic {
|
||||
return &DeleteRoleLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeleteRoleLogic) DeleteRole() (resp *types.IdResp, err error) {
|
||||
id := ctxdata.GetPathId(l.ctx)
|
||||
|
||||
_, err = l.svcCtx.SystemRpc.DeleteRole(l.ctx, &pb.DeleteRoleReq{
|
||||
RoleId: id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.IdResp{Id: id}, nil
|
||||
}
|
||||
49
gateway/internal/logic/system/role/getRoleLogic.go
Normal file
49
gateway/internal/logic/system/role/getRoleLogic.go
Normal file
@ -0,0 +1,49 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/system/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetRoleLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRoleLogic {
|
||||
return &GetRoleLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetRoleLogic) GetRole() (resp *types.RoleInfo, err error) {
|
||||
id := ctxdata.GetPathId(l.ctx)
|
||||
|
||||
rpcResp, err := l.svcCtx.SystemRpc.GetRole(l.ctx, &pb.GetRoleReq{
|
||||
RoleId: id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.RoleInfo{
|
||||
RoleId: rpcResp.RoleId,
|
||||
RoleName: rpcResp.RoleName,
|
||||
RoleKey: rpcResp.RoleKey,
|
||||
RoleDesc: rpcResp.RoleDesc,
|
||||
SortOrder: rpcResp.SortOrder,
|
||||
Status: rpcResp.Status,
|
||||
MenuIds: rpcResp.MenuIds,
|
||||
CreatedAt: rpcResp.CreatedAt,
|
||||
UpdatedAt: rpcResp.UpdatedAt,
|
||||
}, nil
|
||||
}
|
||||
57
gateway/internal/logic/system/role/listRoleLogic.go
Normal file
57
gateway/internal/logic/system/role/listRoleLogic.go
Normal file
@ -0,0 +1,57 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/rpc/system/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ListRoleLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewListRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListRoleLogic {
|
||||
return &ListRoleLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ListRoleLogic) ListRole(req *types.ListRoleReq) (resp *types.ListRoleResp, err error) {
|
||||
rpcResp, err := l.svcCtx.SystemRpc.ListRole(l.ctx, &pb.ListRoleReq{
|
||||
Page: req.Page,
|
||||
PageSize: req.PageSize,
|
||||
RoleName: req.RoleName,
|
||||
Status: req.Status,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]types.RoleInfo, 0, len(rpcResp.List))
|
||||
for _, r := range rpcResp.List {
|
||||
list = append(list, types.RoleInfo{
|
||||
RoleId: r.RoleId,
|
||||
RoleName: r.RoleName,
|
||||
RoleKey: r.RoleKey,
|
||||
RoleDesc: r.RoleDesc,
|
||||
SortOrder: r.SortOrder,
|
||||
Status: r.Status,
|
||||
MenuIds: r.MenuIds,
|
||||
CreatedAt: r.CreatedAt,
|
||||
UpdatedAt: r.UpdatedAt,
|
||||
})
|
||||
}
|
||||
|
||||
return &types.ListRoleResp{
|
||||
Total: rpcResp.Total,
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/system/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SetRolePermissionsLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewSetRolePermissionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SetRolePermissionsLogic {
|
||||
return &SetRolePermissionsLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SetRolePermissionsLogic) SetRolePermissions(req *types.SetRolePermissionsReq) (resp *types.IdResp, err error) {
|
||||
id := ctxdata.GetPathId(l.ctx)
|
||||
|
||||
_, err = l.svcCtx.SystemRpc.SetRolePermissions(l.ctx, &pb.SetRolePermissionsReq{
|
||||
RoleId: id,
|
||||
MenuIds: req.MenuIds,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.IdResp{Id: id}, nil
|
||||
}
|
||||
43
gateway/internal/logic/system/role/updateRoleLogic.go
Normal file
43
gateway/internal/logic/system/role/updateRoleLogic.go
Normal file
@ -0,0 +1,43 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/pkg/ctxdata"
|
||||
"muyu-apiserver/rpc/system/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateRoleLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateRoleLogic {
|
||||
return &UpdateRoleLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateRoleLogic) UpdateRole(req *types.UpdateRoleReq) (resp *types.IdResp, err error) {
|
||||
id := ctxdata.GetPathId(l.ctx)
|
||||
|
||||
_, err = l.svcCtx.SystemRpc.UpdateRole(l.ctx, &pb.UpdateRoleReq{
|
||||
RoleId: id,
|
||||
RoleName: req.RoleName,
|
||||
RoleKey: req.RoleKey,
|
||||
RoleDesc: req.RoleDesc,
|
||||
SortOrder: req.SortOrder,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.IdResp{Id: id}, nil
|
||||
}
|
||||
41
gateway/internal/logic/system/user/createUserLogic.go
Normal file
41
gateway/internal/logic/system/user/createUserLogic.go
Normal file
@ -0,0 +1,41 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"muyu-apiserver/gateway/internal/svc"
|
||||
"muyu-apiserver/gateway/internal/types"
|
||||
"muyu-apiserver/rpc/system/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateUserLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCreateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateUserLogic {
|
||||
return &CreateUserLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateUserLogic) CreateUser(req *types.CreateUserReq) (resp *types.IdResp, err error) {
|
||||
rpcResp, err := l.svcCtx.SystemRpc.CreateUser(l.ctx, &pb.CreateUserReq{
|
||||
Username: req.Username,
|
||||
Password: req.Password,
|
||||
RealName: req.RealName,
|
||||
Phone: req.Phone,
|
||||
Email: req.Email,
|
||||
RoleId: req.RoleId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.IdResp{Id: rpcResp.Id}, nil
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user