mirror of
https://github.com/201206030/novel-plus.git
synced 2025-07-04 00:16:39 +00:00
上传后台管理系统代码
This commit is contained in:
@ -0,0 +1,21 @@
|
||||
package com.java2nb.common.controller;
|
||||
|
||||
import com.java2nb.system.domain.UserToken;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import com.java2nb.common.utils.ShiroUtils;
|
||||
import com.java2nb.system.domain.UserDO;
|
||||
|
||||
@Controller
|
||||
public class BaseController {
|
||||
public UserDO getUser() {
|
||||
return ShiroUtils.getUser();
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return getUser().getUserId();
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return getUser().getUsername();
|
||||
}
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
package com.java2nb.common.controller;
|
||||
|
||||
import com.java2nb.common.config.Constant;
|
||||
import com.java2nb.common.domain.DictDO;
|
||||
import com.java2nb.common.service.DictService;
|
||||
import com.java2nb.common.utils.PageBean;
|
||||
import com.java2nb.common.utils.Query;
|
||||
import com.java2nb.common.utils.R;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 字典表
|
||||
* @author xiongxy
|
||||
* @email 1179705413@qq.com
|
||||
* @date 2019-09-29 18:28:07
|
||||
*/
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/common/dict")
|
||||
public class DictController extends BaseController {
|
||||
@Autowired
|
||||
private DictService dictService;
|
||||
|
||||
@GetMapping()
|
||||
@RequiresPermissions("common:dict:dict")
|
||||
String dict() {
|
||||
return "common/dict/dict";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/list")
|
||||
@RequiresPermissions("common:dict:dict")
|
||||
public PageBean list(@RequestParam Map<String, Object> params) {
|
||||
// 查询列表数据
|
||||
Query query = new Query(params);
|
||||
List<DictDO> dictList = dictService.list(query);
|
||||
int total = dictService.count(query);
|
||||
PageBean pageBean = new PageBean(dictList, total);
|
||||
return pageBean;
|
||||
}
|
||||
|
||||
@GetMapping("/add")
|
||||
@RequiresPermissions("common:dict:add")
|
||||
String add() {
|
||||
return "common/dict/add";
|
||||
}
|
||||
|
||||
@GetMapping("/edit/{id}")
|
||||
@RequiresPermissions("common:dict:edit")
|
||||
String edit(@PathVariable("id") Long id, Model model) {
|
||||
DictDO dict = dictService.get(id);
|
||||
model.addAttribute("dict", dict);
|
||||
return "common/dict/edit";
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@ResponseBody
|
||||
@PostMapping("/save")
|
||||
@RequiresPermissions("common:dict:add")
|
||||
public R save(DictDO dict) {
|
||||
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
|
||||
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
|
||||
}
|
||||
if (dictService.save(dict) > 0) {
|
||||
return R.ok();
|
||||
}
|
||||
return R.error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequestMapping("/update")
|
||||
@RequiresPermissions("common:dict:edit")
|
||||
public R update(DictDO dict) {
|
||||
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
|
||||
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
|
||||
}
|
||||
dictService.update(dict);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping("/remove")
|
||||
@ResponseBody
|
||||
@RequiresPermissions("common:dict:remove")
|
||||
public R remove(Long id) {
|
||||
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
|
||||
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
|
||||
}
|
||||
if (dictService.remove(id) > 0) {
|
||||
return R.ok();
|
||||
}
|
||||
return R.error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping("/batchRemove")
|
||||
@ResponseBody
|
||||
@RequiresPermissions("common:dict:batchRemove")
|
||||
public R remove(@RequestParam("ids[]") Long[] ids) {
|
||||
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
|
||||
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
|
||||
}
|
||||
dictService.batchRemove(ids);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/type")
|
||||
@ResponseBody
|
||||
public List<DictDO> listType() {
|
||||
return dictService.listType();
|
||||
};
|
||||
|
||||
// 类别已经指定增加
|
||||
@GetMapping("/add/{type}/{description}")
|
||||
@RequiresPermissions("common:dict:add")
|
||||
String addD(Model model, @PathVariable("type") String type, @PathVariable("description") String description) {
|
||||
model.addAttribute("type", type);
|
||||
model.addAttribute("description", description);
|
||||
return "common/dict/add";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/list/{type}")
|
||||
public List<DictDO> listByType(@PathVariable("type") String type) {
|
||||
// 查询列表数据
|
||||
Map<String, Object> map = new HashMap<>(16);
|
||||
map.put("type", type);
|
||||
List<DictDO> dictList = dictService.list(map);
|
||||
return dictList;
|
||||
}
|
||||
}
|
@ -0,0 +1,196 @@
|
||||
package com.java2nb.common.controller;
|
||||
|
||||
import com.java2nb.common.config.JnConfig;
|
||||
import com.java2nb.common.domain.FileDO;
|
||||
import com.java2nb.common.service.FileService;
|
||||
import com.java2nb.common.utils.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
*
|
||||
* @author xiongxy
|
||||
* @email 1179705413@qq.com
|
||||
* @date 2019-09-19 16:02:20
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/common/sysFile")
|
||||
public class FileController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private FileService sysFileService;
|
||||
|
||||
@Autowired
|
||||
private JnConfig jnConfig;
|
||||
|
||||
@GetMapping()
|
||||
@RequiresPermissions("common:sysFile:sysFile")
|
||||
String sysFile(Model model) {
|
||||
Map<String, Object> params = new HashMap<>(16);
|
||||
return "common/file/file";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/list")
|
||||
@RequiresPermissions("common:sysFile:sysFile")
|
||||
public PageBean list(@RequestParam Map<String, Object> params) {
|
||||
// 查询列表数据
|
||||
Query query = new Query(params);
|
||||
List<FileDO> sysFileList = sysFileService.list(query);
|
||||
int total = sysFileService.count(query);
|
||||
PageBean pageBean = new PageBean(sysFileList, total);
|
||||
return pageBean;
|
||||
}
|
||||
|
||||
@GetMapping("/add")
|
||||
// @RequiresPermissions("common:bComments")
|
||||
String add() {
|
||||
return "common/sysFile/add";
|
||||
}
|
||||
|
||||
@GetMapping("/edit")
|
||||
// @RequiresPermissions("common:bComments")
|
||||
String edit(Long id, Model model) {
|
||||
FileDO sysFile = sysFileService.get(id);
|
||||
model.addAttribute("sysFile", sysFile);
|
||||
return "common/sysFile/edit";
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@RequestMapping("/info/{id}")
|
||||
@RequiresPermissions("common:info")
|
||||
public R info(@PathVariable("id") Long id) {
|
||||
FileDO sysFile = sysFileService.get(id);
|
||||
return R.ok().put("sysFile", sysFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@ResponseBody
|
||||
@PostMapping("/save")
|
||||
@RequiresPermissions("common:save")
|
||||
public R save(FileDO sysFile) {
|
||||
if (sysFileService.save(sysFile) > 0) {
|
||||
return R.ok();
|
||||
}
|
||||
return R.error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
@RequiresPermissions("common:update")
|
||||
public R update(@RequestBody FileDO sysFile) {
|
||||
sysFileService.update(sysFile);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping("/remove")
|
||||
@ResponseBody
|
||||
// @RequiresPermissions("common:remove")
|
||||
public R remove(Long id, HttpServletRequest request) {
|
||||
if ("test".equals(getUsername())) {
|
||||
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
|
||||
}
|
||||
String fileName = jnConfig.getUploadPath() + sysFileService.get(id).getUrl().replace("/files/", "");
|
||||
if (sysFileService.remove(id) > 0) {
|
||||
boolean b = FileUtil.deleteFile(fileName);
|
||||
if (!b) {
|
||||
return R.error("数据库记录删除成功,文件删除失败");
|
||||
}
|
||||
return R.ok();
|
||||
} else {
|
||||
return R.error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping("/batchRemove")
|
||||
@ResponseBody
|
||||
@RequiresPermissions("common:remove")
|
||||
public R remove(@RequestParam("ids[]") Long[] ids) {
|
||||
if ("test".equals(getUsername())) {
|
||||
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
|
||||
}
|
||||
sysFileService.batchRemove(ids);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/upload")
|
||||
R upload(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
|
||||
if ("test".equals(getUsername())) {
|
||||
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
|
||||
}
|
||||
Date date = new Date();
|
||||
String year = DateUtils.format(date,DateUtils.YEAR_PATTERN);
|
||||
String month = DateUtils.format(date,DateUtils.MONTH_PATTERN);
|
||||
String day = DateUtils.format(date,DateUtils.DAY_PATTERN);
|
||||
|
||||
String fileName = file.getOriginalFilename();
|
||||
String fileDir = year+"/"+month+"/"+day + "/";
|
||||
fileName = FileUtil.renameToUUID(fileName);
|
||||
FileDO sysFile = new FileDO(FileType.fileType(fileName), "/files/" + fileDir + fileName, date);
|
||||
try {
|
||||
FileUtil.uploadFile(file.getBytes(), jnConfig.getUploadPath()+fileDir, fileName);
|
||||
} catch (Exception e) {
|
||||
return R.error();
|
||||
}
|
||||
|
||||
if (sysFileService.save(sysFile) > 0) {
|
||||
return R.ok().put("fileName",sysFile.getUrl());
|
||||
}
|
||||
return R.error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件下载
|
||||
*/
|
||||
@RequestMapping(value = "/download")
|
||||
public void fileDownload(String filePath,String fileName, HttpServletResponse resp) throws Exception {
|
||||
String realFilePath = jnConfig.getUploadPath() + filePath;
|
||||
InputStream in = new FileInputStream(realFilePath);
|
||||
//设置响应头,对文件进行url编码
|
||||
fileName = URLEncoder.encode(fileName, "UTF-8");
|
||||
resp.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
||||
|
||||
resp.setContentLength(in.available());
|
||||
|
||||
OutputStream out = resp.getOutputStream();
|
||||
byte[] b = new byte[1024];
|
||||
int len = 0;
|
||||
while ((len = in.read(b)) != -1) {
|
||||
out.write(b, 0, len);
|
||||
}
|
||||
out.flush();
|
||||
out.close();
|
||||
in.close();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
package com.java2nb.common.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.java2nb.common.domain.GenColumnsDO;
|
||||
import com.java2nb.common.service.GeneratorService;
|
||||
import com.java2nb.common.utils.GenUtils;
|
||||
import com.java2nb.common.utils.PageBean;
|
||||
import com.java2nb.common.utils.R;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.configuration.Configuration;
|
||||
import org.apache.commons.configuration.ConfigurationException;
|
||||
import org.apache.commons.configuration.PropertiesConfiguration;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RequestMapping("/common/generator")
|
||||
@Controller
|
||||
public class GeneratorController {
|
||||
String prefix = "common/generator";
|
||||
@Autowired
|
||||
GeneratorService generatorService;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@GetMapping()
|
||||
String generator() {
|
||||
return prefix + "/list";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/list")
|
||||
List<Map<String, Object>> list(String tableName) {
|
||||
List<Map<String, Object>> list = generatorService.list(tableName);
|
||||
return list;
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
@RequestMapping("/downLoadCode/{tableName}")
|
||||
public void downLoadCode(HttpServletRequest request, HttpServletResponse response,
|
||||
@PathVariable("tableName") String tableName) throws IOException {
|
||||
String[] tableNames = new String[]{tableName};
|
||||
byte[] data = generatorService.downloadCode(tableNames);
|
||||
response.reset();
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"java2nb.zip\"");
|
||||
response.addHeader("Content-Length", "" + data.length);
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
|
||||
IOUtils.write(data, response.getOutputStream());
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/genCode")
|
||||
public R genCode(String tableName) {
|
||||
String[] tableNames = new String[]{tableName};
|
||||
generatorService.generatorCode(tableNames);
|
||||
return R.ok("代码生成成功,请到本地项目中查看!");
|
||||
}
|
||||
|
||||
@RequestMapping("/batchDownload")
|
||||
public void batchDownload(HttpServletRequest request, HttpServletResponse response, String tables) throws IOException {
|
||||
String[] tableNames = new String[]{};
|
||||
tableNames = JSON.parseArray(tables).toArray(tableNames);
|
||||
byte[] data = generatorService.downloadCode(tableNames);
|
||||
response.reset();
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"java2nb.zip\"");
|
||||
response.addHeader("Content-Length", "" + data.length);
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
|
||||
IOUtils.write(data, response.getOutputStream());
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/batchCode")
|
||||
public R batchCode(String tables) {
|
||||
String[] tableNames = new String[]{};
|
||||
tableNames = JSON.parseArray(tables).toArray(tableNames);
|
||||
generatorService.generatorCode(tableNames);
|
||||
return R.ok("代码批量生成成功,请到本地项目中查看!");
|
||||
}
|
||||
|
||||
@GetMapping("/edit")
|
||||
public String edit(Model model) {
|
||||
Configuration conf = GenUtils.getConfig();
|
||||
Map<String, Object> property = new HashMap<>(16);
|
||||
property.put("author", conf.getProperty("author"));
|
||||
property.put("email", conf.getProperty("email"));
|
||||
property.put("package", conf.getProperty("package"));
|
||||
property.put("autoRemovePre", conf.getProperty("autoRemovePre"));
|
||||
property.put("tablePrefix", conf.getProperty("tablePrefix"));
|
||||
property.put("srcPath", conf.getProperty("srcPath"));
|
||||
model.addAttribute("property", property);
|
||||
return prefix + "/edit";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/update")
|
||||
R update(@RequestParam Map<String, Object> map) {
|
||||
try {
|
||||
PropertiesConfiguration conf = new PropertiesConfiguration("generator.properties");
|
||||
conf.setProperty("author", map.get("author"));
|
||||
conf.setProperty("email", map.get("email"));
|
||||
conf.setProperty("package", map.get("package"));
|
||||
conf.setProperty("autoRemovePre", map.get("autoRemovePre"));
|
||||
conf.setProperty("tablePrefix", map.get("tablePrefix"));
|
||||
conf.setProperty("srcPath", map.get("srcPath"));
|
||||
conf.save();
|
||||
} catch (ConfigurationException e) {
|
||||
return R.error("保存配置文件出错");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/genColumns")
|
||||
String genColumns(String tableName, Model model) {
|
||||
model.addAttribute("tableName", tableName);
|
||||
return "common/genColumns/genColumns";
|
||||
}
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/genColumns/list")
|
||||
@SneakyThrows
|
||||
public R genColumnsList(String tableName) {
|
||||
List<GenColumnsDO> genColumns = generatorService.listColumnsByTableName(tableName);
|
||||
int total = genColumns.size();
|
||||
PageBean pageBean = new PageBean(genColumns, total);
|
||||
return R.ok().put("data", pageBean);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@ApiOperation(value = "新增", notes = "新增")
|
||||
@ResponseBody
|
||||
@PostMapping("/genColumns/save")
|
||||
public R save(@RequestBody List<GenColumnsDO> list) {
|
||||
generatorService.genColumnsSave(list);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.java2nb.common.controller;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
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.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.java2nb.common.domain.LogDO;
|
||||
import com.java2nb.common.domain.PageDO;
|
||||
import com.java2nb.common.service.LogService;
|
||||
import com.java2nb.common.utils.Query;
|
||||
import com.java2nb.common.utils.R;
|
||||
|
||||
@RequestMapping("/common/log")
|
||||
@Controller
|
||||
public class LogController {
|
||||
@Autowired
|
||||
LogService logService;
|
||||
String prefix = "common/log";
|
||||
|
||||
@GetMapping()
|
||||
String log() {
|
||||
return prefix + "/log";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/list")
|
||||
PageDO<LogDO> list(@RequestParam Map<String, Object> params) {
|
||||
Query query = new Query(params);
|
||||
PageDO<LogDO> page = logService.queryList(query);
|
||||
return page;
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/remove")
|
||||
R remove(Long id) {
|
||||
if (logService.remove(id)>0) {
|
||||
return R.ok();
|
||||
}
|
||||
return R.error();
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/batchRemove")
|
||||
R batchRemove(@RequestParam("ids[]") Long[] ids) {
|
||||
int r = logService.batchRemove(ids);
|
||||
if (r > 0) {
|
||||
return R.ok();
|
||||
}
|
||||
return R.error();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user