新增营养知识功能

This commit is contained in:
xiezhijun 2021-04-16 19:02:42 +08:00
parent 15e9561327
commit 4c8f29a50a
5 changed files with 395 additions and 18 deletions

View File

@ -1,16 +1,11 @@
package com.stdiet.custom.controller;
import java.util.List;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.stdiet.common.annotation.Log;
import com.stdiet.common.core.controller.BaseController;
import com.stdiet.common.core.domain.AjaxResult;
@ -38,11 +33,10 @@ public class SysNutritionQuestionController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('custom:nutritionQuestion:list')")
@GetMapping("/list")
public TableDataInfo list(SysNutritionQuestion sysNutritionQuestion)
public AjaxResult list(SysNutritionQuestion sysNutritionQuestion, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "10")int pageSize)
{
startPage();
List<SysNutritionQuestion> list = sysNutritionQuestionService.selectSysNutritionQuestionList(sysNutritionQuestion);
return getDataTable(list);
//startPage()
return AjaxResult.success(sysNutritionQuestionService.getNutritionQuestionListByKey(sysNutritionQuestion, pageNum, pageSize));
}
/**

View File

@ -37,6 +37,8 @@ public class SysNutritionQuestionServiceImpl implements ISysNutritionQuestionSer
//建立索引的字段名称
public static final String[] index_field_array = {"id", "title", "content", "key"};
//查询字段
public static final String[] index_select_field_array = {"title", "content", "key"};
/**
* 查询营养知识小问答
@ -151,7 +153,7 @@ public class SysNutritionQuestionServiceImpl implements ISysNutritionQuestionSer
try{
//建立索引
LuceneIndexUtils luceneIndexUtils = LuceneIndexUtils.getLuceneIndexUtils(index_path);
Map<String, Object> indexMap = luceneIndexUtils.queryByKeyword(sysNutritionQuestion.getKey(), index_field_array, pageNum, pageSize);
Map<String, Object> indexMap = luceneIndexUtils.queryByKeyword(sysNutritionQuestion.getKey(), index_select_field_array, pageNum, pageSize);
total = (int)indexMap.get("total");
List<Document> documentList = (List<Document>)indexMap.get("data");
if(documentList != null && documentList.size() > 0){

View File

@ -33,11 +33,6 @@
<select id="selectSysNutritionQuestionList" parameterType="SysNutritionQuestion" resultMap="SysNutritionQuestionResult">
<include refid="selectSysNutritionQuestionVo"/> where del_flag = 0
<if test="title != null and title != ''"> and title = #{title}</if>
<if test="content != null and content != ''"> and content = #{content}</if>
<if test="key != null and key != ''"> and `key` = #{key}</if>
<if test="titleContentIndex != null and titleContentIndex != ''"> and title_content_index = #{titleContentIndex}</if>
<if test="showFlag != null "> and show_flag = #{showFlag}</if>
</select>
<select id="selectSysNutritionQuestionById" parameterType="Long" resultMap="SysNutritionQuestionResult">

View File

@ -0,0 +1,53 @@
import request from '@/utils/request'
// 查询营养知识小问答列表
export function listNutritionQuestion(query) {
return request({
url: '/custom/nutritionQuestion/list',
method: 'get',
params: query
})
}
// 查询营养知识小问答详细
export function getNutritionQuestion(id) {
return request({
url: '/custom/nutritionQuestion/' + id,
method: 'get'
})
}
// 新增营养知识小问答
export function addNutritionQuestion(data) {
return request({
url: '/custom/nutritionQuestion',
method: 'post',
data: data
})
}
// 修改营养知识小问答
export function updateNutritionQuestion(data) {
return request({
url: '/custom/nutritionQuestion',
method: 'put',
data: data
})
}
// 删除营养知识小问答
export function delNutritionQuestion(id) {
return request({
url: '/custom/nutritionQuestion/' + id,
method: 'delete'
})
}
// 导出营养知识小问答
export function exportNutritionQuestion(query) {
return request({
url: '/custom/nutritionQuestion/export',
method: 'get',
params: query
})
}

View File

@ -0,0 +1,333 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="关键词" prop="title">
<el-input
v-model="queryParams.key"
placeholder="请输入关键词"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['custom:nutritionQuestion:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['custom:nutritionQuestion:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['custom:nutritionQuestion:remove']"
>删除</el-button>
</el-col>
<!--<el-col :span="1.5">
<el-button
type="warning"
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['custom:nutritionQuestion:export']"
>导出</el-button>
</el-col>-->
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="nutritionQuestionList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="标题" align="center" prop="title" >
<template slot-scope="scope">
<AutoHideMessage :data="scope.row.title == null ? '' : (scope.row.title+'')" :maxLength="10"/>
</template>
</el-table-column>
<el-table-column label="内容" align="center" prop="content" >
<template slot-scope="scope">
<AutoHideMessage :data="scope.row.content == null ? '' : (scope.row.content+'')" :maxLength="10"/>
</template>
</el-table-column>
<el-table-column label="关键词" align="center" prop="key" >
<template slot-scope="scope">
<AutoHideMessage :data="scope.row.key == null ? '' : (scope.row.key+'')" :maxLength="10"/>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['custom:nutritionQuestion:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['custom:nutritionQuestion:remove']"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改营养知识小问答对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="标题" prop="title">
<el-input v-model="form.title" placeholder="请输入标题" />
</el-form-item>
<!--<el-form-item label="内容">
<editor v-model="form.content" :min-height="192"/>
</el-form-item>-->
<el-form-item label="内容" prop="content" >
<el-input
type="textarea"
:rows="4"
maxlength="1000"
show-word-limit
placeholder="请输入内容"
v-model="form.content">
</el-input>
</el-form-item>
<el-form-item label="关键词" prop="keyArray">
<el-select
v-model="form.keyArray"
multiple
filterable
clearable
allow-create
default-first-option
placeholder="请创建案例关键词按回车创建最多5个"
style="width: 100%"
>
<el-option
v-for="dict in keyOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
>
</el-option>
</el-select>
</el-form-item>
<!-- <el-form-item label="关键词" prop="key">
<el-input v-model="form.key" placeholder="请输入关键词" />
</el-form-item>-->
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { listNutritionQuestion, getNutritionQuestion, delNutritionQuestion, addNutritionQuestion, updateNutritionQuestion, exportNutritionQuestion } from "@/api/custom/nutritionQuestion";
import Editor from '@/components/Editor';
import AutoHideMessage from "@/components/AutoHideMessage";
export default {
name: "NutritionQuestion",
components: { Editor,AutoHideMessage },
data() {
return {
//
loading: true,
//
ids: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
//
nutritionQuestionList: [],
//
title: "",
//
open: false,
//
queryParams: {
pageNum: 1,
pageSize: 10,
key: null
},
//
form: {},
//
rules: {
title: [
{ required: true, message: "标题不能为空", trigger: "blur" },
],
content: [
{ required: true, message: "内容不能为空", trigger: "blur" },
]
},
keyOptions:[]
};
},
created() {
this.getList();
},
methods: {
/** 查询营养知识小问答列表 */
getList() {
this.loading = true;
listNutritionQuestion(this.queryParams).then(response => {
this.nutritionQuestionList = response.data.data;
this.total = response.data.total;
this.loading = false;
});
},
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
id: null,
title: null,
content: null,
key: null,
keyArray: []
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加营养小知识";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id || this.ids
getNutritionQuestion(id).then(response => {
this.form = {
id: response.data.id,
title: response.data.title,
content: response.data.content,
key: response.data.key,
keyArray: response.data.key.split(",")
}
//this.form.keyArray = response.data.key.split(","),
this.open = true;
this.title = "修改营养小知识";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
//
if (this.form.keyArray.length > 5) {
this.$message({ message: "关键词最多5个", type: "warning" });
return;
}
this.form.key = this.form.keyArray.join(",");
if (this.form.id != null) {
updateNutritionQuestion(this.form).then(response => {
if (response.code === 200) {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
}
});
} else {
addNutritionQuestion(this.form).then(response => {
if (response.code === 200) {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
}
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids;
this.$confirm('是否确认删除编号为"' + ids + '"的营养小知识?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return delNutritionQuestion(ids);
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
}).catch(function() {});
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm('是否确认导出所有营养知识小问答数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return exportNutritionQuestion(queryParams);
}).then(response => {
this.download(response.msg);
}).catch(function() {});
}
}
};
</script>