TSubmittedController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. package com.steerinfo.ems.tsubmitted.controller;
  2. import com.steerinfo.auth.utils.JwtUtil;
  3. import com.steerinfo.ems.Utils.DateUtils;
  4. import com.steerinfo.ems.tmaintenance.model.TMaintenance;
  5. import com.steerinfo.ems.tmaintenance.service.ITMaintenanceService;
  6. import com.steerinfo.ems.tmaintenancefile.model.TMaintenanceFile;
  7. import com.steerinfo.ems.tmaintenancefile.service.ITMaintenanceFileService;
  8. import com.steerinfo.framework.controller.BaseRESTfulController;
  9. import com.steerinfo.framework.controller.RESTfulResult;
  10. import com.steerinfo.framework.service.pagehelper.PageList;
  11. import com.steerinfo.framework.utils.collection.ListUtils;
  12. import com.steerinfo.ems.tsubmitted.model.TSubmitted;
  13. import com.steerinfo.ems.tsubmitted.service.ITSubmittedService;
  14. import com.steerinfo.ftp.securitytype.model.SecurityType;
  15. import com.steerinfo.ftp.uploadfile.model.UploadFile;
  16. import com.steerinfo.ftp.uploadfile.utils.FtpFileUtil;
  17. import com.steerinfo.ftp.uploadfile.utils.IDutils;
  18. import io.swagger.annotations.ApiImplicitParam;
  19. import io.swagger.annotations.ApiImplicitParams;
  20. import io.swagger.annotations.ApiOperation;
  21. import org.apache.commons.lang3.StringUtils;
  22. import org.apache.poi.ss.formula.functions.T;
  23. import org.apache.shiro.authz.annotation.RequiresPermissions;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.web.bind.annotation.*;
  26. import org.springframework.web.multipart.MultipartFile;
  27. import java.io.File;
  28. import java.io.IOException;
  29. import java.io.InputStream;
  30. import java.text.SimpleDateFormat;
  31. import java.util.*;
  32. import java.math.BigDecimal;
  33. /**
  34. * TSubmitted RESTful接口:
  35. * @author generator
  36. * @version 1.0-SNAPSHORT 2022-06-10 04:08
  37. * 类描述
  38. * 修订历史:
  39. * 日期:2022-06-10
  40. * 作者:generator
  41. * 参考:
  42. * 描述:TSubmitted RESTful接口
  43. * @see null
  44. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  45. */
  46. @RestController
  47. @RequestMapping("/${api.version}/tsubmitteds")
  48. public class TSubmittedController extends BaseRESTfulController {
  49. /** 文件保存路径 */
  50. public static final String FILE_DIR = "/static/";
  51. @Autowired
  52. ITSubmittedService tSubmittedService;
  53. @Autowired
  54. private FtpFileUtil ftpFileUtil;
  55. @Autowired
  56. ITMaintenanceFileService tMaintenanceFileService;
  57. @ApiOperation(value="获取列表", notes="分页查询")
  58. @ApiImplicitParams({
  59. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  60. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  61. })
  62. //@RequiresPermissions("tsubmitted:view")
  63. @GetMapping(value = "/")
  64. public RESTfulResult list(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
  65. PageList<TSubmitted> list = tSubmittedService.queryForPage(parmas, pageNum, pageSize);
  66. return success(list);
  67. }
  68. @ApiOperation(value="获取列表", notes="分页模糊查询")
  69. @ApiImplicitParams({
  70. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  71. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  72. })
  73. //@RequiresPermissions("tsubmitted:view")
  74. @GetMapping(value = "/like/")
  75. public RESTfulResult listLike(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
  76. PageList<TSubmitted> list = tSubmittedService.queryLikeForPage(parmas, pageNum, pageSize);
  77. return success(list);
  78. }
  79. @ApiOperation(value="创建", notes="根据TSubmitted对象创建")
  80. @ApiImplicitParam(name = "tSubmitted", value = "详细实体tSubmitted", required = true, dataType = "TSubmitted")
  81. //@RequiresPermissions("tsubmitted:create")
  82. @PostMapping(value = "/")
  83. public RESTfulResult add(@ModelAttribute TSubmitted model){
  84. TSubmitted tSubmitted = tSubmittedService.add(model);
  85. return success(tSubmitted);
  86. }
  87. @ApiOperation(value="获取详细信息", notes="根据url的id来获取详细信息")
  88. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
  89. //@RequiresPermissions("tsubmitted:view")
  90. @GetMapping(value = "/{id}")
  91. public RESTfulResult get(@PathVariable String id){
  92. TSubmitted tSubmitted = tSubmittedService.getById(id);
  93. return success(tSubmitted);
  94. }
  95. @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象,并根据传过来的tSubmitted信息来更新详细信息")
  96. @ApiImplicitParams({
  97. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"),
  98. @ApiImplicitParam(name = "tSubmitted", value = "详细实体tSubmitted", required = true, dataType = "TSubmitted")
  99. })
  100. //@RequiresPermissions("tsubmitted:update")
  101. @PutMapping(value = "/{id}", produces = "application/json;charset=UTF-8")
  102. public RESTfulResult update(@PathVariable String id, @RequestBody TSubmitted model){
  103. model.setId(id);
  104. TSubmitted tSubmitted = tSubmittedService.modify(model);
  105. return success(tSubmitted);
  106. }
  107. @ApiOperation(value="删除", notes="根据url的id来指定删除对象")
  108. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
  109. //@RequiresPermissions("tsubmitted:delete")
  110. @DeleteMapping(value = "/{id}")//String
  111. public RESTfulResult delete(@PathVariable String id){
  112. List<String> list = Arrays.asList(id.split(","));
  113. if(ListUtils.isNotEmpty(list)) {
  114. List<String> ids = ListUtils.convertList(list);
  115. tSubmittedService.delete(ids);
  116. }
  117. return success();
  118. }
  119. @PutMapping("/getimage/")
  120. public RESTfulResult getimage(@ModelAttribute MultipartFile[] file, TSubmitted model) throws IOException {
  121. if (file!=null && file.length>0){
  122. //将文件名赋值给model
  123. TSubmitted tSubmitted = new TSubmitted();
  124. tSubmitted.setConstruid( model.getConstruid());
  125. String uploadDir = FILE_DIR +model.getConstruid()+"/";
  126. File dir = new File(uploadDir);
  127. if (!dir.exists()) {
  128. dir.mkdirs();
  129. }
  130. dir.setReadOnly();
  131. for (int i = 0; i < file.length; i++) {
  132. //获取文件原始名
  133. String imagename= file[i].getOriginalFilename();
  134. model.setImagename(imagename);
  135. // 服务器端保存的文件对象
  136. File serverFile = new File(uploadDir, imagename);
  137. file[i].transferTo(serverFile.getAbsoluteFile());
  138. tSubmitted.setImagename(imagename);
  139. }
  140. return success(tSubmitted);
  141. }
  142. return failed("传入文件类型不符合");
  143. }
  144. @PostMapping(value = "/pus/")
  145. public RESTfulResult putMes(@ModelAttribute MultipartFile[] file, TSubmitted model, String del) {
  146. if (model.getSigntime()==null||"".equals(model.getSigntime())){
  147. return failed(null,"日期不能为空");
  148. }
  149. if (model.getState()==null||"".equals(model.getState())){
  150. return failed(null,"状态不能为空");
  151. } if (model.getConstrucontent()==null||"".equals(model.getConstrucontent())){
  152. return failed(null,"内容不能为空");
  153. }
  154. HashMap hashMap = new HashMap();
  155. hashMap.put("declareid",model.getDeclareid());
  156. //丛前端获取申报日期,利用SimpleDateFormat类转换为字符串
  157. String Signtime = model.getSigntime();
  158. //将转换为字符串的日期进行截取,截取出月和日
  159. Integer maxid = tSubmittedService.MaxID(model.getDeclareid());
  160. model.setMaxid(new BigDecimal(maxid));
  161. String datetime = DateUtils.getCurrentTime("yyyy-MM-dd");
  162. if (model == null) {
  163. return failed(null, "参数错误!");
  164. }
  165. TSubmitted tSubmitted = new TSubmitted();
  166. String bid = model.getConstruid();
  167. model.setConstruid(model.getDeclareid()+ "_"+ String.format("%04d", maxid));
  168. String filenames ="";
  169. for (int i = 0; i <file.length ; i++) {
  170. filenames+=file[i].getOriginalFilename()+";";
  171. }
  172. model.setConstrufile(filenames);
  173. tSubmitted= tSubmittedService.add(model);
  174. String filesid = "";
  175. if (file!=null){
  176. for (int i = 0; i <file.length ; i++) {
  177. try {
  178. String userId = JwtUtil.getUseridByToken();
  179. //获取系统时间
  180. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("/yyyy/MM/dd");
  181. //获取文件名
  182. String oldName = file[i].getOriginalFilename();
  183. //取当前时间的长整形值包含毫秒
  184. String newName = IDutils.getImageName();
  185. //重新命名文件
  186. newName = newName + oldName.substring(oldName.lastIndexOf("."));
  187. String filePath = simpleDateFormat.format(new Date());
  188. //获取输入流
  189. InputStream inputStream = file[i].getInputStream();
  190. boolean result = ftpFileUtil.uploadToFtp(inputStream, filePath, newName, false);
  191. inputStream.close();
  192. if (result) {
  193. TMaintenanceFile uploadFile = new TMaintenanceFile();
  194. uploadFile.setFilename(oldName);
  195. uploadFile.setFilepath(filePath + "/" + newName);
  196. uploadFile.setId(model.getConstruid());
  197. TMaintenanceFile modela = tMaintenanceFileService.add(uploadFile);
  198. if (modela != null) {
  199. filesid += "," + modela.getId();
  200. }
  201. } else {
  202. return failed(null, "上传文件失败");
  203. }
  204. } catch (Exception e) {
  205. e.getMessage();
  206. }
  207. }
  208. return success(filesid);
  209. }
  210. return success(tSubmitted);
  211. }
  212. @DeleteMapping("/del/{construid}")
  213. public RESTfulResult del(@PathVariable String construid){
  214. tSubmittedService.delete(construid);
  215. return success("撤销成功");
  216. }
  217. }