THighpresfireController.java 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. package com.ruoyi.project.ehs.controller;
  2. import java.io.IOException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.ArrayList;
  5. import java.util.Date;
  6. import java.util.List;
  7. import com.alibaba.fastjson.JSON;
  8. import com.ruoyi.common.utils.DateUtils;
  9. import com.ruoyi.common.utils.file.ExcelUtils;
  10. import com.ruoyi.project.system.domain.SysDept;
  11. import com.ruoyi.project.system.domain.SysDictData;
  12. import com.ruoyi.project.system.service.ISysDeptService;
  13. import com.ruoyi.project.system.service.ISysDictTypeService;
  14. import org.apache.poi.ss.usermodel.*;
  15. import org.springframework.security.access.prepost.PreAuthorize;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.web.bind.annotation.*;
  18. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  19. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  20. import com.ruoyi.project.ehs.domain.THighpresfire;
  21. import com.ruoyi.project.ehs.service.ITHighpresfireService;
  22. import com.ruoyi.framework.web.controller.BaseController;
  23. import com.ruoyi.framework.web.domain.AjaxResult;
  24. import com.ruoyi.common.utils.poi.ExcelUtil;
  25. import com.ruoyi.framework.web.page.TableDataInfo;
  26. import org.springframework.web.multipart.MultipartFile;
  27. /**
  28. * 高压消防炮Controller
  29. *
  30. * @author ruoyi
  31. * @date 2020-11-25
  32. */
  33. @RestController
  34. @RequestMapping("/ehs/highpresfire")
  35. public class THighpresfireController extends BaseController
  36. {
  37. @Autowired
  38. private ITHighpresfireService tHighpresfireService;
  39. @Autowired
  40. private ISysDeptService iSysDeptService;
  41. @Autowired
  42. private ISysDictTypeService iSysDictTypeService;
  43. /**
  44. * 查询高压消防炮列表
  45. */
  46. @PreAuthorize("@ss.hasPermi('ehs:highpresfire:list')")
  47. @GetMapping("/list")
  48. public TableDataInfo list(THighpresfire tHighpresfire)
  49. {
  50. startPage();
  51. List<THighpresfire> list = tHighpresfireService.selectTHighpresfireList(tHighpresfire);
  52. return getDataTable(list);
  53. }
  54. /**
  55. * 导出高压消防炮列表
  56. */
  57. @PreAuthorize("@ss.hasPermi('ehs:highpresfire:export')")
  58. @Log(title = "高压消防炮", businessType = BusinessType.EXPORT)
  59. @GetMapping("/export")
  60. public AjaxResult export(THighpresfire tHighpresfire)
  61. {
  62. List<THighpresfire> list = tHighpresfireService.selectTHighpresfireList(tHighpresfire);
  63. ExcelUtil<THighpresfire> util = new ExcelUtil<THighpresfire>(THighpresfire.class);
  64. return util.exportExcel(list, "highpresfire");
  65. }
  66. /**
  67. * 获取高压消防炮详细信息
  68. */
  69. @PreAuthorize("@ss.hasPermi('ehs:highpresfire:query')")
  70. @GetMapping(value = "/{id}")
  71. public AjaxResult getInfo(@PathVariable("id") Long id)
  72. {
  73. return AjaxResult.success(tHighpresfireService.selectTHighpresfireById(id));
  74. }
  75. /**
  76. * 新增高压消防炮
  77. */
  78. @PreAuthorize("@ss.hasPermi('ehs:highpresfire:add')")
  79. @Log(title = "高压消防炮", businessType = BusinessType.INSERT)
  80. @PostMapping
  81. public AjaxResult add(@RequestBody THighpresfire tHighpresfire)
  82. {
  83. tHighpresfire.setCreaterCode(getUserId().toString());
  84. return toAjax(tHighpresfireService.insertTHighpresfire(tHighpresfire));
  85. }
  86. /**
  87. * 修改高压消防炮
  88. */
  89. @PreAuthorize("@ss.hasPermi('ehs:highpresfire:edit')")
  90. @Log(title = "高压消防炮", businessType = BusinessType.UPDATE)
  91. @PutMapping
  92. public AjaxResult edit(@RequestBody THighpresfire tHighpresfire)
  93. {
  94. tHighpresfire.setUpdaterCode(getUserId().toString());
  95. tHighpresfire.setUpdatedate(new Date());
  96. return toAjax(tHighpresfireService.updateTHighpresfire(tHighpresfire));
  97. }
  98. /**
  99. * 批量修改消防竖管
  100. */
  101. @PreAuthorize("@ss.hasPermi('ehs:highpresfire:edit')")
  102. @Log(title = "高压消防炮", businessType = BusinessType.UPDATE)
  103. @RequestMapping("/batchEdit")
  104. public AjaxResult batchEdit(@RequestBody THighpresfire dto)
  105. {
  106. Long[] ids = dto.getIds();
  107. for (int i = 0; i < ids.length; i++) {
  108. THighpresfire t = new THighpresfire();
  109. t.setId(ids[i]);
  110. t.setRemarks(dto.getRemarks());
  111. t.setInspectstatus(dto.getInspectstatus());
  112. t.setUpdaterCode(getUserId().toString());
  113. t.setUpdatedate(new Date());
  114. tHighpresfireService.updateTHighpresfire(t);
  115. }
  116. return AjaxResult.success();
  117. }
  118. /**
  119. * 删除高压消防炮
  120. */
  121. @PreAuthorize("@ss.hasPermi('ehs:highpresfire:remove')")
  122. @Log(title = "高压消防炮", businessType = BusinessType.DELETE)
  123. @DeleteMapping("/{ids}")
  124. public AjaxResult remove(@PathVariable Long[] ids)
  125. {
  126. return toAjax(tHighpresfireService.deleteTHighpresfireByIds(ids));
  127. }
  128. /**
  129. * 批量导入高压消防炮
  130. */
  131. @PreAuthorize("@ss.hasPermi('ehs:highpresfire:add')")
  132. @Log(title = "高压消防炮", businessType = BusinessType.INSERT)
  133. @PostMapping("/importData")
  134. public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException
  135. {
  136. //获取操作人员ID
  137. Long userId = getUserId();
  138. //报错行数统计
  139. List<Integer> failRow =new ArrayList<Integer>();
  140. Workbook workbook = ExcelUtils.getWorkBook(file);
  141. Sheet sheet = workbook.getSheetAt(0);
  142. List<THighpresfire> list = new ArrayList<THighpresfire>();
  143. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  144. //字典查询
  145. List<SysDictData> plant = iSysDictTypeService.selectDictDataByType("PLANT_DIVIDE");
  146. List<SysDictData> inspectstatus = iSysDictTypeService.selectDictDataByType("INSPECTSTATUS");
  147. //部门查询
  148. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  149. int rowNum = sheet.getPhysicalNumberOfRows();
  150. int failNumber = 0;
  151. for (int i = 1; i < rowNum; i++) {
  152. try {
  153. logger.info("读取行数:" + i);
  154. Row row = sheet.getRow(i);
  155. int cellNum = row.getPhysicalNumberOfCells();
  156. THighpresfire entity = new THighpresfire();
  157. for (int j = 0; j < cellNum; j++) {
  158. Cell cell = row.getCell(j);
  159. // cell.setCellType(CellType.STRING);
  160. String cellValue = ExcelUtils.getCellValue(cell);
  161. logger.info("cellValue:" + cellValue);
  162. if (j == 0) {
  163. for (SysDictData p : plant) {
  164. if (p.getDictLabel().equals(cellValue.trim())) {
  165. entity.setPlantCode(p.getDictValue());//装置名称
  166. }
  167. }
  168. } else if (j == 1) {
  169. entity.setNumb(cellValue);//编号
  170. } else if (j == 2) {
  171. entity.setName(cellValue);//名称
  172. } else if (j == 3) {
  173. entity.setArea(cellValue);//区域
  174. } else if (j == 4) {
  175. entity.setPosition(cellValue);//位置
  176. } else if (j == 5) {
  177. if (cellValue.length() > 3) {
  178. entity.setInspectdate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//检查日期
  179. }
  180. } else if (j == 6) {
  181. for (SysDictData p : inspectstatus) {
  182. if (p.getDictLabel().equals(cellValue.trim())) {
  183. entity.setInspectstatus(p.getDictValue());//检查状况
  184. }
  185. }
  186. } else if (j == 7) {
  187. for (SysDept d : dept) {
  188. if (d.getDeptName().equals(cellValue.trim())) {
  189. entity.setDeptId(d.getDeptId());//部门编号
  190. }
  191. }
  192. } else if (j == 8) {
  193. entity.setRemarks(cellValue);//备注
  194. }
  195. }
  196. entity.setCreaterCode(userId.toString());
  197. logger.info("entity:" + entity);
  198. list.add(entity);
  199. }catch (Exception e){
  200. failNumber++;
  201. failRow.add(i+1);
  202. }
  203. }
  204. int successNumber = 0;
  205. int failNum = 0;
  206. for (THighpresfire t : list
  207. ) {
  208. failNum++;
  209. try {
  210. tHighpresfireService.insertTHighpresfire(t);
  211. successNumber++;
  212. }catch (Exception e){
  213. failNumber++;
  214. failRow.add(failNum+1);
  215. }
  216. }
  217. logger.info("list:" + JSON.toJSONString(list));
  218. logger.info("successNumber:" +String.valueOf(successNumber));
  219. logger.info("failNumber:" +String.valueOf(failNumber));
  220. logger.info("failRow:" +String.valueOf(failRow));
  221. return AjaxResult.success(String.valueOf(successNumber), failRow);
  222. }
  223. }