From e26af85e049516e6ce2b082bc2bc90bf71643e95 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期五, 24 三月 2023 09:06:30 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/controller/data/MetaController.java | 281 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 225 insertions(+), 56 deletions(-) diff --git a/src/main/java/com/lf/server/controller/data/MetaController.java b/src/main/java/com/lf/server/controller/data/MetaController.java index 494e1e4..570b643 100644 --- a/src/main/java/com/lf/server/controller/data/MetaController.java +++ b/src/main/java/com/lf/server/controller/data/MetaController.java @@ -1,20 +1,30 @@ package com.lf.server.controller.data; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.metadata.OrderItem; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.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.ClassHelper; 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.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.sys.DownlogService; import com.lf.server.service.sys.TokenService; import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; @@ -22,13 +32,16 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.List; /** * 鍏冩暟鎹� * @author WWW */ -@Api(tags = "鏁版嵁绠$悊\\鍏冩暟鎹�") +@Api(tags = "鏁版嵁绠$悊\\淇℃伅绠$悊") @RestController @RequestMapping("/meta") public class MetaController extends BaseController { @@ -39,46 +52,98 @@ TokenService tokenService; @Autowired + BaseQueryService baseQueryService; + + @Autowired + DownlogService downlogService; + + @Autowired DownloadService downloadService; + + @Autowired + VerService verService; @SysLog() @ApiOperation(value = "鍒嗛〉鏌ヨ骞惰繑鍥炶褰曟暟") @ApiImplicitParams({ - @ApiImplicitParam(name = "dirid", value = "鐩綍ID", dataType = "Integer", paramType = "query", example = "10"), + @ApiImplicitParam(name = "depcode", value = "鍗曚綅缂栫爜", dataType = "String", paramType = "query", example = "00"), + @ApiImplicitParam(name = "dircode", value = "鐩綍缂栫爜", dataType = "String", paramType = "query", example = "00"), + @ApiImplicitParam(name = "verid", value = "鐗堟湰ID", dataType = "Integer", paramType = "query", example = "0"), @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(Integer dirid, String name, Integer pageSize, Integer pageIndex) { + public ResponseMsg<List<MetaEntity>> selectByPageAndCount(String depcode, String dircode, Integer verid, String name, Integer pageSize, Integer pageIndex) { try { if (pageSize < 1 || pageIndex < 1) { return fail("姣忛〉椤垫暟鎴栧垎椤垫暟灏忎簬1", null); } - int count = metaService.selectCount(dirid, name); + int count = metaService.selectCount(depcode, dircode, verid, name); if (count == 0) { return success(0, null); } - List<MetaEntity> rs = metaService.selectByPage(dirid, name, pageSize, pageSize * (pageIndex - 1)); + List<MetaEntity> rs = metaService.selectByPage(depcode, dircode, verid, name, pageSize, pageSize * (pageIndex - 1)); return success(count, rs); } catch (Exception ex) { - return fail(ex.getMessage(), null); + return fail(ex, null); } } @SysLog() - @ApiOperation(value = "鏌ヨ鎵�鏈�") - @GetMapping(value = "/selectAll") - public ResponseMsg<List<MetaEntity>> selectAll() { + @ApiOperation(value = "鏍规嵁鐖禝D鍒嗛〉鏌ヨ骞惰繑鍥炶褰曟暟") + @ApiImplicitParams({ + @ApiImplicitParam(name = "metaid", value = "鐖禝D", dataType = "String", paramType = "query", example = "0"), + @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 = "/selectPageAndCountByPid") + public ResponseMsg<List<MetaEntity>> selectPageAndCountByPid(Integer metaid, String name, Integer pageSize, Integer pageIndex) { try { - List<MetaEntity> list = metaService.selectAll(); + if (pageSize < 1 || pageIndex < 1) { + return fail("姣忛〉椤垫暟鎴栧垎椤垫暟灏忎簬1", null); + } + if (null == metaid || metaid < 1) { + return fail("鐖禝D涓嶈兘涓虹┖涓斿ぇ浜�1", null); + } + + int count = metaService.selectCountByPid(metaid, name); + if (count == 0) { + return success(0, null); + } + + List<MetaEntity> rs = metaService.selectPageByPid(metaid, name, pageSize, pageSize * (pageIndex - 1)); + + return success(count, rs); + } catch (Exception ex) { + return fail(ex, 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); + return fail(ex, null); } } @@ -94,7 +159,67 @@ return success(entity); } catch (Exception ex) { - return fail(ex.getMessage(), null); + return fail(ex, null); + } + } + + @SysLog() + @ApiOperation(value = "鏌ヨ琛ㄤ腑鏁版嵁") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "鍏冩暟鎹甀D", dataType = "Integer", paramType = "query", example = "115"), + @ApiImplicitParam(name = "pageIndex", value = "鍒嗛〉鏁帮紙浠�1寮�濮嬶級", dataType = "Integer", paramType = "query", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "姣忛〉鏉℃暟", dataType = "Integer", paramType = "query", example = "10") + }) + @GetMapping(value = "/selectDbData") + public ResponseMsg<Object> selectDbData(Integer id, Integer pageIndex, Integer pageSize) { + // noinspection AlibabaRemoveCommentedCode + try { + if (null == id || id < 0) { + return fail("鍏冩暟鎹甀D涓嶈兘涓虹┖鎴栧皬浜�0", null); + } + + MetaEntity meta = metaService.selectById(id); + if (null == meta || null == meta.getTab() || !meta.getTab().contains(StaticData.POINT)) { + return fail("鎵句笉鍒板厓鏁版嵁淇℃伅", null); + } + + String entity = meta.getTab().substring(meta.getTab().indexOf(".") + 1).replace("_", "").toLowerCase(); + BasicMapper baseMapper = ClassHelper.getBasicMapper(entity); + if (null == baseMapper) { + return null; + } + + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq("parentid", meta.getEventid()); + + Page<Object> page = new Page<>(pageIndex, pageSize); + page.addOrder(OrderItem.desc("gid")); + IPage<Object> paged = baseMapper.selectPage(page, wrapper); + + return success(paged.getTotal(), paged.getRecords()); + } catch (Exception ex) { + return fail(ex, null); + } + } + + @SysLog() + @ApiOperation(value = "鏌ヨ瀛楁淇℃伅") + @ApiImplicitParams({ + @ApiImplicitParam(name = "ns", value = "鍚嶇О绌洪棿", dataType = "String", paramType = "query", example = "bd"), + @ApiImplicitParam(name = "tab", value = "琛ㄥ悕", dataType = "String", paramType = "query", example = "dlg25wAanp") + }) + @GetMapping(value = "/selectTabFields") + public ResponseMsg<List<DictEntity>> selectTabFields(String ns, String tab) { + try { + if (StringHelper.isEmpty(ns) || StringHelper.isEmpty(tab)) { + return fail("鍚嶇О绌洪棿鍜岃〃鍚嶄笉鑳戒负绌�", null); + } + + List<DictEntity> list = baseQueryService.selectFields(ns, tab); + + return success(list); + } catch (Exception ex) { + return fail(ex, null); } } @@ -116,7 +241,7 @@ return success(count); } catch (Exception ex) { - return fail(ex.getMessage(), -1); + return fail(ex, -1); } } @@ -139,23 +264,7 @@ return success(count); } catch (Exception ex) { - return fail(ex.getMessage(), -1); - } - } - - @SysLog() - @ApiOperation(value = "鍒犻櫎涓�鏉�") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "ID", dataType = "Integer", paramType = "query", example = "1") - }) - @GetMapping(value = "/delete") - public ResponseMsg<Integer> delete(int id) { - try { - int count = metaService.delete(id); - - return success(count); - } catch (Exception ex) { - return fail(ex.getMessage(), -1); + return fail(ex, -1); } } @@ -175,7 +284,7 @@ return success(count); } catch (Exception ex) { - return fail(ex.getMessage(), -1); + return fail(ex, -1); } } @@ -197,7 +306,7 @@ return success(count); } catch (Exception ex) { - return fail(ex.getMessage(), -1); + return fail(ex, -1); } } @@ -221,12 +330,12 @@ return success(count); } catch (Exception ex) { - return fail(ex.getMessage(), -1); + return fail(ex, -1); } } @SysLog() - @ApiOperation(value = "鍒嗛〉鏌ヨ涓嬭浇璁板綍骞惰繑鍥炶褰曟暟") + @ApiOperation(value = "鍒嗛〉鏌ヨ涓嬭浇鏂囦欢") @ApiImplicitParams({ @ApiImplicitParam(name = "name", value = "鍚嶇О", dataType = "String", paramType = "query", example = ""), @ApiImplicitParam(name = "pageSize", value = "姣忛〉鏉℃暟", dataType = "Integer", paramType = "query", example = "10"), @@ -244,15 +353,15 @@ return fail("鐢ㄦ埛鏈櫥褰�", null); } - int count = downloadService.selectCountForUser(ue.getCreateUser(), 3, name); + int count = downloadService.selectCountForUser(ue.getId(), 3, name); if (count == 0) { return success(0, null); } - List<DownloadEntity> rs = downloadService.selectByPageForUser(ue.getCreateUser(), 3, name, pageSize, pageSize * (pageIndex - 1)); + List<DownloadEntity> rs = downloadService.selectByPageForUser(ue.getId(), 3, name, pageSize, pageSize * (pageIndex - 1)); return success(count, rs); } catch (Exception ex) { - return fail(ex.getMessage(), null); + return fail(ex, null); } } @@ -272,48 +381,98 @@ if (null == reqEntity.getIds() || reqEntity.getIds().isEmpty()) { return fail("璇烽�夋嫨瑕佷笅杞界殑鏂囦欢"); } - if (!downloadService.validatePwd(reqEntity)) { + if (!DownloadService.decryptPwd(reqEntity)) { + return fail("瀵嗙爜瑙e瘑澶辫触", null); + } + if (StringHelper.isPwdInvalid(reqEntity.getPwd())) { return fail("瀵嗙爜涓嶇鍚堣姹�"); } - List<MetaFileEntity> list = metaService.selectMetaFiles(reqEntity.getIds()); + List<MetaEntity> list = metaService.selectMetaFiles(reqEntity.getIds()); + if (null == list || list.isEmpty()) { + return fail("娌℃湁鎵惧埌鍏冩暟鎹�"); + } - return success(true); + UserEntity ue = tokenService.getCurrentUser(req); + String guid = downloadService.zipFiles(ue, list, reqEntity.getPwd()); + + return success(guid); } catch (Exception ex) { - return fail(ex.getMessage(), null); + return fail(ex, null); + } + } + + @SysLog() + @ApiOperation(value = "鏌ヨ涓嬭浇鏂囦欢") + @ApiImplicitParams({ + @ApiImplicitParam(name = "guid", value = "鏂囦欢GUID", dataType = "String", paramType = "query"), + @ApiImplicitParam(name = "pwd", value = "瀵嗙爜", dataType = "String", paramType = "query") + }) + @GetMapping(value = "/selectDownloadFile") + public ResponseMsg<Boolean> selectDownloadFile(String guid, String pwd) { + try { + if (StringHelper.isEmpty(guid) || StringHelper.isEmpty(pwd)) { + return fail("鏂囦欢ID鍜屽瘑鐮佷笉鑳戒负绌�", null); + } + if (!pwd.endsWith(StaticData.EQ)) { + pwd = URLDecoder.decode(pwd, StandardCharsets.UTF_8.name()); + } + + String password = DownloadService.decryptPwd(pwd); + if (null == password) { + return fail("瀵嗙爜瑙e瘑澶辫触", null); + } + + DownloadEntity de = downloadService.selectByGuid(guid); + if (null == de) { + return fail("鏂囦欢涓嶅瓨鍦�", null); + } + if (!StringHelper.isNull(de.getPwd()) && !Md5Helper.validatePassword(password, de.getPwd())) { + return fail("瀵嗙爜涓嶆纭�", null); + } + + String filePath = downloadService.getDownloadFilePath(de); + File file = new File(filePath); + + return success(file.exists()); + } catch (Exception ex) { + return fail(ex, false); } } @SysLog() @ApiOperation(value = "涓嬭浇鏂囦欢") @ApiImplicitParams({ - @ApiImplicitParam(name = "guid", value = "鏂囦欢GUID", dataType = "String", paramType = "query") + @ApiImplicitParam(name = "guid", value = "鏂囦欢GUID", dataType = "String", paramType = "query"), + @ApiImplicitParam(name = "pwd", value = "瀵嗙爜", dataType = "String", paramType = "query") }) @ResponseBody - @RequestMapping(value = "/downloadFile", method = RequestMethod.GET) - public void downloadFile(@RequestBody DownloadReqEntity reqEntity, HttpServletRequest req, HttpServletResponse res) { + @GetMapping(value = "/downloadFile") + public void downloadFile(String guid, String pwd, HttpServletRequest req, HttpServletResponse res) { try { - if (null == reqEntity || StringHelper.isEmpty(reqEntity.getPwd())) { - WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "瀵嗙爜涓嶈兘涓虹┖", res); + if (StringHelper.isEmpty(guid) || StringHelper.isEmpty(pwd)) { + WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "鏂囦欢ID鍜屽瘑鐮佷笉鑳戒负绌�", res); } - if (StringHelper.isEmpty(reqEntity.getGuid())) { - WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "鎵句笉鍒版枃浠禝D", res); - return; + if (!pwd.endsWith(StaticData.EQ)) { + pwd = URLDecoder.decode(pwd, StandardCharsets.UTF_8.name()); } - DownloadEntity de = downloadService.selectByGuid(reqEntity.getGuid()); + String password = DownloadService.decryptPwd(pwd); + if (null == password) { + WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "瀵嗙爜瑙e瘑澶辫触", res); + } + + DownloadEntity de = downloadService.selectByGuid(guid); if (null == de) { WebHelper.writeInfo(HttpStatus.NOT_FOUND, "鏂囦欢涓嶅瓨鍦�", res); return; } - if (!StringHelper.isNull(de.getPwd()) && !Md5Helper.validatePassword(reqEntity.getPwd(), 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); @@ -321,4 +480,14 @@ WebHelper.writeInfo(HttpStatus.ERROR, ex.getMessage(), res); } } + + @SysLog() + @ApiOperation(value = "鏌ョ湅鏂囦欢") + @ApiImplicitParams({ + @ApiImplicitParam(name = "guid", value = "闄勪欢Guid", dataType = "String", paramType = "body") + }) + @GetMapping(value = "/downloadForView") + public void downloadForView(String guid, HttpServletResponse res) { + metaService.downloadForView(guid, true, res); + } } -- Gitblit v1.9.3