You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.3 KiB

package com.dsideal.base.Res.Controller;
import com.dsideal.base.Interceptor.IsLoginInterface;
import com.dsideal.base.Interceptor.IsNumericInterface;
import com.dsideal.base.Res.Model.ResourceModel;
import com.dsideal.base.Util.CommonUtil;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.ext.interceptor.GET;
import com.jfinal.ext.interceptor.POST;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.upload.UploadFile;
import com.jfinal.plugin.activerecord.Record;
import java.io.UnsupportedEncodingException;
import java.util.UUID;
public class ResourceController extends Controller {
ResourceModel rm = new ResourceModel();
/**
* 获取知识库分页数据
*
* @param pageNum 第几页
* @param pageSize 每页几条
*/
@Before(GET.class)
public void getZskPage(int pageNum, int pageSize) throws UnsupportedEncodingException {
Page<Record> page = rm.getZskPage(pageNum, pageSize);
renderJson(CommonUtil.renderJsonForLayUI(page));
}
/**
* 上传知识库文档
*/
@Before({POST.class})
@IsLoginInterface({})
public void uploadZskDocument() {
UploadFile uploadFile = getFile();
String fileName = uploadFile.getFileName();
String fileExtension = fileName.substring(fileName.lastIndexOf("."));
String name = getPara("name");
String file_id = UUID.randomUUID().toString();
String key = "resource/" + file_id + fileExtension;
// 删除临时文件
try {
uploadFile.getFile().delete();
} catch (Exception e) {
System.out.println("删除文件失败:" + e);
}
//返回
Kv kv = Kv.create();
kv.set("success", true);
kv.set("message", "保存成功");
renderJson(kv);
}
/**
* 删除知识库文档
*
* @param id 知识库文档ID
*/
@Before({POST.class})
@IsNumericInterface({"id"})
@IsLoginInterface({})
public void delZskDocument(int id) {
rm.delZskDocument(id);
Kv kv = Kv.create();
kv.set("success", true);
kv.set("message", "保存成功");
renderJson(kv);
}
}