Browse Source

智能讲解

xyg 2 năm trước cách đây
mục cha
commit
b4736764a4

+ 31 - 5
spring-cloud/server-basic/src/main/java/com/jd/controller/SmartExplainController.java

@@ -1,17 +1,17 @@
 package com.jd.controller;
 
 import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jd.code.ConstString;
 import com.jd.entity.SmartExplain;
 import com.jd.service.SmartExplainService;
+import com.jd.util.Blank;
 import com.jd.util.SendUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.util.Map;
@@ -20,7 +20,7 @@ import java.util.Map;
 @Slf4j
 @RestController()
 @RequestMapping("/api/smart/explain")
-@Api(tags="智能讲解(视频/图片)")
+@Api(tags = "智能讲解(视频/图片)")
 public class SmartExplainController {
 
     @Resource
@@ -37,6 +37,7 @@ public class SmartExplainController {
     @PostMapping("/addBean")
     @ApiOperation(value = "2、新增")
     public Map<String, Object> addBean(SmartExplain smartExplain) {
+        smartExplain.setStatus(20);
         smartExplain.setCreateTime(DateUtil.now());
         return SendUtil.send(true, null, smartExplainService.save(smartExplain));
     }
@@ -54,4 +55,29 @@ public class SmartExplainController {
         return SendUtil.send(true, null, smartExplainService.removeById(id));
     }
 
+    @GetMapping("/find/{id}")
+    @ApiOperation(value = "5、根据id查询")
+    public Map<String, Object> findById(@PathVariable("id") Integer id) {
+        return SendUtil.send(true, null, smartExplainService.getById(id));
+    }
+
+    @PostMapping("/updateStatus")
+    @ApiOperation(value = "6、修改启用状态")
+    public Map<String, Object> findById(Integer id, Integer status) {
+        // 判断参数
+        if (Blank.isEmpty(id, status)) {
+            return SendUtil.send(false, ConstString.REQUEST_WRONGPARAMS);
+        }
+        SmartExplain bean = smartExplainService.getById(id);
+        if (bean == null) {
+            return SendUtil.send(false);
+        }
+        //如果是启用某个讲解,则禁用掉这个讲解类型的其他讲解数据
+        if (status == 10) {
+            smartExplainService.disableOther(bean.getExplainType());
+        }
+        //修改状态
+        bean.setStatus(status);
+        return SendUtil.send(true, null, smartExplainService.updateById(bean));
+    }
 }

+ 5 - 1
spring-cloud/server-basic/src/main/java/com/jd/mapper/SmartExplainMapper.java

@@ -2,7 +2,11 @@ package com.jd.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.jd.entity.SmartExplain;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Update;
 
 public interface SmartExplainMapper extends BaseMapper<SmartExplain> {
-	
+
+    @Update("UPDATE t_smart_explain SET status = 20 WHERE explain_type = #{type}")
+    Integer disableOther(@Param("type") Integer type);
 }

+ 2 - 0
spring-cloud/server-basic/src/main/java/com/jd/service/SmartExplainService.java

@@ -9,5 +9,7 @@ import java.util.Map;
 
 public interface SmartExplainService extends IService<SmartExplain> {
 
+    Boolean disableOther(Integer type);
+
 
 }

+ 4 - 0
spring-cloud/server-basic/src/main/java/com/jd/service/impl/SmartExplainServiceImpl.java

@@ -8,4 +8,8 @@ import org.springframework.stereotype.Service;
 
 @Service
 public class SmartExplainServiceImpl extends ServiceImpl<SmartExplainMapper, SmartExplain> implements SmartExplainService {
+    @Override
+    public Boolean disableOther(Integer type) {
+        return baseMapper.disableOther(type)>0;
+    }
 }

+ 470 - 0
spring-cloud/server-page/src/main/resources/static/page/js/basic/smartExplain.js

@@ -0,0 +1,470 @@
+let form, table, uploadInst;
+let ACCEPT = 'images';
+layui.config({
+    base: 'js/encryption/'
+}).use(['layer', 'form', 'jquery', 'table', 'upload', 'ajax'], function () {
+    layer = layui.layer;
+    upload = layui.upload;
+    table = layui.table;
+    form = layui.form;
+    $ = layui.jquery;
+    ly = layui.ajax;
+
+    // 主要表格
+    table.render({
+        elem: '#explainTable',
+        url: PAGE_BASIC + '/api/smart/explain/list',
+        toolbar: '#explainTable_toolbar', //开启头部工具栏,并为其绑定左侧模板
+        page: true,
+        cols: [
+            [{
+                type: 'numbers',
+                title: '序号'
+            }, {
+                field: 'explainName',
+                title: '讲解名称',
+            }, {
+                field: 'explainType',
+                title: '讲解类型',
+                templet: function (d) {
+                    if (d.explainType == 10) {
+                        return '视频讲解';
+                    } else {
+                        return '图片讲解';
+                    }
+                }
+            }, {
+                field: 'status',
+                title: '状态',
+                templet: function (d) {
+                    if (d.status == 10) {
+                        return '已启用';
+                    } else {
+                        return '已停用';
+                    }
+                }
+            }, {
+                field: 'createTime',
+                title: '创建时间'
+            }, {
+                fixed: 'right',
+                title: '操作',
+                toolbar: '#explainTable_bar',
+                width: 250
+            }]
+        ]
+    });
+
+    //头工具栏事件(主要表格)
+    table.on('toolbar(explainTable)', function (obj) {
+        // var checkStatus = table.checkStatus(obj.config.id);
+        switch (obj.event) {
+            case 'add': //新增
+                $(".main").addClass("layui-hide").removeClass("layui-show");
+                $(".add").addClass("layui-show").removeClass("layui-hide");
+                $('#submit').attr('submitType', 'insert');
+                $(".add .header_title span").html("新增");
+                $('#explainInfo')[0].reset();
+                break;
+        }
+    });
+
+    //监听行工具事件(主要表格)
+    table.on('tool(explainTable)', function (obj) {
+        let data = obj.data;
+        //console.log(obj)
+        if (obj.event === 'del') {
+            layer.confirm('是否确认删除', function (index) {
+                deleteExplain(data.id);
+                layer.close(index);
+            });
+        } else if (obj.event === 'edit') {
+            $(".main").addClass("layui-hide").removeClass("layui-show");
+            $(".add").addClass("layui-show").removeClass("layui-hide");
+            $(".add .header_title span").html("编辑");
+            $('#submit').attr('submitType', 'update');
+            $('#explainInfo')[0].reset();
+            // 数据初始化
+            echoExplainInfo(data.id);
+        } else if (obj.event === 'disable') {
+            updateStatus(data.id, 20);
+        } else if (obj.event === 'enable') {
+            updateStatus(data.id, 10);
+        }
+    });
+
+    form.on('select(explainType)', function (data) {
+        console.log(data.value); //得到被选中的值
+        if (data.value) {
+            $('.operation').removeClass('layui-hide');
+            $('#list').removeClass('layui-hide');
+            if (data.value == 20) {
+                ACCEPT = 'images';
+                uploadInst.reload({
+                    accept: ACCEPT, //只允许上传图片
+                    acceptMime: 'image/*', //只筛选图片
+                    data: {
+                        'prefix': ACCEPT
+                    },
+                });
+                $('#additionBtn').removeClass('layui-hide');
+            } else {
+                ACCEPT = 'video';
+                uploadInst.reload({
+                    accept: ACCEPT, //只允许上传图片
+                    acceptMime: 'video/*', //只筛选图片
+                    data: {
+                        'prefix': ACCEPT
+                    },
+                });
+                $('#additionBtn').addClass('layui-hide');
+            }
+        } else {
+            ACCEPT = 'images';
+            uploadInst.reload({
+                accept: ACCEPT, //只允许上传图片
+                acceptMime: 'image/*', //只筛选图片
+                data: {
+                    'prefix': ACCEPT
+                },
+            });
+            $('#additionBtn').addClass('layui-hide');
+            $('.operation').addClass('layui-hide');
+            $('#list').addClass('layui-hide');
+        }
+    });
+
+    uploadInst = upload.render({
+        elem: '#uploadBtn', //绑定元素
+        url: PAGE_BASIC + '/upload/fileUpload',
+        accept: ACCEPT,
+        headers: {
+            'timestamp': new Date().getTime(),
+            'Authorization': sessionStorage.TOKEN_TYPE + ' ' + sessionStorage.ACCESS_TOKEN
+        },
+        data: {
+            'prefix': ACCEPT
+        },
+        before: function (obj) {
+            layer.load(2); //上传loading
+        },
+        done: function (res) {
+            layer.closeAll('loading');
+            //上传完毕回调
+            console.info(res)
+            if (res.data) {
+                let fileUrl = $('#fileUrl').val();
+                if (fileUrl) {
+                    fileUrl = fileUrl + ';' + res.data.filePath;
+                } else {
+                    fileUrl = res.data.filePath;
+                }
+                $('#fileUrl').val(fileUrl);
+                console.info($('#fileUrl').val())
+            }
+        },
+        error: function (err) {
+            //请求异常回调
+            console.error(err)
+            layer.closeAll('loading');
+        }
+    });
+
+    // 验证表单
+    form.verify({
+        explainName: function (value, item) {
+            if (!value.trim()) {
+                return '讲解名称不能为空';
+            }
+        },
+        explainType: function (value, item) {
+            if (!value.trim()) {
+                return '请选择讲解类型';
+            }
+        },
+        fileUrl: function (value, item) {
+            if (!value.trim()) {
+                return '请上传讲解文件';
+            }
+        },
+        content: function (value, item) {
+            if (!value.trim()) {
+                return '请输入语音文本内容';
+            }
+        }
+    });
+
+    // 监听提交按钮
+    form.on('submit(submit)', function (data) {
+        let submitType = data.elem.getAttribute("submitType");
+        // 新增
+        if (submitType == 'insert') {
+            addExplain();
+            return false;
+        } else if (submitType == 'update') {
+            updateExplain();
+            return false;
+        }
+    });
+
+    // 查询
+    $(".search_btn").click(function () {
+        let queryValue = $.trim($("#queryValue").val());
+        table.reload('explainTable', {
+            where: {
+                "queryVal": queryValue
+            },
+            page: {
+                curr: 1 //重新从第 1 页开始
+            }
+        }); //只重载数据
+    });
+
+    //基础数据搜索回车事件
+    $('#queryValue').bind('keypress', function (event) {
+        if (event.keyCode == "13") {
+            $(".search_btn").click();
+            // let queryValue = $.trim($("#queryValue").val());
+            // table.reload('explainTable', {
+            //     where: {
+            //         "queryVal": queryValue
+            //     },
+            //     page: {
+            //         curr: 1 //重新从第 1 页开始
+            //     }
+            // }); //只重载数据
+        }
+    });
+
+    // 返回
+    $(".back").click(function () {
+        $(".main").addClass("layui-show").removeClass("layui-hide");
+        $(".add").addClass("layui-hide").removeClass("layui-show");
+    });
+
+});
+
+/**
+ * 新增智能讲解
+ */
+function addExplain() {
+    let postData = form.val('explainInfo');
+    let index = layer.load(2);
+    ly.ajax({
+        type: 'POST',
+        url: PAGE_BASIC + '/api/smart/explain/addBean',
+        dataType: 'json',
+        data: postData,
+        success: function (json) {
+            if (json.result) {
+                layer.msg("新增成功");
+                $(".main").addClass("layui-show").removeClass("layui-hide");
+                $(".add").addClass("layui-hide").removeClass("layui-show");
+                reloadTable();
+            } else {
+                layer.msg("新增失败");
+            }
+            layer.close(index);
+        },
+        error: function (msg) {
+            layer.close(index);
+        }
+    });
+}
+
+/**
+ * 编辑智能讲解
+ */
+function updateExplain() {
+    let postData = form.val('explainInfo');
+    let index = layer.load(2);
+    ly.ajax({
+        type: 'POST',
+        url: PAGE_BASIC + '/api/smart/explain/updateBean',
+        dataType: 'json',
+        data: postData,
+        success: function (json) {
+            if (json.result) {
+                layer.msg("编辑成功");
+                $(".main").addClass("layui-show").removeClass("layui-hide");
+                $(".add").addClass("layui-hide").removeClass("layui-show");
+                reloadTable();
+            } else {
+                layer.msg("编辑失败");
+            }
+            layer.close(index);
+        },
+        error: function (msg) {
+            layer.close(index);
+        }
+    });
+}
+
+/**
+ * 回显智能讲解详情
+ * @param id
+ */
+function echoExplainInfo(id) {
+    let index = layer.load(2);
+    ly.ajax({
+        type: 'GET',
+        url: PAGE_BASIC + '/api/smart/explain/find/' + id,
+        dataType: 'json',
+        success: function (json) {
+            if (json.result) {
+                $('#id').val(id);
+                $('#explainName').val(json.data.explainName);
+                $('#explainType').val(json.data.explainType);
+                $('#fileUrl').val(json.data.fileUrl);
+                $('#content').val(json.data.content);
+                $('#list').removeClass('layui-hide');
+                if (json.data.explainType == 10) {
+                    ACCEPT = 'video';
+                    uploadInst.reload({
+                        accept: ACCEPT, //只允许上传图片
+                        acceptMime: 'video/*', //只筛选图片
+                        data: {
+                            'prefix': ACCEPT
+                        },
+                    });
+                } else {
+                    ACCEPT = 'images';
+                    uploadInst.reload({
+                        accept: ACCEPT, //只允许上传图片
+                        acceptMime: 'image/*', //只筛选图片
+                        data: {
+                            'prefix': ACCEPT
+                        },
+                    });
+                }
+                form.render();
+            } else {
+                layer.msg("数据获取失败");
+            }
+            layer.close(index);
+        },
+        error: function (msg) {
+            layer.close(index);
+        }
+    });
+}
+
+/**
+ * 删除智能讲解
+ * @param id
+ */
+function deleteExplain(id) {
+    let index = layer.load(2);
+    ly.ajax({
+        type: 'POST',
+        url: PAGE_BASIC + '/api/smart/explain/deleteById',
+        dataType: 'json',
+        data: {
+            "id": id,
+        },
+        success: function (json) {
+            if (json.result) {
+                layer.msg("删除成功");
+                reloadTable();
+            } else {
+                layer.msg("删除失败");
+            }
+            layer.close(index);
+        },
+        error: function (msg) {
+            layer.close(index);
+        }
+    });
+}
+
+/**
+ * 重载数据表格
+ */
+function reloadTable() {
+    table.reload('explainTable', {
+        page: {
+            curr: 1 //重新从第 1 页开始
+        }
+    }); //只重载数据
+}
+
+/**
+ * 插入语言间隔时间
+ */
+function insertTime() {
+    let timestamp = $.trim($('#timestamp').val());
+    if (!timestamp) {
+        layer.msg('请输入语音时间间隔', {icon: 5});
+        return false;
+    }
+    if (timestamp < 100 || timestamp > 600000) {
+        layer.msg('语音时间间隔,最小100毫秒,最大10分钟', {icon: 5});
+        return false;
+    }
+    let tc = document.getElementById("content");
+    let tclen = tc.value.length;
+    tc.focus();
+    // 兼容性检查
+    if (typeof document.selection != "undefined") {
+        // document.selection.createRange().text = timestamp;
+    } else {
+        tc.value =
+            // 获取光标的开始位置
+            tc.value.substr(0, tc.selectionStart) + `[p` + (timestamp).toString() + `]` + tc.value.substring(tc.selectionStart, tclen);
+    }
+}
+
+/**
+ * 变更启用状态
+ * @param id
+ * @param status
+ */
+function updateStatus(id, status) {
+    let index = layer.load(2);
+    ly.ajax({
+        type: 'POST',
+        url: PAGE_BASIC + '/api/smart/explain/updateStatus',
+        dataType: 'json',
+        data: {
+            'id': id,
+            'status': status
+        },
+        success: function (json) {
+            if (json.result) {
+                layer.msg("变更成功");
+                reloadTable();
+            } else {
+                layer.msg("变更失败");
+            }
+            layer.close(index);
+        },
+        error: function (msg) {
+            layer.close(index);
+        }
+    });
+}
+
+/**
+ * 添加更多语音内容
+ */
+function addItem() {
+    let count = $('.content').length;
+    let html = `<div class="layui-form-item">
+                    <label class="layui-form-label"><span class="font-red">*</span>语音内容` + (++count) + `:</label>
+                    <div class="layui-input-inline" style="display: flex">
+                        <textarea class="layui-textarea content" lay-verify="content" placeholder="请输入语音内容" autocomplete="off"></textarea>
+                        <button type="button" class="layui-btn" style="margin-left: 20px;" onclick="removeItem(this)">
+                            <i class="layui-icon">&#xe616;</i>移除
+                        </button>
+                    </div>
+                </div>`;
+    $('#list').append(html);
+}
+
+/**
+ * 移除当前语音内容
+ * @param obj
+ */
+function removeItem(obj) {
+    $(obj).parent().parent().remove();
+}

+ 128 - 0
spring-cloud/server-page/src/main/resources/static/page/smartExplain.html

@@ -0,0 +1,128 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+    <meta charset="UTF-8">
+    <meta name="renderer" content="webkit">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
+    <title>智能讲解</title>
+    <link rel="stylesheet" type="text/css" href="layui/css/layui.css"/>
+    <link rel="stylesheet" type="text/css" href="css/admin.css"/>
+    <link rel="stylesheet" type="text/css" href="css/common.css"/>
+    <link rel="stylesheet" type="text/css" href="css/animate.css"/>
+</head>
+<style>
+    .layui-form-item .layui-input-inline {
+        width: 60%;
+    }
+
+    .layui-textarea {
+        resize: none;
+        height: 100px;
+    }
+</style>
+<body>
+<!-- 主要内容 -->
+<div class="main fadeIn animated">
+    <div class="header_title"><span>智能讲解</span></div>
+    <div class="main_content">
+        <table class="layui-hide" id="explainTable" lay-filter="explainTable"></table>
+
+        <script type="text/html" id="explainTable_toolbar">
+            {{# if (sessionStorage.getItem("menuid-" + sessionStorage.MENU_ID + "-add")  == 'add') { }}
+            <div class="layui-btn-container">
+                <button class="layui-btn layui-btn-sm main_head_btn" lay-event="add"><span class="iconfont">&#xe607;</span>新增</button>
+            </div>
+            {{# } }}
+        </script>
+
+        <script type="text/html" id="explainTable_bar">
+            {{# if (d.status == 10) { }}
+            <a class="main_tab_btn" lay-event="disable" style="color: #5FB878;" title="停用"><span class="iconfont">&#xe716;</span>停用</a>
+            {{# } else { }}
+            <a class="main_tab_btn" lay-event="enable" style="color: #5FB878;" title="启用"><span class="iconfont">&#xe716;</span>启用</a>
+            {{# } }}
+            {{# if (sessionStorage.getItem("menuid-" + sessionStorage.MENU_ID + "-update") == 'update') { }}
+            <a class="main_tab_btn" lay-event="edit" style="color: #64ADF9;"><span class="iconfont">&#xe637;</span>编辑</a>
+            {{# } }}
+            {{# if (sessionStorage.getItem("menuid-" + sessionStorage.MENU_ID + "-delete") == 'delete') { }}
+            <a class="main_tab_btn" lay-event="del" style="color: #FC7D8C;"><span class="iconfont">&#xe78d;</span>删除</a>
+            {{# } }}
+        </script>
+
+        <div class="search_box">
+            <div class="layui-input-inline">
+                <input type="text" name="queryValue" id="queryValue" autocomplete="off" class="layui-input" placeholder="请输会议名称查询"/>
+            </div>
+            <button type="button" class="layui-btn layui-btn-sm search_btn">搜 索</button>
+        </div>
+    </div>
+</div>
+
+<!-- 新增 -->
+<div class="add layui-hide fadeIn animated">
+    <div class="header_title"><span>新增</span></div>
+    <div class="main_content">
+        <form class="layui-form" action="" id="explainInfo" lay-filter="explainInfo">
+            <input type="hidden" class="layui-hide" id="id" name="id" readonly=""/>
+            <div class="layui-form-item">
+                <label class="layui-form-label"><span class="font-red">*</span>讲解名称:</label>
+                <div class="layui-input-inline">
+                    <input type="text" class="layui-input" id="explainName" name="explainName" lay-verify="explainName" autocomplete="off" placeholder="请输入讲解名称" maxlength="100"/>
+                </div>
+            </div>
+            <div class="layui-form-item">
+                <label class="layui-form-label"><span class="font-red">*</span>讲解类型:</label>
+                <div class="layui-input-inline">
+                    <select class="layui-select" id="explainType" name="explainType" lay-verify="explainType" lay-filter="explainType" lay-search="">
+                        <option value="">请选择讲解类型</option>
+                        <option value="10">视频讲解</option>
+                        <option value="20">图片讲解</option>
+                    </select>
+                </div>
+            </div>
+            <div class="operation layui-hide">
+                <div class="layui-form-item">
+                    <label class="layui-form-label">
+                        <button type="button" class="layui-btn" id="uploadBtn">
+                            <i class="layui-icon">&#xe67c;</i>上传文件
+                        </button>
+                    </label>
+                    <div class="layui-input-inline" style="display: flex;margin-left: 50px;">
+                        <input type="hidden" id="fileUrl" name="fileUrl" lay-verify="fileUrl">
+                        <input type="number" class="layui-input" style="width: 300px;" id="timestamp" step="100" placeholder="间隔时间,最小100毫秒,最大10分钟" max="600000" autocomplete="off">
+                        毫秒
+                        <button type="button" class="layui-btn" style="margin-left: 20px;" onclick="insertTime();">
+                            <i class="layui-icon">&#xe624;</i>插入间隔时间
+                        </button>
+                        <button type="button" class="layui-btn layui-hide" style="margin-left: 20px;" id="additionBtn" onclick="addItem()">
+                            <i class="layui-icon">&#xe61f;</i>更多
+                        </button>
+                    </div>
+                </div>
+                <div id="list">
+                    <div class="layui-form-item">
+                        <label class="layui-form-label"><span class="font-red">*</span>语音内容:</label>
+                        <div class="layui-input-inline">
+                            <textarea class="layui-textarea" id="content" name="content" lay-verify="content" placeholder="请输入语音内容" autocomplete="off"></textarea>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <button type="submit" id="submit" class="layui-btn submit_btn" lay-submit="" lay-filter="submit" submitType="" style="margin-left: 50px;margin-top: 30px;">提交</button>
+            <button type="button" class="layui-btn layui-btn-primary back back_btn" style="margin-top: 30px;">返回</button>
+        </form>
+    </div>
+</div>
+
+<script src="layui/layui.js" type="text/javascript" charset="utf-8"></script>
+<script src="js/common.js" type="text/javascript" charset="utf-8"></script>
+<script src="js/constants.js" type="text/javascript" charset="utf-8"></script>
+<script src="js/js-util.js" type="text/javascript" charset="utf-8"></script>
+<script src="js/base64.js" type="text/javascript" charset="utf-8"></script>
+<script src="js/basic/smartExplain.js" type="text/javascript" charset="utf-8"></script>
+
+</body>
+
+</html>