package com.lf.server.controller.all;
|
|
import com.lf.server.annotation.SysLog;
|
import com.lf.server.entity.all.ResponseMsg;
|
import com.lf.server.entity.data.DirEntity;
|
import com.lf.server.entity.data.MetaEntity;
|
import com.lf.server.entity.data.VerEntity;
|
import com.lf.server.entity.sys.DepEntity;
|
import com.lf.server.entity.sys.UserEntity;
|
import com.lf.server.service.all.BaseUploadService;
|
import com.lf.server.service.data.DirService;
|
import com.lf.server.service.data.MetaService;
|
import com.lf.server.service.data.VerService;
|
import com.lf.server.service.sys.DepService;
|
import com.lf.server.service.sys.TokenService;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.util.List;
|
|
/**
|
* 父上传控制器
|
* @author WWW
|
*/
|
public class BaseUploadController extends BaseController {
|
@Autowired
|
DepService depService;
|
|
@Autowired
|
DirService dirService;
|
|
@Autowired
|
VerService verService;
|
|
@Autowired
|
MetaService metaService;
|
|
@Autowired
|
protected TokenService tokenService;
|
|
@Autowired
|
protected BaseUploadService baseUploadService;
|
|
@SysLog()
|
@ApiOperation(value = "查询所有单位")
|
@GetMapping(value = "/selectDepAll")
|
public ResponseMsg<List<DepEntity>> selectDepAll() {
|
try {
|
List<DepEntity> list = depService.selectDepAll();
|
|
return success(list);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "查询所有目录")
|
@GetMapping(value = "/selectDirAll")
|
public ResponseMsg<List<DirEntity>> selectDirAll() {
|
try {
|
List<DirEntity> list = dirService.selectDirAll();
|
|
return success(list);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "根据目录ID查询版本列表")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "dirid", value = "目录ID", dataType = "Integer", paramType = "query")
|
})
|
@GetMapping(value = "/selectVerByDirid")
|
public ResponseMsg<List<VerEntity>> selectVerByDirid(Integer dirid) {
|
try {
|
if (null == dirid || dirid < 0) {
|
dirid = 0;
|
}
|
|
List<VerEntity> list = verService.selectByDirid(dirid);
|
if (null == list || list.isEmpty()) {
|
list = verService.selectByDirid(0);
|
}
|
|
return success(list);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "查询路径")
|
@GetMapping(value = "/selectPath")
|
public ResponseMsg<String> selectPath() {
|
try {
|
String pathName = baseUploadService.selectPath();
|
|
return success(pathName);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "上传文件")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query")
|
})
|
@ResponseBody
|
@PostMapping(value = "/uploadFiles")
|
public ResponseMsg<Object> uploadFiles(String path, HttpServletRequest req, HttpServletResponse res) {
|
try {
|
UserEntity ue = tokenService.getCurrentUser(req);
|
if (ue == null) {
|
return fail("用户未登录", null);
|
}
|
|
List<MetaEntity> list = baseUploadService.uploadData(null, path, req, res);
|
if (null == list || list.isEmpty()) {
|
return fail("没有找到上传文件", null);
|
}
|
|
return success(list);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "删除文件")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "list", value = "实体类集合", dataType = "MetaEntity", paramType = "body")
|
})
|
@ResponseBody
|
@PostMapping(value = "/deleteFiles")
|
public ResponseMsg<Object> deleteFiles(@RequestBody List<MetaEntity> list, HttpServletRequest req) {
|
try {
|
UserEntity ue = tokenService.getCurrentUser(req);
|
if (ue == null) {
|
return fail("用户未登录", null);
|
}
|
if (null == list || list.isEmpty()) {
|
return fail("没有找到文件", null);
|
}
|
|
int rows = baseUploadService.deleteFiles(list);
|
|
return success("成功", rows);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "删除元数据")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "ids", value = "ID数组", dataType = "Integer", paramType = "query", example = "1,2")
|
})
|
@GetMapping(value = "/deleteMetas")
|
public ResponseMsg<Integer> deleteMetas(@RequestParam List<Integer> ids) {
|
try {
|
if (ids == null || ids.isEmpty()) {
|
return fail("id数组不能为空", -1);
|
}
|
|
int count = metaService.deletes(ids);
|
|
return success(count);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), -1);
|
}
|
}
|
}
|