TMaintenanceFileController.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package com.steerinfo.ems.tmaintenancefile.controller;
  2. import com.steerinfo.auth.utils.JwtUtil;
  3. import com.steerinfo.framework.controller.BaseRESTfulController;
  4. import com.steerinfo.framework.controller.RESTfulResult;
  5. import com.steerinfo.framework.service.pagehelper.PageList;
  6. import com.steerinfo.framework.utils.collection.ListUtils;
  7. import com.steerinfo.ems.tmaintenancefile.model.TMaintenanceFile;
  8. import com.steerinfo.ems.tmaintenancefile.service.ITMaintenanceFileService;
  9. import com.steerinfo.ftp.securitytype.model.SecurityType;
  10. import com.steerinfo.ftp.uploadfile.model.UploadFile;
  11. import com.steerinfo.ftp.uploadfile.utils.FtpFileUtil;
  12. import com.steerinfo.ftp.uploadfile.utils.IDutils;
  13. import io.swagger.annotations.ApiImplicitParam;
  14. import io.swagger.annotations.ApiImplicitParams;
  15. import io.swagger.annotations.ApiOperation;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.apache.shiro.authz.annotation.RequiresPermissions;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.web.bind.annotation.*;
  20. import org.springframework.web.multipart.MultipartFile;
  21. import java.io.InputStream;
  22. import java.text.SimpleDateFormat;
  23. import java.util.*;
  24. import java.math.BigDecimal;
  25. /**
  26. * TMaintenanceFile RESTful接口:
  27. * @author generator
  28. * @version 1.0-SNAPSHORT 2022-06-06 02:51
  29. * 类描述
  30. * 修订历史:
  31. * 日期:2022-06-06
  32. * 作者:generator
  33. * 参考:
  34. * 描述:TMaintenanceFile RESTful接口
  35. * @see null
  36. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  37. */
  38. @RestController
  39. @RequestMapping("/${api.version}/tmaintenancefiles")
  40. public class TMaintenanceFileController extends BaseRESTfulController {
  41. @Autowired
  42. private FtpFileUtil ftpFileUtil;
  43. @Autowired
  44. ITMaintenanceFileService tMaintenanceFileService;
  45. @ApiOperation(value="获取列表", notes="分页查询")
  46. @ApiImplicitParams({
  47. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  48. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  49. })
  50. //@RequiresPermissions("tmaintenancefile:view")
  51. @GetMapping(value = "/")
  52. public RESTfulResult list(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
  53. PageList<TMaintenanceFile> list = tMaintenanceFileService.queryForPage(parmas, pageNum, pageSize);
  54. return success(list);
  55. }
  56. @ApiOperation(value="获取列表", notes="分页模糊查询")
  57. @ApiImplicitParams({
  58. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  59. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  60. })
  61. //@RequiresPermissions("tmaintenancefile:view")
  62. @GetMapping(value = "/like/")
  63. public RESTfulResult listLike(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
  64. PageList<TMaintenanceFile> list = tMaintenanceFileService.queryLikeForPage(parmas, pageNum, pageSize);
  65. return success(list);
  66. }
  67. @ApiOperation(value="创建", notes="根据TMaintenanceFile对象创建")
  68. @ApiImplicitParam(name = "tMaintenanceFile", value = "详细实体tMaintenanceFile", required = true, dataType = "TMaintenanceFile")
  69. //@RequiresPermissions("tmaintenancefile:create")
  70. @PostMapping(value = "/")
  71. public RESTfulResult add(@ModelAttribute TMaintenanceFile model){
  72. TMaintenanceFile tMaintenanceFile = tMaintenanceFileService.add(model);
  73. return success(tMaintenanceFile);
  74. }
  75. @ApiOperation(value="获取详细信息", notes="根据url的id来获取详细信息")
  76. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
  77. //@RequiresPermissions("tmaintenancefile:view")
  78. @GetMapping(value = "/{id}")
  79. public RESTfulResult get(@PathVariable String id){
  80. TMaintenanceFile tMaintenanceFile = tMaintenanceFileService.getById(id);
  81. return success(tMaintenanceFile);
  82. }
  83. @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象,并根据传过来的tMaintenanceFile信息来更新详细信息")
  84. @ApiImplicitParams({
  85. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"),
  86. @ApiImplicitParam(name = "tMaintenanceFile", value = "详细实体tMaintenanceFile", required = true, dataType = "TMaintenanceFile")
  87. })
  88. //@RequiresPermissions("tmaintenancefile:update")
  89. @PutMapping(value = "/{id}", produces = "application/json;charset=UTF-8")
  90. public RESTfulResult update(@PathVariable String id, @RequestBody TMaintenanceFile model){
  91. model.setId(id);
  92. TMaintenanceFile tMaintenanceFile = tMaintenanceFileService.modify(model);
  93. return success(tMaintenanceFile);
  94. }
  95. @ApiOperation(value="删除", notes="根据url的id来指定删除对象")
  96. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
  97. //@RequiresPermissions("tmaintenancefile:delete")
  98. @DeleteMapping(value = "/{id}")//String
  99. public RESTfulResult delete(@PathVariable String id){
  100. List<String> list = Arrays.asList(id.split(","));
  101. if(ListUtils.isNotEmpty(list)) {
  102. List<String> ids = ListUtils.convertList(list);
  103. tMaintenanceFileService.delete(ids);
  104. }
  105. return success();
  106. }
  107. @PostMapping("/file")
  108. public RESTfulResult fileUpload(@ModelAttribute MultipartFile[] files){
  109. String filesid = "";
  110. for (int i = 0; i < files.length; i++) {
  111. try {
  112. String userId = JwtUtil.getUseridByToken();
  113. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("/yyyy/MM/dd");
  114. String oldName = files[i].getOriginalFilename();
  115. String newName = IDutils.getImageName();
  116. newName = newName + oldName.substring(oldName.lastIndexOf("."));
  117. String filePath = simpleDateFormat.format(new Date());
  118. InputStream inputStream = files[i].getInputStream();
  119. boolean result = ftpFileUtil.uploadToFtp(inputStream, filePath, newName, false);
  120. inputStream.close();
  121. if (result) {
  122. TMaintenanceFile uploadFile = new TMaintenanceFile();
  123. uploadFile.setFilename(oldName);
  124. uploadFile.setFilepath(filePath + "/" + newName);
  125. TMaintenanceFile model = tMaintenanceFileService.add(uploadFile);
  126. if (model != null) {
  127. filesid += "," + model.getId();
  128. }
  129. } else {
  130. return failed(null, "上传文件失败");
  131. }
  132. } catch (Exception e) {
  133. e.getMessage();
  134. }
  135. }
  136. return success(filesid);
  137. }
  138. }