init:代码初始化
This commit is contained in:
65
src/controllers/priceController.js
Normal file
65
src/controllers/priceController.js
Normal file
@@ -0,0 +1,65 @@
|
||||
const PriceService = require('../services/priceService');
|
||||
const { asyncHandler } = require('../middlewares/errorHandler');
|
||||
|
||||
/**
|
||||
* 价格控制器
|
||||
* 处理 HTTP 请求和响应
|
||||
*/
|
||||
class PriceController {
|
||||
/**
|
||||
* 按地区查询价格
|
||||
* GET /api/prices/region?region=昆明&date=2026-01-05&page=1&pageSize=20
|
||||
*/
|
||||
static getByRegion = asyncHandler(async (req, res) => {
|
||||
const { region, date, page = 1, pageSize = 20 } = req.query;
|
||||
|
||||
const result = await PriceService.getByRegion(region, date, page, pageSize);
|
||||
res.json(result);
|
||||
});
|
||||
|
||||
/**
|
||||
* 搜索价格数据
|
||||
* GET /api/prices/search?material=螺纹钢&startDate=2026-01-01&endDate=2026-01-05
|
||||
*/
|
||||
static search = asyncHandler(async (req, res) => {
|
||||
const filters = req.query;
|
||||
|
||||
const result = await PriceService.search(filters);
|
||||
res.json(result);
|
||||
});
|
||||
|
||||
/**
|
||||
* 获取价格统计
|
||||
* GET /api/prices/stats?region=昆明&material=螺纹钢&days=30
|
||||
*/
|
||||
static getStats = asyncHandler(async (req, res) => {
|
||||
const filters = req.query;
|
||||
|
||||
const result = await PriceService.getStats(filters);
|
||||
res.json(result);
|
||||
});
|
||||
|
||||
/**
|
||||
* 获取价格趋势
|
||||
* GET /api/prices/trend?region=昆明&material=螺纹钢&days=30
|
||||
*/
|
||||
static getTrend = asyncHandler(async (req, res) => {
|
||||
const filters = req.query;
|
||||
|
||||
const result = await PriceService.getTrend(filters);
|
||||
res.json(result);
|
||||
});
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
* POST /api/prices/import
|
||||
*/
|
||||
static importData = asyncHandler(async (req, res) => {
|
||||
const { prices } = req.body;
|
||||
|
||||
const result = await PriceService.importData(prices);
|
||||
res.json(result);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = PriceController;
|
||||
Reference in New Issue
Block a user