Skip to content

Commit

Permalink
✨ 添加月份分类
Browse files Browse the repository at this point in the history
  • Loading branch information
kalicyh committed Aug 5, 2024
1 parent 4e2a5b1 commit 2cba01a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions api/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Record(Base):
__tablename__ = 'records'
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
name = Column(String(255), index=True)
month = Column(String(255), nullable=True)
category = Column(String(255), nullable=True)
text = Column(String(5000))

Expand Down
7 changes: 6 additions & 1 deletion api/routes/talking_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ async def get_progress(upload_id: str):
def process_file(file_buffer: BytesIO, upload_id: str):
df = pd.read_excel(file_buffer)
df.columns = df.columns.str.strip()
df['月份'] = df['月份'].fillna('未设置')
df['分类'] = df['分类'].fillna('未分类')

total_rows = len(df)
Expand All @@ -66,6 +67,7 @@ def process_file(file_buffer: BytesIO, upload_id: str):
records.append(
Record(
name=row['名字'],
month=row['月份'],
category=row['分类'],
text=row['文案']
)
Expand Down Expand Up @@ -136,7 +138,10 @@ async def get_infos():
info_record = get_info(db)
if not info_record:
db.close()
raise HTTPException(status_code=404, detail="No info record found")
return JSONResponse(content={
"total_rows": "0",
"last_updated": "暂无数据",
}, status_code=200)

name_categories = db.query(Record.name).distinct().all()
db.close()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "knowledge_backend_vue",
"version": "1.1.0",
"version": "1.2.0",
"private": true,
"scripts": {
"setup": "yarn install && pip3 install poetry && poetry install",
Expand Down
12 changes: 7 additions & 5 deletions src/components/ExcelUploader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
<h1>果之都智库</h1>
<p>数据条数: {{ totalRows }}</p>
<p>最后更新: {{ lastUpdated }}</p>
<div v-if="error" class="error">{{ error }}</div>
<div v-if="progress >= 0">
<p>Progress: {{ progress }}%</p>
</div>

<input type="file" @change="handleFileUpload" />
<button @click="togglePreviewData">{{ showPreviewData ? '隐藏上传文件数据' : '预览上传文件' }}</button>
Expand All @@ -24,6 +28,7 @@
<tbody>
<tr v-for="(item, index) in data" :key="index">
<td>{{ item.名字 }}</td>
<td>{{ item.月份 }}</td>
<td>{{ item.分类 }}</td>
<td>{{ item.文案 }}</td>
</tr>
Expand All @@ -39,6 +44,7 @@
<tr>
<th>序号</th>
<th>名字</th>
<th>月份</th>
<th>分类</th>
<th>文案</th>
</tr>
Expand All @@ -47,17 +53,13 @@
<tr v-for="item in mysqlData" :key="item.序号">
<td>{{ item.序号 }}</td>
<td>{{ item.名字 }}</td>
<td>{{ item.月份 }}</td>
<td>{{ item.分类 }}</td>
<td>{{ item.文案 }}</td>
</tr>
</tbody>
</table>
</div>

<div v-if="error" class="error">{{ error }}</div>
<div v-if="progress >= 0">
<p>Progress: {{ progress }}%</p>
</div>
</div>
</template>

Expand Down

0 comments on commit 2cba01a

Please sign in to comment.