| | |
| | | package com.lf.server.controller.data; |
| | | |
| | | import com.lf.server.aspect.SysLog; |
| | | import com.lf.server.annotation.SysLog; |
| | | import com.lf.server.controller.all.BaseController; |
| | | import com.lf.server.entity.all.HttpStatus; |
| | | import com.lf.server.entity.all.ResponseMsg; |
| | | import com.lf.server.entity.ctrl.DownloadReqEntity; |
| | | import com.lf.server.entity.data.DownloadEntity; |
| | | import com.lf.server.entity.data.MetaEntity; |
| | | import com.lf.server.entity.data.MetaFileEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.Md5Helper; |
| | | import com.lf.server.helper.RsaHelper; |
| | | import com.lf.server.helper.StringHelper; |
| | | import com.lf.server.helper.WebHelper; |
| | | import com.lf.server.service.data.DownloadService; |
| | | import com.lf.server.service.data.MetaService; |
| | | import com.lf.server.service.sys.TokenService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.*; |
| | | 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 |
| | | */ |
| | | @Api(tags = "数据管理\\元数据管理") |
| | | @Api(tags = "数据管理\\元数据") |
| | | @RestController |
| | | @RequestMapping("/meta") |
| | | public class MetaController extends BaseController { |
| | |
| | | @Autowired |
| | | TokenService tokenService; |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询记录数") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", required = false, example = "") |
| | | }) |
| | | @GetMapping({"/selectCount"}) |
| | | public ResponseMsg<Integer> selectCount(String name) { |
| | | try { |
| | | int count = metaService.selectCount(name); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), -1); |
| | | } |
| | | } |
| | | |
| | | @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 = "/selectByPage") |
| | | public ResponseMsg<List<MetaEntity>> selectByPage(String name, Integer pageSize, Integer pageIndex) { |
| | | try { |
| | | if (pageSize < 1 || pageIndex < 1) { |
| | | return fail("每页页数或分页数小于1", null); |
| | | } |
| | | |
| | | List<MetaEntity> rs = metaService.selectByPage(name, pageSize, pageSize * (pageIndex - 1)); |
| | | |
| | | return success(rs); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | @Autowired |
| | | DownloadService downloadService; |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "分页查询并返回记录数") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "dirid", value = "目录ID", dataType = "Integer", paramType = "query", example = "10"), |
| | | @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 = "/selectByPageAndCount") |
| | | public ResponseMsg<List<MetaEntity>> selectByPageAndCount(String name, Integer pageSize, Integer pageIndex) { |
| | | public ResponseMsg<List<MetaEntity>> selectByPageAndCount(Integer dirid, String name, Integer pageSize, Integer pageIndex) { |
| | | try { |
| | | if (pageSize < 1 || pageIndex < 1) { |
| | | return fail("每页页数或分页数小于1", null); |
| | | } |
| | | int count = metaService.selectCount(name); |
| | | |
| | | int count = metaService.selectCount(dirid, name); |
| | | if (count == 0) { |
| | | return success(0, null); |
| | | } |
| | | List<MetaEntity> rs = metaService.selectByPage(name, pageSize, pageSize * (pageIndex - 1)); |
| | | |
| | | List<MetaEntity> rs = metaService.selectByPage(dirid, name, pageSize, pageSize * (pageIndex - 1)); |
| | | |
| | | return success(count, rs); |
| | | } catch (Exception ex) { |
| | |
| | | entity.setCreateUser(ue.getId()); |
| | | } |
| | | |
| | | entity.setCreateTime(WebHelper.getCurrentTimestamp()); |
| | | int count = metaService.insert(entity); |
| | | |
| | | return success(count); |
| | |
| | | @GetMapping(value = "/delete") |
| | | public ResponseMsg<Integer> delete(int id) { |
| | | try { |
| | | int count = metaService.delete(id); |
| | | // int count = metaService.delete(id) |
| | | int count = metaService.deleteCascade(String.valueOf(id)); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | |
| | | return fail("id数组不能为空", -1); |
| | | } |
| | | |
| | | int count = metaService.deletes(ids); |
| | | // int count = metaService.deletes(ids) |
| | | String idStr = StringHelper.join(ids, ","); |
| | | int count = metaService.deleteCascade(idStr); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | |
| | | return fail(ex.getMessage(), -1); |
| | | } |
| | | } |
| | | |
| | | @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 = "/selectPageCountForDownload") |
| | | public ResponseMsg<List<DownloadEntity>> selectPageCountForDownload(String name, Integer pageSize, Integer pageIndex, HttpServletRequest req) { |
| | | try { |
| | | if (pageSize < 1 || pageIndex < 1) { |
| | | return fail("每页页数或分页数小于1", null); |
| | | } |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue == null) { |
| | | return fail("用户未登录", null); |
| | | } |
| | | |
| | | int count = downloadService.selectCountForUser(ue.getCreateUser(), 3, name); |
| | | if (count == 0) { |
| | | return success(0, null); |
| | | } |
| | | List<DownloadEntity> rs = downloadService.selectByPageForUser(ue.getCreateUser(), 3, name, pageSize, pageSize * (pageIndex - 1)); |
| | | |
| | | return success(count, rs); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "请求下载") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "pwd", value = "密码", dataType = "String", paramType = "body", example = ""), |
| | | @ApiImplicitParam(name = "ids", value = "ID数组", dataType = "Integer", paramType = "body", example = "1,2") |
| | | }) |
| | | @ResponseBody |
| | | @PostMapping(value = "/downloadReq") |
| | | public ResponseMsg<Object> downloadReq(@RequestBody DownloadReqEntity reqEntity, HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | if (null == reqEntity || StringHelper.isEmpty(reqEntity.getPwd())) { |
| | | return fail("密码不能为空"); |
| | | } |
| | | if (null == reqEntity.getIds() || reqEntity.getIds().isEmpty()) { |
| | | return fail("请选择要下载的文件"); |
| | | } |
| | | if (!downloadService.validatePwd(reqEntity)) { |
| | | return fail("密码不符合要求"); |
| | | } |
| | | |
| | | List<MetaFileEntity> list = metaService.selectMetaFiles(reqEntity.getIds()); |
| | | |
| | | return success(true); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "下载文件") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "guid", value = "文件GUID", dataType = "String", paramType = "query") |
| | | }) |
| | | @ResponseBody |
| | | @RequestMapping(value = "/downloadFile", method = RequestMethod.GET) |
| | | public void downloadFile(@RequestBody DownloadReqEntity reqEntity, HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | if (null == reqEntity || StringHelper.isEmpty(reqEntity.getPwd())) { |
| | | WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "密码不能为空", res); |
| | | } |
| | | if (StringHelper.isEmpty(reqEntity.getGuid())) { |
| | | WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "找不到文件ID", res); |
| | | return; |
| | | } |
| | | |
| | | DownloadEntity de = downloadService.selectByGuid(reqEntity.getGuid()); |
| | | if (null == de) { |
| | | WebHelper.writeInfo(HttpStatus.NOT_FOUND, "文件不存在", res); |
| | | return; |
| | | } |
| | | if (!StringHelper.isNull(de.getPwd()) && !Md5Helper.validatePassword(reqEntity.getPwd(), de.getPwd())) { |
| | | WebHelper.writeInfo(HttpStatus.UNAUTHORIZED, "密码不正确", res); |
| | | } |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | de.setDcount(de.getDcount() + 1); |
| | | de.setDownloadUser(ue.getId()); |
| | | int rows = downloadService.update(de); |
| | | |
| | | String filePath = downloadService.getDownloadFilePath(de); |
| | | WebHelper.download(filePath, de.getName(), res); |
| | | } catch (Exception ex) { |
| | | WebHelper.writeInfo(HttpStatus.ERROR, ex.getMessage(), res); |
| | | } |
| | | } |
| | | } |