CommonController.java 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. package com.ruoyi.project.common;
  2. import com.ruoyi.common.constant.Constants;
  3. import com.ruoyi.common.utils.StringUtils;
  4. import com.ruoyi.common.utils.file.FileUploadUtils;
  5. import com.ruoyi.common.utils.file.FileUtils;
  6. import com.ruoyi.framework.config.RuoYiConfig;
  7. import com.ruoyi.framework.config.ServerConfig;
  8. import com.ruoyi.framework.web.controller.BaseController;
  9. import com.ruoyi.framework.web.domain.AjaxResult;
  10. import com.ruoyi.project.sems.domain.TSpecdevGl;
  11. import com.ruoyi.project.sems.service.*;
  12. import org.apache.poi.ss.usermodel.CellStyle;
  13. import org.apache.poi.ss.usermodel.Row;
  14. import org.apache.poi.ss.usermodel.Sheet;
  15. import org.apache.poi.xssf.streaming.SXSSFWorkbook;
  16. import org.slf4j.Logger;
  17. import org.slf4j.LoggerFactory;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.web.bind.annotation.*;
  20. import org.springframework.web.multipart.MultipartFile;
  21. import javax.servlet.ServletOutputStream;
  22. import javax.servlet.http.HttpServletRequest;
  23. import javax.servlet.http.HttpServletResponse;
  24. import java.io.*;
  25. import java.util.ArrayList;
  26. import java.util.List;
  27. import java.util.UUID;
  28. /**
  29. * 通用请求处理
  30. *
  31. * @author ruoyi
  32. */
  33. @RestController
  34. public class CommonController extends BaseController
  35. {
  36. private static final Logger log = LoggerFactory.getLogger(CommonController.class);
  37. private static final String FILE_DELIMETER = ",";
  38. @Autowired
  39. private ServerConfig serverConfig;
  40. @Autowired
  41. private ITSpecdevYlrqService tSpecdevYlrqService;
  42. @Autowired
  43. private ITSpecdevYlgdService tSpecdevYlgdService;
  44. @Autowired
  45. private ITSpecdevGlService tSpecdevGlService;
  46. @Autowired
  47. private ITSpecdevDzsbService tSpecdevDzsbService;
  48. @Autowired
  49. private ITSpecdevDtService tSpecdevDtService;
  50. @Autowired
  51. private ITSpecdevCcService tSpecdevCcService;
  52. /**
  53. * 导入下载模板
  54. */
  55. @RequestMapping("common/template")
  56. @ResponseBody
  57. public void template(String type,HttpServletRequest request, HttpServletResponse response) throws IOException
  58. {
  59. String downloadname = "";
  60. String url = "";
  61. if ( type.equals("alarmmodify") ) {
  62. downloadname = "报警值管理导入模板.xlsx";
  63. url = "static/template/process/alarmmodify.xlsx";
  64. } else if( type.equals("publicdoc") ) {
  65. downloadname = "公共文档管理导入模板.xlsx";
  66. url = "static/template/document/publicdoc.xlsx";
  67. } else if( type.equals("publicdocmenu") ) {
  68. downloadname = "公共文档目录管理导入模板.xlsx";
  69. url = "static/template/document/publicdocmenu.xlsx";
  70. } else if( type.equals("permanentMoc") ) {
  71. downloadname = "永久MOC导入模板.xlsx";
  72. url = "static/template/process/moc/permanentMoc.xlsx";
  73. } else if( type.equals("temporaryMoc") ) {
  74. downloadname = "临时MOC导入模板.xlsx";
  75. url = "static/template/process/moc/temporaryMoc.xlsx";
  76. } else if( type.equals("aquifier") ) {
  77. downloadname = "临时MOC-带压消漏清单导入模板.xlsx";
  78. url = "static/template/process/moc/aquifier.xlsx";
  79. } else if( type.equals("facility") ) {
  80. downloadname = "临时MOC-临时设施及其它导入模板.xlsx";
  81. url = "static/template/process/moc/facility.xlsx";
  82. } else if( type.equals("interlock") ) {
  83. downloadname = "临时MOC-仪表联锁旁路导入模板.xlsx";
  84. url = "static/template/process/moc/interlock.xlsx";
  85. } else if( type.equals("accident") ) {
  86. downloadname = "隐患排查导入模板.xlsx";
  87. url = "static/template/production/accident.xlsx";
  88. } else if( type.equals("blind") ) {
  89. downloadname = "盲板清单导入模板.xlsx";
  90. url = "static/template/production/blind.xlsx";
  91. } else if( type.equals("我的机器") ) {
  92. downloadname = "5S管理我的机器导入模板.xlsx";
  93. url = "static/template/production/wsglmachine.xlsx";
  94. } else if( type.equals("我的区域") ) {
  95. downloadname = "5S管理我的区域导入模板.xlsx";
  96. url = "static/template/production/wsglarea.xlsx";
  97. } else if( type.equals("day") ) {
  98. downloadname = "报警统计(昨天)导入模板.xlsx";
  99. url = "static/template/production/alarmstatistics.xlsx";
  100. } else if( type.equals("month") ) {
  101. downloadname = "报警统计(上月)导入模板.xlsx";
  102. url = "static/template/production/alarmstatistics.xlsx";
  103. } else if( type.equals("lbnhjstj") ) {
  104. downloadname = "能耗管理统计导入模板.xlsx";
  105. url = "static/template/production/lbnhjstj.xlsx";
  106. } else if( type.equals("sai") ) {
  107. downloadname = "SAI检查管理导入模板.xlsx";
  108. url = "static/template/production/sai.xlsx";
  109. } else if( type.equals("saiApply") ) {
  110. downloadname = "SAI开项管理导入模板.xlsx";
  111. url = "static/template/production/saiApply.xlsx";
  112. } else if( type.equals("rcaudit") ) {
  113. downloadname = "RC审计助手导入模板.xlsx";
  114. url = "static/template/ehs/rcaudit.xlsx";
  115. } else if( type.equals("rcauditmenu") ) {
  116. downloadname = "RC审计助手目录导入模板.xlsx";
  117. url = "static/template/ehs/rcauditmenu.xlsx";
  118. } else if( type.equals("plantproglistprocedure") ) {
  119. downloadname = "装置程序清单程序总汇导入模板.xlsx";
  120. url = "static/template/document/plantproglistprocedure.xlsx";
  121. } else if( type.equals("plantproglistform") ) {
  122. downloadname = "装置程序清单表格总汇导入模板.xlsx";
  123. url = "static/template/document/plantproglistform.xlsx";
  124. } else if( type.equals("plantproglistguide") ) {
  125. downloadname = "装置程序清单指南总汇导入模板.xlsx";
  126. url = "static/template/document/plantproglistguide.xlsx";
  127. } else if( type.equals("plantproglistbook") ) {
  128. downloadname = "装置程序清单指导书总汇导入模板.xlsx";
  129. url = "static/template/document/plantproglistbook.xlsx";
  130. } else if( type.equals("plantproglistannex") ) {
  131. downloadname = "装置程序清单附件总汇导入模板.xlsx";
  132. url = "static/template/document/plantproglistannex.xlsx";
  133. } else if( type.equals("plantproglistmaterials") ) {
  134. downloadname = "装置程序清单培训材料导入模板.xlsx";
  135. url = "static/template/document/plantproglistmaterials.xlsx";
  136. } else if( type.equals("officesupply") ) {
  137. downloadname = "办公用品管理导入模板.xlsx";
  138. url = "static/template/affair/officesupply.xlsx";
  139. } else if( type.equals("ppe") ) {
  140. downloadname = "PPE发放登记导入模板.xlsx";
  141. url = "static/template/affair/ppe.xlsx";
  142. } else if( type.equals("intercom") ) {
  143. downloadname = "对讲机管理导入模板.xlsx";
  144. url = "static/template/affair/intercom.xlsx";
  145. } else if( type.equals("kkxglcs") ) {
  146. downloadname = "可靠性管理措施导入模板.xlsx";
  147. url = "static/template/reliability/kkxglcs.xlsx";
  148. } else if( type.equals("original") ) {
  149. downloadname = "故障管理初选导入模板.xlsx";
  150. url = "static/template/reliability/original.xlsx";
  151. } else if( type.equals("abnormalreport") ) {
  152. downloadname = "异常报告管理导入模板.xlsx";
  153. url = "static/template/reliability/abnormalreport.xlsx";
  154. } else if( type.equals("assetlist") ) {
  155. downloadname = "资产清单导入模板.xlsx";
  156. url = "static/template/reliability/assetlist.xlsx";
  157. } else if( type.equals("safetyvavle") ) {
  158. downloadname = "安全阀清单导入模板.xlsx";
  159. url = "static/template/reliability/safetyvavle.xlsx";
  160. } else if( type.equals("preventivemaintenance") ) {
  161. downloadname = "预防性维修导入模板.xlsx";
  162. url = "static/template/reliability/preventivemaintenance.xlsx";
  163. } else if( type.equals("pipe") ) {
  164. downloadname = "管线清单导入模板.xlsx";
  165. url = "static/template/cui/pipe.xlsx";
  166. } else if( type.equals("pvessel") ) {
  167. downloadname = "容器清单导入模板.xlsx";
  168. url = "static/template/cui/pvessel.xlsx";
  169. } else if( type.equals("problems") ) {
  170. downloadname = "CUI问题整改跟踪清单导入模板.xlsx";
  171. url = "static/template/cui/problems.xlsx";
  172. } else if( type.equals("eyewasher") ) {
  173. downloadname = "洗眼器导入模板.xlsx";
  174. url = "static/template/ehs/eyewasher.xlsx";
  175. } else if( type.equals("firehose") ) {
  176. downloadname = "消防水带箱导入模板.xlsx";
  177. url = "static/template/ehs/firehose.xlsx";
  178. } else if( type.equals("firehydrant") ) {
  179. downloadname = "消防栓导入模板.xlsx";
  180. url = "static/template/ehs/firehydrant.xlsx";
  181. } else if( type.equals("highpresfire") ) {
  182. downloadname = "高压消防炮导入模板.xlsx";
  183. url = "static/template/ehs/highpresfire.xlsx";
  184. } else if( type.equals("fireextinguisher") ) {
  185. downloadname = "灭火器导入模板.xlsx";
  186. url = "static/template/ehs/fireextinguisher.xlsx";
  187. } else if( type.equals("autosprinkler") ) {
  188. downloadname = "自动喷淋系统导入模板.xlsx";
  189. url = "static/template/ehs/autosprinkler.xlsx";
  190. } else if( type.equals("firestandpipe") ) {
  191. downloadname = "消防竖管导入模板.xlsx";
  192. url = "static/template/ehs/firestandpipe.xlsx";
  193. } else if( type.equals("safetyapproval") ) {
  194. downloadname = "安全批文清单导入模板.xlsx";
  195. url = "static/template/ehs/safetyapproval.xlsx";
  196. } else if( type.equals("fireapproval") ) {
  197. downloadname = "消防批文清单导入模板.xlsx";
  198. url = "static/template/ehs/fireapproval.xlsx";
  199. } else if( type.equals("environapproval") ) {
  200. downloadname = "环保批文清单导入模板.xlsx";
  201. url = "static/template/ehs/environapproval.xlsx";
  202. } else if( type.equals("healthapproval") ) {
  203. downloadname = "卫生批文清单导入模板.xlsx";
  204. url = "static/template/ehs/healthapproval.xlsx";
  205. } else if( type.equals("safetyapprcont") ) {
  206. downloadname = "安全批文主要内容导入模板.xlsx";
  207. url = "static/template/ehs/safetyapprcont.xlsx";
  208. } else if( type.equals("environapprcont") ) {
  209. downloadname = "环保批文主要内容导入模板.xlsx";
  210. url = "static/template/ehs/environapprcont.xlsx";
  211. } else if( type.equals("jobticket") ) {
  212. downloadname = "工作票导入模板.xlsx";
  213. url = "static/template/ehs/jobticket.xlsx";
  214. } else if( type.equals("msds") ) {
  215. downloadname = "MSDS管理导入模板.xlsx";
  216. url = "static/template/ehs/msds.xlsx";
  217. } else if( type.equals("incidentRecords") ) {
  218. downloadname = "事故报告清单导入模板.xlsx";
  219. url = "static/template/ehs/incidentRecords.xlsx";
  220. } else if( type.equals("water") ) {
  221. downloadname = "废水风险评估导入模板.xlsx";
  222. url = "static/template/ehs/water.xlsx";
  223. } else if( type.equals("danger") ) {
  224. downloadname = "危险废物清单导入模板.xlsx";
  225. url = "static/template/ehs/danger.xlsx";
  226. } else if( type.equals("dangermonth") ) {
  227. downloadname = "危险废物出入库月报导入模板.xlsx";
  228. url = "static/template/ehs/dangermonth.xlsx";
  229. } else if( type.equals("barrelmonth") ) {
  230. downloadname = "废桶进出库统计日报导入模板.xlsx";
  231. url = "static/template/ehs/barrelmonth.xlsx";
  232. } else if( type.equals("dangerday") ) {
  233. downloadname = "危废出入库统计日报导入模板.xlsx";
  234. url = "static/template/ehs/dangerday.xlsx";
  235. } else if( type.equals("workcertificate") ) {
  236. downloadname = "作业证书一览表导入模板.xlsx";
  237. url = "static/template/training/workcertificate.xlsx";
  238. } else if( type.equals("byxworkcertificate") ) {
  239. downloadname = "苯乙烯作业证书一览表导入模板.xlsx";
  240. url = "static/template/training/byxworkcertificate.xlsx";
  241. } else if( type.equals("worklicense") ) {
  242. downloadname = "上岗证一览表导入模板.xlsx";
  243. url = "static/template/training/worklicense.xlsx";
  244. } else if( type.equals("trainingrecords") ) {
  245. downloadname = "培训成绩导入模板.xlsx";
  246. url = "static/template/training/trainingrecords.xlsx";
  247. } else if( type.equals("training") ) {
  248. downloadname = "培训计划执行及跟踪导入模板.xlsx";
  249. url = "static/template/training/training.xlsx";
  250. } else if( type.equals("skillevaluation") ) {
  251. downloadname = "岗位人员技能评估导入模板.xlsx";
  252. url = "static/template/training/skillevaluation.xlsx";
  253. } else if( type.equals("newemployee") ) {
  254. downloadname = "新员工培训导入模板.xlsx";
  255. url = "static/template/training/newemployee.xlsx";
  256. }else if( type.equals("companyLevelRecord") ) {
  257. downloadname = "公司培训成绩导入模板.xlsx";
  258. url = "static/template/training/companyLevelRecord.xlsx";
  259. } else if( type.equals("targetlist") ) {
  260. downloadname = "目标录入导入模板.xlsm";
  261. url = "static/template/plant/targetlist.xlsm";
  262. } else if( type.equals("targetreview") ) {
  263. downloadname = "目标回顾导入模板.xlsx";
  264. url = "static/template/plant/targetreview.xlsx";
  265. } else if( type.equals("manageactivity") ) {
  266. downloadname = "管理活动抽查导入模板.xlsx";
  267. url = "static/template/plant/manageactivity.xlsx";
  268. } else if( type.equals("awardrecord") ) {
  269. downloadname = "人员嘉奖记录导入模板.xlsx";
  270. url = "static/template/plant/awardrecord.xlsx";
  271. } else if( type.equals("staffmgr") ) {
  272. downloadname = "人员信息导入模板.xlsx";
  273. url = "static/template/plant/staffmgr.xlsx";
  274. } else if( type.equals("specYlrq") ) {
  275. downloadname = "压力容器导入模板.xlsx";
  276. url = "static/template/sems/specYlrq.xlsx";
  277. } else if( type.equals("specYlgd") ) {
  278. downloadname = "压力管道导入模板.xlsx";
  279. url = "static/template/sems/specYlgd.xlsx";
  280. }else if( type.equals("specGl") ) {
  281. downloadname = "锅炉导入模板.xlsx";
  282. url = "static/template/sems/specGl.xlsx";
  283. }else if( type.equals("specDzsb") ) {
  284. downloadname = "起重机械导入模板.xlsx";
  285. url = "static/template/sems/specDzsb.xlsx";
  286. }else if( type.equals("specCc") ) {
  287. downloadname = "叉车导入模板.xlsx";
  288. url = "static/template/sems/specCc.xlsx";
  289. }else if( type.equals("specDt") ) {
  290. downloadname = "电梯导入模板.xlsx";
  291. url = "static/template/sems/specDt.xlsx";
  292. }else if( type.equals("reportYlrq") ) {
  293. downloadname = "压力容器年检报告批量导入更新模板.xlsx";
  294. url = "static/template/sems/reportYlrq.xlsx";
  295. }else if( type.equals("reportYlgd") ) {
  296. downloadname = "压力管道年检报告批量导入更新模板.xlsx";
  297. url = "static/template/sems/reportYlgd.xlsx";
  298. }else if( type.equals("thickness") ) {
  299. downloadname = "定点测厚批量导入更新模板.xlsx";
  300. url = "static/template/sems/thickness.xlsx";
  301. }else if( type.equals("thicknessData") ) {
  302. downloadname = "定点测厚数据导入模板.xlsx";
  303. url = "static/template/sems/thicknessData.xlsx";
  304. }else if( type.equals("applyLock") ) {
  305. downloadname = "锁开锁关导入模板.xlsx";
  306. url = "static/template/apply/applyLock.xlsx";
  307. }else if( type.equals("workcertificateCbps") ) {
  308. downloadname = "作业证书模板.xlsx";
  309. url = "static/template/training/workcertificateCbps.xlsx";
  310. }else if( type.equals("quality") ) {
  311. downloadname = "质量月报批量导入模板.xlsx";
  312. url = "static/template/production/quality.xlsx";
  313. }else if( type.equals("trainingMatrix") ) {
  314. downloadname = "培训矩阵导入模板.xlsx";
  315. url = "static/template/training/trainingMatrix.xlsx";
  316. }else if( type.equals("ljPlanTmpl") ) {
  317. downloadname = "裂解培训导入模板.xlsx";
  318. url = "static/template/training/bccnewDsdt.xlsx";
  319. }else if( type.equals("ysPlanTmpl") ) {
  320. downloadname = "压缩培训导入模板.xlsx";
  321. url = "static/template/training/bccnewDsdt.xlsx";
  322. }else if( type.equals("flPlanTmpl") ) {
  323. downloadname = "分离培训导入模板.xlsx";
  324. url = "static/template/training/bccnewDsdt.xlsx";
  325. }else if( type.equals("ftPlanTmpl") ) {
  326. downloadname = "芳烃培训导入模板.xlsx";
  327. url = "static/template/training/bccnewDsdt.xlsx";
  328. }else if( type.equals("jzPlanTmpl") ) {
  329. downloadname = "装置级培训导入模板.xlsx";
  330. url = "static/template/training/bccnewJz.xlsx";
  331. }else if( type.equals("trainerTmpl") ) {
  332. downloadname = "导师库导入模板.xlsx";
  333. url = "static/template/training/bccnewDsk.xlsx";
  334. }else if( type.equals("shiftRoster") ) {
  335. downloadname = "排班计划导入模板.xlsx";
  336. url = "static/template/training/roster.xlsx";
  337. }else if( type.equals("pssrTmpl") ) {
  338. downloadname = "开车条件确认表导入模板.xlsx";
  339. url = "static/template/pssr/pssrTmpl.xlsx";
  340. }else if( type.equals("pssrRegionTmpl") ) {
  341. downloadname = "PSSR区域导入模板.xlsx";
  342. url = "static/template/pssr/pssrRegionTmpl.xlsx";
  343. }else if( type.equals("overhaulExchanger") ) {
  344. downloadname = "PSSR检修项目-换热器导入模板.xlsx";
  345. url = "static/template/pssr/overhaulExchanger.xlsx";
  346. }else if( type.equals("overhaulTower") ) {
  347. downloadname = "PSSR检修项目-塔罐导入模板.xlsx";
  348. url = "static/template/pssr/overhaulTower.xlsx";
  349. }else if( type.equals("overhaulValve") ) {
  350. downloadname = "PSSR检修项目-阀门导入模板.xlsx";
  351. url = "static/template/pssr/overhaulValve.xlsx";
  352. }else if( type.equals("overhaulFilter") ) {
  353. downloadname = "PSSR检修项目-过滤器导入模板.xlsx";
  354. url = "static/template/pssr/overhaulFilter.xlsx";
  355. }else if( type.equals("pssrblind") ) {
  356. downloadname = "PSSR盲板导入模板.xlsx";
  357. url = "static/template/pssr/blind.xlsx";
  358. }else if( type.equals("overhaulExchanger2") ) {
  359. downloadname = "PSSR检修项目-电仪导入模板.xlsx";
  360. url = "static/template/pssr/overhaulExchanger.xlsx";
  361. }else if( type.equals("overhaulExchanger3") ) {
  362. downloadname = "PSSR检修项目-反应器导入模板.xlsx";
  363. url = "static/template/pssr/overhaulExchanger.xlsx";
  364. }else if( type.equals("overhaulExchanger4") ) {
  365. downloadname = "PSSR检修项目-裂解炉导入模板.xlsx";
  366. url = "static/template/pssr/overhaulExchanger.xlsx";
  367. }else if( type.equals("overhaulExchanger5") ) {
  368. downloadname = "PSSR检修项目-其它导入模板.xlsx";
  369. url = "static/template/pssr/overhaulExchanger.xlsx";
  370. }else if( type.equals("hygiene") ) {
  371. downloadname = "PSSR现场卫生导入模板.xlsx";
  372. url = "static/template/pssr/hygiene.xlsx";
  373. }else if( type.equals("measure") ) {
  374. downloadname = "PSSR人身防护现场转动设备防护措施检查表导入模板.xlsx";
  375. url = "static/template/pssr/measure.xlsx";
  376. }else if( type.equals("protection") ) {
  377. downloadname = "PSSR人身防护现场管道和设备保温防护检查表导入模板.xlsx";
  378. url = "static/template/pssr/protection.xlsx";
  379. }
  380. InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(url);
  381. downloadFile(downloadname, is, request, response);
  382. }
  383. /**
  384. * 通用下载请求
  385. *
  386. * @param fileName 文件名称
  387. * @param delete 是否删除
  388. */
  389. @GetMapping("common/download")
  390. public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
  391. {
  392. try
  393. {
  394. if (!FileUtils.isValidFilename(fileName))
  395. {
  396. throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
  397. }
  398. String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
  399. String filePath = RuoYiConfig.getDownloadPath() + fileName;
  400. response.setCharacterEncoding("utf-8");
  401. response.setContentType("multipart/form-data");
  402. response.setHeader("Content-Disposition",
  403. "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
  404. FileUtils.writeBytes(filePath, response.getOutputStream());
  405. if (delete)
  406. {
  407. FileUtils.deleteFile(filePath);
  408. }
  409. }
  410. catch (Exception e)
  411. {
  412. log.error("下载文件失败", e);
  413. }
  414. }
  415. /**
  416. * 通用上传请求
  417. */
  418. @PostMapping("/common/upload")
  419. public AjaxResult uploadFile(MultipartFile file) throws Exception
  420. {
  421. try
  422. {
  423. // 上传文件路径
  424. String filePath = RuoYiConfig.getUploadPath();
  425. // 上传并返回新文件名称
  426. String fileName = FileUploadUtils.upload(filePath, file);
  427. String url = serverConfig.getUrl() + fileName;
  428. logger.info("url:" + url);
  429. AjaxResult ajax = AjaxResult.success();
  430. ajax.put("fileName", fileName);
  431. ajax.put("url", url);
  432. return ajax;
  433. }
  434. catch (Exception e)
  435. {
  436. return AjaxResult.error(e.getMessage());
  437. }
  438. }
  439. /**
  440. * 通用上传请求(多个)
  441. */
  442. @PostMapping("/common/uploads")
  443. public AjaxResult uploadFiles(List<MultipartFile> files, @RequestParam(value = "fileDir", required = false) String fileDir) throws Exception {
  444. try {
  445. // 上传文件路径
  446. String filePath;
  447. if (StringUtils.isNotEmpty(fileDir)) {
  448. filePath = RuoYiConfig.getUploadPath(getResource(fileDir));
  449. } else {
  450. filePath = RuoYiConfig.getUploadPath();
  451. }
  452. List<String> urls = new ArrayList<String>();
  453. List<String> fileNames = new ArrayList<String>();
  454. List<String> newFileNames = new ArrayList<String>();
  455. List<String> originalFilenames = new ArrayList<String>();
  456. for (MultipartFile file : files) {
  457. // 上传并返回新文件名称
  458. String fileName = FileUploadUtils.upload(filePath, file);
  459. String url = serverConfig.getUrl();
  460. if (url.contains("81")){
  461. url += "/cpms";
  462. }
  463. url = url + fileName;
  464. urls.add(url);
  465. fileNames.add(fileName);
  466. newFileNames.add(FileUtils.getName(fileName));
  467. originalFilenames.add(file.getOriginalFilename());
  468. }
  469. AjaxResult ajax = AjaxResult.success();
  470. ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER));
  471. ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER));
  472. ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
  473. ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
  474. return ajax;
  475. } catch (Exception e) {
  476. return AjaxResult.error(e.getMessage());
  477. }
  478. }
  479. private static String getResource(String type) {
  480. switch (type) {
  481. case "1":
  482. return "/annihiliator";
  483. case "12":
  484. return "/eyewash";
  485. default:
  486. return "";
  487. }
  488. }
  489. /**
  490. * 本地资源通用下载
  491. */
  492. @GetMapping("/common/download/resource")
  493. public void resourceDownload(String name, HttpServletRequest request, HttpServletResponse response) throws Exception
  494. {
  495. // 本地资源路径
  496. String localPath = RuoYiConfig.getProfile();
  497. // 数据库资源地址
  498. String downloadPath = localPath + StringUtils.substringAfter(name, Constants.RESOURCE_PREFIX);
  499. // 下载名称
  500. String downloadName = StringUtils.substringAfterLast(downloadPath, "/");
  501. response.setCharacterEncoding("utf-8");
  502. response.setContentType("multipart/form-data");
  503. response.setHeader("Content-Disposition",
  504. "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, downloadName));
  505. FileUtils.writeBytes(downloadPath, response.getOutputStream());
  506. }
  507. public static void downloadFile(String filename, InputStream is, HttpServletRequest request, HttpServletResponse response) throws IOException {
  508. response.reset();
  509. if (filename.endsWith(".doc") || filename.endsWith(".docx")) {
  510. response.setContentType("application/msword;charset=utf-8");
  511. } else if (filename.endsWith(".xls") || filename.endsWith(".xlsx")) {
  512. response.setContentType("application/vnd.ms-excel;charset=utf-8");
  513. } else {
  514. response.setHeader("content-type", "application/octet-stream");
  515. }
  516. //下载文件的名称
  517. response.setHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes("UTF-8"), "iso-8859-1"));
  518. request.setCharacterEncoding("UTF-8");
  519. ServletOutputStream out = null;
  520. BufferedInputStream bis = null;
  521. BufferedOutputStream bos = null;
  522. try {
  523. out = response.getOutputStream();
  524. bis = new BufferedInputStream(is);
  525. bos = new BufferedOutputStream(out);
  526. byte[] buff = new byte[2048];
  527. int bytesRead;
  528. while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
  529. bos.write(buff, 0, bytesRead);
  530. }
  531. } catch (IOException e) {
  532. e.printStackTrace();
  533. } finally {
  534. try {
  535. if (bis != null) {
  536. bis.close();
  537. }
  538. if (bos != null) {
  539. bos.close();
  540. }
  541. if (is != null) {
  542. is.close();
  543. }
  544. } catch (IOException e) {
  545. e.printStackTrace();
  546. }
  547. }
  548. }
  549. // @RequestMapping("/common/download/exportDevList")
  550. // public ModelAndView exportbmy(@RequestParam Map<String, Object> params, HttpServletRequest request, HttpServletResponse response) throws ParseException {
  551. // logger.info(JSON.toJSONString(params));
  552. // String id = (String) params.get("ids");
  553. // int devType = Integer.parseInt((String) params.get("devType"));
  554. // String[] ids = id.split(",");
  555. // logger.info("ids" + ids);
  556. // int downloadType = Integer.parseInt((String) params.get("downloadType"));
  557. // logger.info("downloadType" + downloadType);
  558. // List<Object> list = new ArrayList<>();
  559. // switch (devType) {
  560. // case 1:
  561. // for (String i : ids
  562. // ) {
  563. // TSpecdevYlrq ylrqEntity = tSpecdevYlrqService.getById(i);
  564. // list.add(ylrqEntity);
  565. // }
  566. // break;
  567. // case 2:
  568. // for (String i : ids
  569. // ) {
  570. // TSpecdevYlgd ylgdEntity = tSpecdevYlgdService.getById(i);
  571. // list.add(ylgdEntity);
  572. // }
  573. // break;
  574. // case 3:
  575. // for (String i : ids
  576. // ) {
  577. // TSpecdevDzsb dzsbEntity = tSpecdevDzsbService.getById(i);
  578. // list.add(dzsbEntity);
  579. // }
  580. // break;
  581. // case 4:
  582. // for (String i : ids
  583. // ) {
  584. // TSpecdevGl glEntity = tSpecdevGlService.getById(i);
  585. // list.add(glEntity);
  586. // }
  587. // break;
  588. // case 5:
  589. // for (String i : ids
  590. // ) {
  591. // TSpecdevDt dtEntity = tSpecdevDtService.getById(i);
  592. // list.add(dtEntity);
  593. // }
  594. // break;
  595. // case 6:
  596. // for (String i : ids
  597. // ) {
  598. // TSpecdevCc ccEntity = tSpecdevCcService.getById(i);
  599. // list.add(ccEntity);
  600. // }
  601. // break;
  602. // case 7:
  603. //// for (String i : ids
  604. //// ) {
  605. //// TOtherTankEntity tankEntity = tOtherTankService.getById(i);
  606. //// list.add(tankEntity);
  607. //// }
  608. // }
  609. // if(devType == 1 && downloadType == 2){ return new ModelAndView(new JxlsView(JxlsTemplateEnum.DEV_YLRQ_UPDATE, list)); }
  610. // else if(devType == 2 && downloadType == 2){ return new ModelAndView(new JxlsView(JxlsTemplateEnum.DEV_YLGD_UPDATE, list)); }
  611. // else if(devType == 3 && downloadType == 2){ return new ModelAndView(new JxlsView(JxlsTemplateEnum.DEV_DZSB_UPDATE, list)); }
  612. // else if(devType == 4 && downloadType == 2){ return new ModelAndView(new JxlsView(JxlsTemplateEnum.DEV_GL_UPDATE, list)); }
  613. // else if(devType == 5 && downloadType == 2){ return new ModelAndView(new JxlsView(JxlsTemplateEnum.DEV_DT_UPDATE, list)); }
  614. // else if(devType == 6 && downloadType == 2){ return new ModelAndView(new JxlsView(JxlsTemplateEnum.DEV_CC_UPDATE, list)); }
  615. // return null;
  616. // }
  617. @GetMapping("/common/download/exportDevList")
  618. public AjaxResult exportbmy(TSpecdevGl tSpecdevGl) throws IOException {
  619. logger.info("kaishi");
  620. SXSSFWorkbook wb = new SXSSFWorkbook(1000);
  621. CellStyle wrapStyle = wb.createCellStyle();
  622. wrapStyle.setWrapText(true); //设置自动换行
  623. //创建sheet页
  624. Sheet sheet = wb.createSheet("sheetName");
  625. //设置列的宽度,第一个参数为列的序号,从0开始,第二参数为列宽,单位1/256个字节
  626. sheet.setColumnWidth(0, 12*256);
  627. sheet.setColumnWidth(2, 16*256);
  628. sheet.setColumnWidth(5, 12*256);
  629. sheet.setColumnWidth(6, 26*256);
  630. sheet.setColumnWidth(7, 26*256);
  631. //设置开始行和开始列
  632. int rowIndex = 0;
  633. int columnIndex = 0;
  634. Row row = sheet.createRow(rowIndex);
  635. OutputStream out = null;
  636. String filename = encodingFilename("sheetName");
  637. out = new FileOutputStream(getAbsoluteFile(filename));
  638. wb.write(out);
  639. wb.close();
  640. out.close();
  641. return AjaxResult.success(filename);
  642. }
  643. /**
  644. * 编码文件名
  645. */
  646. public String encodingFilename(String filename)
  647. {
  648. filename = UUID.randomUUID().toString() + "_" + filename + ".xlsx";
  649. return filename;
  650. }
  651. /**
  652. * 获取下载路径
  653. *
  654. * @param filename 文件名称
  655. */
  656. public String getAbsoluteFile(String filename)
  657. {
  658. String downloadPath = RuoYiConfig.getDownloadPath() + filename;
  659. File desc = new File(downloadPath);
  660. if (!desc.getParentFile().exists())
  661. {
  662. desc.getParentFile().mkdirs();
  663. }
  664. return downloadPath;
  665. }
  666. }