Sfoglia il codice sorgente

已完成训练代码相关文件的字段对齐工作

yourname 6 mesi fa
parent
commit
3511c8b666

+ 63 - 16
client/admin/pages_xunlian_codes.tsx

@@ -4,7 +4,7 @@ import {
   Button, Table, Space,
   Form, Input, message, Modal,
   Card, Row, Col,
-  Popconfirm, Tag
+  Popconfirm, Tag, DatePicker
 } from 'antd';
 import { 
   useQuery,
@@ -170,9 +170,24 @@ export const XunlianCodePage = () => {
       key: 'code',
     },
     {
-      title: '训练日期',
-      dataIndex: 'training_date',
-      key: 'training_date',
+      title: '股票名称',
+      dataIndex: 'stock_name',
+      key: 'stock_name',
+    },
+    {
+      title: '案例名称',
+      dataIndex: 'name',
+      key: 'name',
+    },
+    {
+      title: '案例类型',
+      dataIndex: 'type',
+      key: 'type',
+    },
+    {
+      title: '交易日期',
+      dataIndex: 'trade_date',
+      key: 'trade_date',
       render: (date: string) => dayjs(date).format('YYYY-MM-DD'),
     },
     {
@@ -293,22 +308,54 @@ export const XunlianCodePage = () => {
             </Col>
             <Col span={12}>
               <Form.Item
-                name="training_date"
-                label="训练日期"
-                rules={[{ required: true, message: '请选择训练日期' }]}
+                name="stock_name"
+                label="股票名称"
+                rules={[{ required: true, message: '请输入股票名称' }]}
               >
-                <Input placeholder="请输入训练日期,格式:YYYY-MM-DD" />
+                <Input placeholder="请输入股票名称" />
+              </Form.Item>
+            </Col>
+          </Row>
+
+          <Row gutter={16}>
+            <Col span={12}>
+              <Form.Item
+                name="name"
+                label="案例名称"
+                rules={[{ required: true, message: '请输入案例名称' }]}
+              >
+                <Input placeholder="请输入案例名称" />
+              </Form.Item>
+            </Col>
+            <Col span={12}>
+              <Form.Item
+                name="type"
+                label="案例类型"
+              >
+                <Input placeholder="请输入案例类型" />
+              </Form.Item>
+            </Col>
+          </Row>
+
+          <Row gutter={16}>
+            <Col span={12}>
+              <Form.Item
+                name="trade_date"
+                label="交易日期"
+                rules={[{ required: true, message: '请选择交易日期' }]}
+              >
+                <DatePicker style={{ width: '100%' }} format="YYYY-MM-DD" />
+              </Form.Item>
+            </Col>
+            <Col span={12}>
+              <Form.Item
+                name="description"
+                label="案例描述"
+              >
+                <Input.TextArea rows={1} placeholder="请输入案例描述" />
               </Form.Item>
             </Col>
           </Row>
-          
-          <Form.Item
-            name="content"
-            label="代码内容"
-            rules={[{ required: true, message: '请输入代码内容' }]}
-          >
-            <Input.TextArea rows={15} placeholder="请输入代码内容" />
-          </Form.Item>
           
         </Form>
       </Modal>

+ 11 - 8
client/share/types_stock.ts

@@ -158,17 +158,20 @@ export enum ClassroomStatus {
     /** 股票代码 */
     code: string;
     
-    /** 训练日期 */
-    training_date: string;
+    /** 股票名称 */
+    stock_name: string;
     
-    /** 代码内容 */
-    content: string;
+    /** 案例名称 */
+    name: string;
     
-    /** 提交用户ID */
-    user_id: number;
+    /** 案例类型 */
+    type?: string;
     
-    /** 用户昵称 */
-    nickname: string;
+    /** 案例描述 */
+    description?: string;
+    
+    /** 交易日期 */
+    trade_date: string;
     
     /** 创建时间 */
     created_at: string;

+ 35 - 73
server/routes_xunlian_codes.ts

@@ -15,15 +15,20 @@ export function createXunlianCodesRoutes(withAuth: WithAuth) {
       
       const search = c.req.query('search') || ''
       
-      let query = apiClient.database.table('xunlian_codes')
+      let query = apiClient.database.table('stock_xunlian_codes')
         .orderBy('id', 'desc')
       
-      if (search) {
-        query = query.where('code', 'like', `%${search}%`)
-      }
+      const { code, stock_name, name, type, trade_date } = c.req.query()
+      
+      if (code) query = query.where('code', 'like', `%${code}%`)
+      if (stock_name) query = query.where('stock_name', 'like', `%${stock_name}%`)
+      if (name) query = query.where('name', 'like', `%${name}%`)
+      if (type) query = query.where('type', type)
+      if (trade_date) query = query.where('trade_date', trade_date)
+      if (search) query = query.where('code', 'like', `%${search}%`)
       
       const total = await query.clone().count()
-      const codes = await query.select('id', 'code', 'status', 'created_at', 'updated_at')
+      const codes = await query.select('*')
         .limit(pageSize).offset(offset)
       
       return c.json({
@@ -50,9 +55,9 @@ export function createXunlianCodesRoutes(withAuth: WithAuth) {
       }
       
       const apiClient = c.get('apiClient')
-      const code = await apiClient.database.table('xunlian_codes')
+      const code = await apiClient.database.table('stock_xunlian_codes')
         .where('id', id)
-        .select('id', 'code', 'status', 'created_at', 'updated_at')
+        .select('*')
         .first()
       
       if (!code) {
@@ -76,13 +81,13 @@ export function createXunlianCodesRoutes(withAuth: WithAuth) {
       const body = await c.req.json()
       
       // 验证必填字段
-      const { code } = body
-      if (!code) {
-        return c.json({ error: '缺少训练码' }, 400)
+      const { code, stock_name, name, trade_date } = body
+      if (!code || !stock_name || !name || !trade_date) {
+        return c.json({ error: '缺少必填字段(code/stock_name/name/trade_date)' }, 400)
       }
 
       // 检查训练码是否已存在
-      const existingCode = await apiClient.database.table('xunlian_codes')
+      const existingCode = await apiClient.database.table('stock_xunlian_codes')
         .where('code', code)
         .first()
       
@@ -91,16 +96,15 @@ export function createXunlianCodesRoutes(withAuth: WithAuth) {
       }
 
       // 创建训练码
-      const [id] = await apiClient.database.table('xunlian_codes').insert({
-        code,
-        status: 'active', // 默认激活状态
-        created_at: new Date(),
-        updated_at: new Date()
+      const [id] = await apiClient.database.table('stock_xunlian_codes').insert({
+        ...body,
+        created_at: apiClient.database.fn.now(),
+        updated_at: apiClient.database.fn.now()
       })
 
-      const newCode = await apiClient.database.table('xunlian_codes')
+      const newCode = await apiClient.database.table('stock_xunlian_codes')
         .where('id', id)
-        .select('id', 'code', 'status', 'created_at')
+        .select('*')
         .first()
 
       return c.json({
@@ -109,7 +113,7 @@ export function createXunlianCodesRoutes(withAuth: WithAuth) {
       })
     } catch (error) {
       console.error('创建训练码失败:', error)
-      return c.json({ error: '创建训练码失败' }, 500)
+      return c.json({ error: '创建训练码失败', message: error }, 500)
     }
   })
 
@@ -125,13 +129,13 @@ export function createXunlianCodesRoutes(withAuth: WithAuth) {
       const body = await c.req.json()
       
       // 验证必填字段
-      const { code } = body
-      if (!code) {
-        return c.json({ error: '缺少训练码' }, 400)
+      const { code, stock_name, name, trade_date } = body
+      if (!code || !stock_name || !name || !trade_date) {
+        return c.json({ error: '缺少必填字段(code/stock_name/name/trade_date)' }, 400)
       }
 
       // 检查训练码是否存在
-      const existingCode = await apiClient.database.table('xunlian_codes')
+      const existingCode = await apiClient.database.table('stock_xunlian_codes')
         .where('id', id)
         .first()
       
@@ -141,7 +145,7 @@ export function createXunlianCodesRoutes(withAuth: WithAuth) {
 
       // 如果修改了训练码,检查新训练码是否已被使用
       if (code !== existingCode.code) {
-        const codeWithSameName = await apiClient.database.table('xunlian_codes')
+        const codeWithSameName = await apiClient.database.table('stock_xunlian_codes')
           .where('code', code)
           .whereNot('id', id.toString())
           .first()
@@ -153,17 +157,17 @@ export function createXunlianCodesRoutes(withAuth: WithAuth) {
 
       // 更新训练码信息
       const updateData = {
-        code,
-        updated_at: new Date()
+        ...body,
+        updated_at: apiClient.database.fn.now()
       }
 
-      await apiClient.database.table('xunlian_codes')
+      await apiClient.database.table('stock_xunlian_codes')
         .where('id', id)
         .update(updateData)
 
-      const updatedCode = await apiClient.database.table('xunlian_codes')
+      const updatedCode = await apiClient.database.table('stock_xunlian_codes')
         .where('id', id)
-        .select('id', 'code', 'status', 'created_at')
+        .select('*')
         .first()
 
       return c.json({
@@ -187,7 +191,7 @@ export function createXunlianCodesRoutes(withAuth: WithAuth) {
       const apiClient = c.get('apiClient')
       
       // 检查训练码是否存在
-      const existingCode = await apiClient.database.table('xunlian_codes')
+      const existingCode = await apiClient.database.table('stock_xunlian_codes')
         .where('id', id)
         .first()
       
@@ -196,7 +200,7 @@ export function createXunlianCodesRoutes(withAuth: WithAuth) {
       }
 
       // 删除训练码
-      await apiClient.database.table('xunlian_codes')
+      await apiClient.database.table('stock_xunlian_codes')
         .where('id', id)
         .delete()
 
@@ -210,49 +214,7 @@ export function createXunlianCodesRoutes(withAuth: WithAuth) {
     }
   })
 
-  // 更新训练码状态
-  xunlianCodesRoutes.put('/:id/status', withAuth, async (c) => {
-    try {
-      const id = Number(c.req.param('id'))
-      if (!id || isNaN(id)) {
-        return c.json({ error: '无效的训练码ID' }, 400)
-      }
 
-      const apiClient = c.get('apiClient')
-      const body = await c.req.json()
-      
-      const { status } = body
-      if (!status || !['active', 'inactive', 'used'].includes(status)) {
-        return c.json({ error: '无效的状态值' }, 400)
-      }
-
-      // 检查训练码是否存在
-      const existingCode = await apiClient.database.table('xunlian_codes')
-        .where('id', id)
-        .first()
-      
-      if (!existingCode) {
-        return c.json({ error: '训练码不存在' }, 404)
-      }
-
-      // 更新状态
-      await apiClient.database.table('xunlian_codes')
-        .where('id', id)
-        .update({
-          status,
-          updated_at: new Date()
-        })
-
-      return c.json({
-        message: '更新训练码状态成功',
-        id,
-        status
-      })
-    } catch (error) {
-      console.error('更新训练码状态失败:', error)
-      return c.json({ error: '更新训练码状态失败' }, 500)
-    }
-  })
 
   return xunlianCodesRoutes
 }