ÎļþÃû´Ó src/main/java/com/lf/server/controller/data/DataLoaderController.java ÐÞ¸Ä |
| | |
| | | package com.lf.server.controller.data; |
| | | package com.lf.server.controller.data.upload; |
| | | |
| | | 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.BaseUploadController; |
| | | import com.lf.server.entity.all.ResponseMsg; |
| | | import com.lf.server.entity.all.StaticData; |
| | | import com.lf.server.entity.ctrl.TabEntity; |
| | | import com.lf.server.entity.ctrl.TabMapperEntity; |
| | | import com.lf.server.entity.ctrl.UploadEntity; |
| | | import com.lf.server.entity.data.DictEntity; |
| | | 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.helper.ClassHelper; |
| | | 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.DataLoaderService; |
| | | import com.lf.server.service.data.MetaService; |
| | | import io.swagger.annotations.Api; |
| | | import com.lf.server.service.data.*; |
| | | 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 org.springframework.web.bind.annotation.GetMapping; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * æ°æ®å
¥åº |
| | | * æ¥è¯¢æ§å¶å¨ |
| | | * @author WWW |
| | | */ |
| | | @Api(tags = "æ°æ®ç®¡ç\\æ°æ®å
¥åº") |
| | | @RestController |
| | | @RequestMapping("/dataLoader") |
| | | public class DataLoaderController extends BaseUploadController { |
| | | public class SelectController extends CheckController { |
| | | @Autowired |
| | | MetaService metaService; |
| | | protected DepService depService; |
| | | |
| | | @Autowired |
| | | BaseQueryService baseQueryService; |
| | | protected DirService dirService; |
| | | |
| | | @Autowired |
| | | DataLoaderService dataLoaderService; |
| | | protected VerService verService; |
| | | |
| | | public static List<String> extList = new ArrayList<>(Arrays.asList(".xls", ".xlsx", ".mdb", ".zip")); |
| | | @Autowired |
| | | protected MetaService metaService; |
| | | |
| | | @Autowired |
| | | protected TokenService tokenService; |
| | | |
| | | @Autowired |
| | | protected BaseQueryService baseQueryService; |
| | | |
| | | @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) { |
| | | @ApiOperation(value = "æ¥è¯¢ææåä½") |
| | | @GetMapping(value = "/selectDepAll") |
| | | public ResponseMsg<List<DepEntity>> selectDepAll() { |
| | | try { |
| | | if (pageSize < 1 || pageIndex < 1) { |
| | | return fail("æ¯é¡µé¡µæ°æå页æ°å°äº1", null); |
| | | } |
| | | List<DepEntity> list = depService.selectDepAll(); |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | |
| | | int count = metaService.selectCountForUpload(name, ue.getId(), StaticData.FILE_TYPES); |
| | | if (count == 0) { |
| | | return success(0, null); |
| | | } |
| | | |
| | | List<MetaEntity> list = metaService.selectByPageForUpload(name, ue.getId(), StaticData.FILE_TYPES, pageSize, pageSize * (pageIndex - 1)); |
| | | |
| | | return success(count, list); |
| | | return success(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) { |
| | | @ApiOperation(value = "æ¥è¯¢ææç®å½") |
| | | @GetMapping(value = "/selectDirAll") |
| | | public ResponseMsg<List<DirEntity>> selectDirAll() { |
| | | try { |
| | | List<MetaEntity> list = baseUploadService.selectFiles(path, extList); |
| | | 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) { |
| | |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "æ¥è¯¢æ å°") |
| | | @ApiOperation(value = "æ¥è¯¢å段信æ¯") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "path", value = "è·¯å¾", dataType = "String", paramType = "query") |
| | | @ApiImplicitParam(name = "ns", value = "å称空é´", dataType = "String", paramType = "query", example = "bd"), |
| | | @ApiImplicitParam(name = "tab", value = "表å", dataType = "String", paramType = "query", example = "dlg25wAanp") |
| | | }) |
| | | @GetMapping(value = "/selectMappers") |
| | | public ResponseMsg<List<TabMapperEntity>> selectMappers(String path) { |
| | | @GetMapping(value = "/selectFields") |
| | | public ResponseMsg<List<DictEntity>> selectFields(String ns, String tab) { |
| | | try { |
| | | List<TabMapperEntity> list = dataLoaderService.selectMappers(path); |
| | | 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.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()); |
| | | |
| | | dataLoaderService.insertFiles(me, entity.getFileEntities(), entity.getTabEntities()); |
| | | |
| | | return success("æå", entity.getTabEntities()); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "æ¥è¯¢å段信æ¯") |
| | | @ApiOperation(value = "å页æ¥è¯¢ä¸ä¼ æ°æ®å¹¶è¿åè®°å½æ°") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "ns", value = "å称空é´", dataType = "String", paramType = "query", example = "bd"), |
| | | @ApiImplicitParam(name = "tab", value = "表å", dataType = "String", paramType = "query", example = "dlg25wAanp") |
| | | @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 = "/selectFields") |
| | | public ResponseMsg<List<DictEntity>> selectFields(String ns, String tab) { |
| | | @GetMapping(value = "/selectByPageForUpload") |
| | | public ResponseMsg<Object> selectByPageForUpload(String name, Integer pageSize, Integer pageIndex, HttpServletRequest req) { |
| | | try { |
| | | if (StringHelper.isEmpty(ns) || StringHelper.isEmpty(tab)) { |
| | | return fail("å称空é´å表åä¸è½ä¸ºç©º", null); |
| | | if (pageSize < 1 || pageIndex < 1) { |
| | | return fail("æ¯é¡µé¡µæ°æå页æ°å°äº1", null); |
| | | } |
| | | |
| | | List<DictEntity> list = baseQueryService.selectFields(ns, tab); |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | |
| | | return success(list); |
| | | int count = metaService.selectCountForUpload(name, ue.getId(), StaticData.FILE_TYPES); |
| | | if (count == 0) { |
| | | return success(0, null); |
| | | } |
| | | |
| | | List<MetaEntity> list = metaService.selectByPageForUpload(name, ue.getId(), StaticData.FILE_TYPES, pageSize, pageSize * (pageIndex - 1)); |
| | | |
| | | return success(count, list); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |