TApplyLockController.java 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. package com.ruoyi.project.apply.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.ruoyi.common.utils.file.ExcelUtils;
  4. import com.ruoyi.common.utils.poi.ExcelUtil;
  5. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  6. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  7. import com.ruoyi.framework.interceptor.annotation.RepeatSubmit;
  8. import com.ruoyi.framework.web.controller.BaseController;
  9. import com.ruoyi.framework.web.domain.AjaxResult;
  10. import com.ruoyi.framework.web.page.TableDataInfo;
  11. import com.ruoyi.project.apply.domain.TApplyLock;
  12. import com.ruoyi.project.apply.domain.TApplyOfflinevalve;
  13. import com.ruoyi.project.apply.domain.TApplySafetychange;
  14. import com.ruoyi.project.apply.service.ITApplyLockService;
  15. import com.ruoyi.project.apply.service.ITApplyOfflinevalveService;
  16. import com.ruoyi.project.apply.service.ITApplySafetychangeService;
  17. import com.ruoyi.project.system.domain.SysDept;
  18. import com.ruoyi.project.system.service.ISysDeptService;
  19. import org.apache.poi.ss.usermodel.Cell;
  20. import org.apache.poi.ss.usermodel.Row;
  21. import org.apache.poi.ss.usermodel.Sheet;
  22. import org.apache.poi.ss.usermodel.Workbook;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.security.access.prepost.PreAuthorize;
  25. import org.springframework.web.bind.annotation.*;
  26. import org.springframework.web.multipart.MultipartFile;
  27. import java.io.IOException;
  28. import java.util.*;
  29. /**
  30. * 破锁管理Controller
  31. *
  32. * @author ruoyi
  33. * @date 2023-03-06
  34. */
  35. @RestController
  36. @RequestMapping("/apply/lock")
  37. public class TApplyLockController extends BaseController {
  38. @Autowired
  39. private ITApplyLockService tApplyLockService;
  40. @Autowired
  41. private ISysDeptService iSysDeptService;
  42. @Autowired
  43. private ITApplyOfflinevalveService tApplyOfflinevalveService;
  44. @Autowired
  45. private ITApplySafetychangeService tApplySafetychangeService;
  46. @GetMapping(value = "/getInfoByLock/{lockNo}")
  47. public AjaxResult getInfoByLock(@PathVariable("lockNo") String lockNo) {
  48. TApplyOfflinevalve lock = tApplyOfflinevalveService.selectTApplyOfflinevalveByLock(lockNo);
  49. TApplySafetychange lock1 = tApplySafetychangeService.selectTApplySafetychangeByLock(lockNo);
  50. Map<String, Object> map = new HashMap<>();
  51. if (lock != null) {
  52. map.put("type", 1);
  53. map.put("data", lock);
  54. } else if (lock1 != null) {
  55. map.put("type", 2);
  56. map.put("data", lock1);
  57. } else {
  58. map.put("type", 3);
  59. }
  60. return AjaxResult.success(map);
  61. }
  62. /**
  63. * 查询破锁管理列表
  64. */
  65. @PreAuthorize("@ss.hasPermi('apply:lock:list')")
  66. @GetMapping("/list")
  67. public TableDataInfo list(TApplyLock tApplyLock) {
  68. startPage();
  69. List<TApplyLock> list = tApplyLockService.selectTApplyLockList(tApplyLock);
  70. return getDataTable(list);
  71. }
  72. @PreAuthorize("@ss.hasPermi('apply:lock:list')")
  73. @GetMapping("/listLockBranch")
  74. public AjaxResult listLockBranch(TApplyLock tApplyLock) {
  75. //查询所有锁数据
  76. List<TApplyLock> list = tApplyLockService.selectTApplyLockList(tApplyLock);
  77. List<List<TApplyLock>> result = new ArrayList<>();//行元素
  78. List<TApplyLock> item = new ArrayList<>();//列元素
  79. int count = 1;//列统计
  80. for (int i = 0; i < list.size(); i++) {
  81. item.add(list.get(i));//添加列
  82. if (count == 35) {//当列达到35个
  83. count = 0;
  84. result.add(item);//将所有列添加到行
  85. item = new ArrayList<>();
  86. } else if ((list.size() % 35) == (list.size() - i)) {//总数%35=它本身,即剩余锁个数不满35个时
  87. item = new ArrayList<>(list.subList(i, list.size()));//将剩下的所有锁添加到列
  88. for (int j = 0; j < (35 - (list.size() - i)); j++) {//填充空对象充满该行
  89. item.add(new TApplyLock());
  90. }
  91. result.add(item);
  92. break;
  93. }
  94. count++;
  95. }
  96. return AjaxResult.success(result);
  97. }
  98. @GetMapping("/listAllLock")
  99. public AjaxResult listAllLock(TApplyLock tApplyLock) {
  100. return AjaxResult.success(tApplyLockService.selectTApplyLockList(tApplyLock));
  101. }
  102. /**
  103. * 导出破锁管理列表
  104. */
  105. @PreAuthorize("@ss.hasPermi('apply:lock:export')")
  106. @Log(title = "破锁管理", businessType = BusinessType.EXPORT)
  107. @GetMapping("/export")
  108. public AjaxResult export(TApplyLock tApplyLock) {
  109. List<TApplyLock> list = tApplyLockService.selectTApplyLockList(tApplyLock);
  110. ExcelUtil<TApplyLock> util = new ExcelUtil<TApplyLock>(TApplyLock.class);
  111. return util.exportExcel(list, "lock");
  112. }
  113. /**
  114. * 获取破锁管理详细信息
  115. */
  116. @PreAuthorize("@ss.hasPermi('apply:lock:query')")
  117. @GetMapping(value = "/{id}")
  118. public AjaxResult getInfo(@PathVariable("id") Long id) {
  119. return AjaxResult.success(tApplyLockService.selectTApplyLockById(id));
  120. }
  121. /**
  122. * 新增破锁管理
  123. */
  124. @PreAuthorize("@ss.hasPermi('apply:lock:add')")
  125. @Log(title = "破锁管理", businessType = BusinessType.INSERT)
  126. @RepeatSubmit
  127. @PostMapping
  128. public AjaxResult add(@RequestBody TApplyLock tApplyLock) {
  129. tApplyLock.setCreaterCode(getUserId().toString());
  130. tApplyLock.setCreatedate(new Date());
  131. return toAjax(tApplyLockService.insertTApplyLock(tApplyLock));
  132. }
  133. /**
  134. * 修改破锁管理
  135. */
  136. @PreAuthorize("@ss.hasPermi('apply:lock:edit')")
  137. @Log(title = "破锁管理", businessType = BusinessType.UPDATE)
  138. @RepeatSubmit
  139. @PutMapping
  140. public AjaxResult edit(@RequestBody TApplyLock tApplyLock) {
  141. return toAjax(tApplyLockService.updateTApplyLock(tApplyLock));
  142. }
  143. /**
  144. * 删除破锁管理
  145. */
  146. @PreAuthorize("@ss.hasPermi('apply:lock:remove')")
  147. @Log(title = "破锁管理", businessType = BusinessType.DELETE)
  148. @DeleteMapping("/{ids}")
  149. public AjaxResult remove(@PathVariable Long[] ids) {
  150. return toAjax(tApplyLockService.deleteTApplyLockByIds(ids));
  151. }
  152. @PreAuthorize("@ss.hasPermi('apply:lock:add')")
  153. @Log(title = "破锁管理", businessType = BusinessType.INSERT)
  154. @PostMapping("/importData")
  155. public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException {
  156. //获取操作人员ID
  157. Long userId = getUserId();
  158. //报错行数统计
  159. List<Integer> failRow = new ArrayList<Integer>();
  160. Workbook workbook = ExcelUtils.getWorkBook(file);
  161. Sheet sheet = workbook.getSheetAt(0);
  162. List<TApplyLock> list = new ArrayList<>();
  163. int rowNum = sheet.getPhysicalNumberOfRows();
  164. //部门查询
  165. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  166. int failNumber = 0;
  167. for (int i = 1; i < rowNum; i++) {
  168. try {
  169. logger.info("读取行数:" + i);
  170. Row row = sheet.getRow(i);
  171. int cellNum = row.getPhysicalNumberOfCells();
  172. TApplyLock entity = new TApplyLock();
  173. for (int j = 0; j < cellNum; j++) {
  174. Cell cell = row.getCell(j);
  175. // cell.setCellType(CellType.STRING);
  176. String cellValue = ExcelUtils.getCellValue(cell);
  177. logger.info("cellValue:" + cellValue);
  178. if (j == 0) {
  179. entity.setUnit(cellValue.trim());
  180. } else if (j == 1) {
  181. entity.setLockPost(cellValue.trim());
  182. } else if (j == 2) {
  183. entity.setPidNo(cellValue.trim());
  184. } else if (j == 3) {
  185. entity.setLockCode(cellValue.trim());
  186. } else if (j == 4) {
  187. entity.setMedium(cellValue.trim());
  188. } else if (j == 5) {
  189. entity.setPosition(cellValue.trim());
  190. } else if (j == 6) {
  191. entity.setReason(cellValue.trim());
  192. } else if (j == 7) {
  193. entity.setTechnology(cellValue.trim());
  194. } else if (j == 8) {
  195. entity.setRiskLevel(cellValue.trim());
  196. } else if (j == 9) {
  197. entity.setLockSize(cellValue.trim());
  198. } else if (j == 10) {
  199. entity.setValveStatus(cellValue.trim());
  200. } else if (j == 11) {
  201. for (SysDept d : dept) {
  202. if (d.getDeptName().equals(cellValue.trim())) {
  203. entity.setDeptId(d.getDeptId());//部门编号
  204. }
  205. }
  206. }
  207. }
  208. entity.setCreaterCode(userId.toString());
  209. entity.setCreatedate(new Date());
  210. logger.info("entity:" + entity);
  211. list.add(entity);
  212. } catch (Exception e) {
  213. logger.error("Exception:{}", e.getMessage());
  214. failNumber++;
  215. failRow.add(i + 1);
  216. }
  217. }
  218. int successNumber = 0;
  219. int failNum = 0;
  220. for (TApplyLock t : list
  221. ) {
  222. failNum++;
  223. try {
  224. tApplyLockService.insertTApplyLock(t);
  225. successNumber++;
  226. } catch (Exception e) {
  227. failNumber++;
  228. failRow.add(failNum + 1);
  229. }
  230. }
  231. logger.info("list:" + JSON.toJSONString(list));
  232. logger.info("successNumber:" + String.valueOf(successNumber));
  233. logger.info("failNumber:" + String.valueOf(failNumber));
  234. logger.info("failRow:" + String.valueOf(failRow));
  235. return AjaxResult.success(String.valueOf(successNumber), failRow);
  236. }
  237. }