package com.lf.server.controller.data;
|
|
import com.lf.server.annotation.SysLog;
|
import com.lf.server.controller.all.BaseUploadController;
|
import com.lf.server.entity.all.ResponseMsg;
|
import com.lf.server.entity.ctrl.UploadEntity;
|
import com.lf.server.entity.data.MetaEntity;
|
import com.lf.server.entity.sys.UserEntity;
|
import com.lf.server.helper.StringHelper;
|
import com.lf.server.helper.WebHelper;
|
import com.lf.server.service.data.DataUploadService;
|
import com.lf.server.service.data.MetaService;
|
import io.swagger.annotations.Api;
|
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 java.util.Date;
|
import java.util.List;
|
|
/**
|
* 数据上传
|
* @author WWW
|
*/
|
@Api(tags = "数据管理\\数据上传")
|
@RestController
|
@RequestMapping("/dataUpload")
|
public class DataUploadController extends BaseUploadController {
|
@Autowired
|
MetaService metaService;
|
|
@Autowired
|
DataUploadService dataUploadService;
|
|
private final static String FILE_TYPES = "'file'";
|
|
@SysLog()
|
@ApiOperation(value = "分页查询上传数据并返回记录数")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", example = ""),
|
@ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10"),
|
@ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1")
|
})
|
@GetMapping(value = "/selectByPageForUpload")
|
public ResponseMsg<Object> selectByPageForUpload(String name, Integer pageSize, Integer pageIndex, HttpServletRequest req) {
|
try {
|
if (pageSize < 1 || pageIndex < 1) {
|
return fail("每页页数或分页数小于1", null);
|
}
|
|
UserEntity ue = tokenService.getCurrentUser(req);
|
|
int count = metaService.selectCountForUpload(name, ue.getId(), FILE_TYPES);
|
if (count == 0) {
|
return success(0, null);
|
}
|
|
List<MetaEntity> list = metaService.selectByPageForUpload(name, ue.getId(), FILE_TYPES, pageSize, pageSize * (pageIndex - 1));
|
|
return success(count, list);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "查询文件")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query")
|
})
|
@GetMapping(value = "/selectFiles")
|
public ResponseMsg<List<MetaEntity>> selectFiles(String path) {
|
try {
|
List<MetaEntity> list = baseUploadService.selectFiles(path, null);
|
|
return success(list);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "插入文件")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "entity", value = "上传实体类", dataType = "UploadEntity", paramType = "body")
|
})
|
@ResponseBody
|
@PostMapping(value = "/insertFiles")
|
public ResponseMsg<Object> insertFiles(@RequestBody UploadEntity entity, HttpServletRequest req) {
|
try {
|
UserEntity ue = tokenService.getCurrentUser(req);
|
if (ue == null) {
|
return fail("用户未登录", null);
|
}
|
if (null == entity || null == entity.getMetaEntity()) {
|
return fail("元数据信息为空", null);
|
}
|
|
if (null == entity.getFileEntities() || entity.getFileEntities().isEmpty()) {
|
return fail("没有找到上传文件", null);
|
}
|
|
MetaEntity me = entity.getMetaEntity();
|
me.setCreateTime(WebHelper.getCurrentTimestamp());
|
// me.setBatch(StringHelper.YMDHMS_FORMAT.format(new Date(me.getCreateTime().getTime())))
|
me.setCreateUser(ue.getId());
|
|
int rows = dataUploadService.insertFiles(me, entity.getFileEntities());
|
|
return success("成功", rows);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}
|
}
|