| | |
| | | import com.lf.server.entity.all.ResponseMsg; |
| | | import com.lf.server.entity.all.StaticData; |
| | | import com.lf.server.entity.ctrl.DownloadReqEntity; |
| | | import com.lf.server.entity.data.DictEntity; |
| | | 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.data.VerEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.*; |
| | | import com.lf.server.mapper.all.BasicMapper; |
| | | import com.lf.server.service.all.BaseQueryService; |
| | | import com.lf.server.service.data.DownloadService; |
| | | import com.lf.server.service.data.MetaService; |
| | | import com.lf.server.service.data.VerService; |
| | | import com.lf.server.service.show.DataLibService; |
| | | import com.lf.server.service.sys.DownlogService; |
| | | import com.lf.server.service.sys.TokenService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | |
| | | import java.io.File; |
| | | import java.net.URLDecoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 资料馆 |
| | |
| | | DataLibService dataLibService; |
| | | |
| | | @Autowired |
| | | DownlogService downlogService; |
| | | |
| | | @Autowired |
| | | DownloadService downloadService; |
| | | |
| | | @Autowired |
| | | BaseQueryService baseQueryService; |
| | | |
| | | @Autowired |
| | | VerService verService; |
| | | |
| | | @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, null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "分页查询元数据") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "depid", value = "单位ID", dataType = "Integer", paramType = "query", example = "1"), |
| | | @ApiImplicitParam(name = "dirid", value = "目录ID", dataType = "Integer", paramType = "query", example = "10"), |
| | | @ApiImplicitParam(name = "depcode", value = "单位编码", dataType = "String", paramType = "query", example = "00"), |
| | | @ApiImplicitParam(name = "dirs", value = "目录编码", dataType = "String", paramType = "query", example = "00,01"), |
| | | @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 = "/selectByPageForMeta") |
| | | public ResponseMsg<List<MetaEntity>> selectByPageForMeta(Integer depid, Integer dirid, String name, Integer pageSize, Integer pageIndex) { |
| | | @GetMapping(value = "/selectMetasForPage") |
| | | public ResponseMsg<Object> selectMetasForPage(String depcode, String dirs, String name, Integer pageSize, Integer pageIndex) { |
| | | try { |
| | | if (pageSize < 1 || pageIndex < 1) { |
| | | return fail("每页页数或分页数小于1", null); |
| | | } |
| | | dirs = DataLibService.copeCodes(dirs, "dircode"); |
| | | |
| | | int count = metaService.selectCount(depid, dirid, name); |
| | | int count = metaService.selectMetasForCount(depcode, dirs, name); |
| | | if (count == 0) { |
| | | return success(0, null); |
| | | } |
| | | |
| | | List<MetaEntity> rs = metaService.selectByPage(depid, dirid, name, pageSize, pageSize * (pageIndex - 1)); |
| | | List<MetaEntity> rs = metaService.selectMetasForPage(depcode, dirs, name, pageSize, pageSize * (pageIndex - 1)); |
| | | |
| | | return success(count, rs); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | QueryWrapper wrapper = new QueryWrapper(); |
| | | //wrapper.eq("dirid", meta.getDirid()); |
| | | //wrapper.eq("depid", meta.getDepid()); |
| | | //wrapper.eq("verid", meta.getVerid()); |
| | | wrapper.eq("createuser", meta.getCreateUser()); |
| | | wrapper.eq("createtime", meta.getCreateTime()); |
| | | wrapper.eq("parentid", meta.getEventid()); |
| | | |
| | | Page<Object> page = new Page<>(pageIndex, pageSize); |
| | | page.addOrder(OrderItem.asc("gid")); |
| | | page.addOrder(OrderItem.desc("gid")); |
| | | IPage<Object> paged = baseMapper.selectPage(page, wrapper); |
| | | |
| | | return success(paged.getTotal(), paged.getRecords()); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "请求元数据下载") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "reqEntity", value = "请求下载实体", dataType = "DownloadReqEntity", paramType = "body") |
| | | @ApiImplicitParam(name = "dr", value = "请求下载实体", dataType = "DownloadReqEntity", paramType = "body") |
| | | }) |
| | | @ResponseBody |
| | | @PostMapping(value = "/downloadReq") |
| | | public ResponseMsg<Object> downloadReq(@RequestBody DownloadReqEntity reqEntity, HttpServletRequest req, HttpServletResponse res) { |
| | | public ResponseMsg<Object> downloadReq(@RequestBody DownloadReqEntity dr, HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | if (null == reqEntity || StringHelper.isEmpty(reqEntity.getPwd())) { |
| | | if (null == dr || StringHelper.isEmpty(dr.getPwd())) { |
| | | return fail("密码不能为空"); |
| | | } |
| | | if (null == reqEntity.getIds() || reqEntity.getIds().isEmpty()) { |
| | | return fail("请选择要下载的文件"); |
| | | if (null == dr.getIds() || dr.getIds().isEmpty()) { |
| | | return fail("请选择要下载的文件ID"); |
| | | } |
| | | if (!downloadService.decryptPwd(reqEntity)) { |
| | | if (!DownloadService.decryptPwd(dr)) { |
| | | return fail("密码解密失败", null); |
| | | } |
| | | if (!StringHelper.checkPwdValid(reqEntity.getPwd())) { |
| | | if (StringHelper.isPwdInvalid(dr.getPwd())) { |
| | | return fail("密码不符合要求"); |
| | | } |
| | | |
| | | List<MetaFileEntity> list = metaService.selectMetaFiles(reqEntity.getIds()); |
| | | if (null == list || list.isEmpty()) { |
| | | return fail("没有找到元数据"); |
| | | } |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | String guid = downloadService.zipFiles(ue, list, reqEntity.getPwd()); |
| | | String guid = metaService.downloadMeteReq(ue, dr); |
| | | |
| | | return success(guid); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | |
| | | pwd = URLDecoder.decode(pwd, StandardCharsets.UTF_8.name()); |
| | | } |
| | | |
| | | String password = downloadService.decryptPwd(pwd); |
| | | String password = DownloadService.decryptPwd(pwd); |
| | | if (null == password) { |
| | | return fail("密码解密失败", null); |
| | | } |
| | |
| | | |
| | | return success(file.exists()); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), false); |
| | | return fail(ex, false); |
| | | } |
| | | } |
| | | |
| | |
| | | }) |
| | | @ResponseBody |
| | | @GetMapping(value = "/downloadFile") |
| | | @SuppressWarnings("AlibabaRemoveCommentedCode") |
| | | public void downloadFile(String guid, String pwd, HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | if (StringHelper.isEmpty(guid) || StringHelper.isEmpty(pwd)) { |
| | | /*if (StringHelper.isEmpty(guid) || StringHelper.isEmpty(pwd)) { |
| | | WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "文件ID和密码不能为空", res); |
| | | } |
| | | if (!pwd.endsWith(StaticData.EQ)) { |
| | | pwd = URLDecoder.decode(pwd, StandardCharsets.UTF_8.name()); |
| | | } |
| | | |
| | | String password = downloadService.decryptPwd(pwd); |
| | | String password = DownloadService.decryptPwd(pwd); |
| | | if (null == password) { |
| | | WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "密码解密失败", res); |
| | | } |
| | | }*/ |
| | | |
| | | DownloadEntity de = downloadService.selectByGuid(guid); |
| | | if (null == de) { |
| | | WebHelper.writeInfo(HttpStatus.NOT_FOUND, "文件不存在", res); |
| | | return; |
| | | } |
| | | if (!StringHelper.isNull(de.getPwd()) && !Md5Helper.validatePassword(password, de.getPwd())) { |
| | | /*if (!StringHelper.isNull(de.getPwd()) && !Md5Helper.validatePassword(password, 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); |
| | | downlogService.updateInfos(ue, de, req); |
| | | |
| | | String filePath = downloadService.getDownloadFilePath(de); |
| | | WebHelper.download(filePath, de.getName(), res); |