123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- package com.cpms.project.process.controller;
- import com.alibaba.fastjson2.JSON;
- import com.cpms.common.annotation.Log;
- import com.cpms.common.config.RuoYiConfig;
- import com.cpms.common.core.controller.BaseController;
- import com.cpms.common.core.domain.AjaxResult;
- import com.cpms.common.core.page.TableDataInfo;
- import com.cpms.common.enums.BusinessType;
- import com.cpms.common.utils.DateUtils;
- import com.cpms.common.utils.file.ExcelUtils;
- import com.cpms.common.utils.poi.ExcelUtil;
- import com.cpms.project.process.domain.TLockValve;
- import com.cpms.project.process.service.ITLockValveService;
- import org.apache.poi.ss.usermodel.*;
- import org.apache.poi.xssf.streaming.SXSSFWorkbook;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.security.access.prepost.PreAuthorize;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import javax.servlet.http.HttpServletResponse;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * 阀门锁开锁关状态记录Controller
- *
- * @author admin
- * @date 2024-04-03
- */
- @RestController
- @RequestMapping("/process/valve")
- public class TLockValveController extends BaseController {
- @Autowired
- private ITLockValveService tLockValveService;
- /**
- * 查询阀门锁开锁关状态记录列表
- */
- @PreAuthorize("@ss.hasPermi('process:valve:list')")
- @GetMapping("/list")
- public TableDataInfo list(TLockValve tLockValve) {
- startPage();
- List<TLockValve> list = tLockValveService.selectTLockValveList(tLockValve);
- return getDataTable(list);
- }
- /**
- * 导出阀门锁开锁关状态记录列表
- */
- @PreAuthorize("@ss.hasPermi('process:valve:export')")
- @Log(title = "阀门锁开锁关状态记录", businessType = BusinessType.EXPORT)
- @PostMapping("/export")
- public void export(HttpServletResponse response, TLockValve tLockValve) {
- List<TLockValve> list = tLockValveService.selectTLockValveList(tLockValve);
- ExcelUtil<TLockValve> util = new ExcelUtil<TLockValve>(TLockValve.class);
- util.exportExcel(response, list, "阀门锁开锁关状态记录数据");
- }
- /**
- * 导出阀门锁开锁关状态记录列表
- */
- @PreAuthorize("@ss.hasPermi('process:valve:export')")
- @Log(title = "阀门锁开锁关状态记录", businessType = BusinessType.EXPORT)
- @PostMapping("/exportTmpl")
- public void exportTmpl(HttpServletResponse response, TLockValve tLockValve) {
- List<TLockValve> list = tLockValveService.selectTLockValveList(tLockValve);
- try {
- String tempUrl = "static/template/process/valveExport.xlsx"; // 模板文件
- InputStream is = null;
- is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
- XSSFWorkbook wb1 = null;
- wb1 = new XSSFWorkbook(is);
- SXSSFWorkbook wb = new SXSSFWorkbook(wb1, 1000);
- Sheet sheet;
- if (wb instanceof SXSSFWorkbook) {
- SXSSFWorkbook sxssfWorkbook = (SXSSFWorkbook) wb;
- sheet = sxssfWorkbook.getXSSFWorkbook().getSheetAt(0);
- } else {
- sheet = wb.getSheetAt(0);
- }
- //填充数据
- int rowIndex = 6;
- int num = 1;
- Row originalRow = sheet.getRow(6);
- Cell originalcell = originalRow.getCell(0);
- // 获取单元格样式
- CellStyle originalStyle = originalcell.getCellStyle();
- for (TLockValve t: list
- ) {
- Row row = sheet.createRow(rowIndex);
- row.createCell(0).setCellValue(num);
- row.createCell(1).setCellValue(t.getUnit());
- row.createCell(2).setCellValue(t.getVtNo());
- row.createCell(3).setCellValue(t.getPidNo());
- row.createCell(4).setCellValue(t.getLocationDes());
- row.createCell(5).setCellValue(t.getMedium());
- row.createCell(6).setCellValue(t.getValveType());
- row.createCell(7).setCellValue(t.getValveSize());
- row.createCell(8).setCellValue(t.getIdentifier());
- row.createCell(9).setCellValue(t.getValvePosition());
- row.createCell(10).setCellValue(t.getFirmlySecured());
- row.createCell(11).setCellValue(t.getResponsibility());
- row.createCell(12).setCellValue(t.getCheckedBy());
- row.createCell(13).setCellValue(t.getCheckBeforeSu());
- row.createCell(14).setCellValue(t.getPidStatus());
- row.createCell(15).setCellValue(t.getRiskLevel());
- row.createCell(16).setCellValue(t.getSheReview());
- row.createCell(17).setCellValue(t.getRemarks());
- //渲染样式
- for (int i = 0; i < 18; i++) {
- row.getCell(i).setCellStyle(originalStyle);
- }
- num++;
- rowIndex++;
- }
- // 生成文件返回下载地址
- response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
- response.setCharacterEncoding("utf-8");
- wb.write(response.getOutputStream());
- wb.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- /**
- * 获取阀门锁开锁关状态记录详细信息
- */
- @PreAuthorize("@ss.hasPermi('process:valve:query')")
- @GetMapping(value = "/{id}")
- public AjaxResult getInfo(@PathVariable("id") Long id) {
- return success(tLockValveService.selectTLockValveById(id));
- }
- /**
- * 新增阀门锁开锁关状态记录
- */
- @PreAuthorize("@ss.hasPermi('process:valve:add')")
- @Log(title = "阀门锁开锁关状态记录", businessType = BusinessType.INSERT)
- @PostMapping
- public AjaxResult add(@RequestBody TLockValve tLockValve) {
- return toAjax(tLockValveService.insertTLockValve(tLockValve));
- }
- /**
- * 修改阀门锁开锁关状态记录
- */
- @PreAuthorize("@ss.hasPermi('process:valve:edit')")
- @Log(title = "阀门锁开锁关状态记录", businessType = BusinessType.UPDATE)
- @PutMapping
- public AjaxResult edit(@RequestBody TLockValve tLockValve) {
- return toAjax(tLockValveService.updateTLockValve(tLockValve));
- }
- /**
- * 删除阀门锁开锁关状态记录
- */
- @PreAuthorize("@ss.hasPermi('process:valve:remove')")
- @Log(title = "阀门锁开锁关状态记录", businessType = BusinessType.DELETE)
- @DeleteMapping("/{ids}")
- public AjaxResult remove(@PathVariable Long[] ids) {
- return toAjax(tLockValveService.deleteTLockValveByIds(ids));
- }
- @Log(title = "阀门锁开锁关状态记录批量导入", businessType = BusinessType.INSERT)
- @PostMapping("/importData")
- public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException {
- //获取操作人员ID
- Long userId = getUserId();
- //报错行数统计
- List<Integer> failRow = new ArrayList<>();
- Workbook workbook = ExcelUtils.getWorkBook(file);
- Sheet sheet = workbook.getSheetAt(0);
- List<TLockValve> list = new ArrayList<>();
- int rowNum = sheet.getPhysicalNumberOfRows();
- int failNumber = 0;
- for (int i = 3; i < rowNum; i++) {
- try {
- logger.info("读取行数:" + i);
- Row row = sheet.getRow(i);
- int cellNum = row.getLastCellNum();
- TLockValve entity = new TLockValve();
- for (int j = 0; j < cellNum; j++) {
- Cell cell = row.getCell(j);
- if (cell == null) {
- continue;
- }
- String cellValue = ExcelUtils.getCellValue(cell);
- logger.info("cellValue:" + cellValue);
- if (j == 0) {
- entity.setUnit(cellValue);
- } else if (j == 1) {
- entity.setVtNo(cellValue);
- } else if (j == 2) {
- entity.setPidNo(cellValue);
- } else if (j == 3) {
- entity.setLocationDes(cellValue);
- } else if (j == 4) {
- entity.setMedium(cellValue);
- } else if (j == 5) {
- entity.setValveType(cellValue);
- } else if (j == 6) {
- entity.setValveSize(cellValue);
- } else if (j == 7) {
- entity.setIdentifier(cellValue);
- } else if (j == 8) {
- entity.setValvePosition(cellValue);
- } else if (j == 9) {
- entity.setFirmlySecured(cellValue);
- } else if (j == 10) {
- entity.setResponsibility(cellValue);
- } else if (j == 11) {
- entity.setCheckedBy(cellValue);
- } else if (j == 12) {
- entity.setCheckBeforeSu(cellValue);
- } else if (j == 13) {
- entity.setPidStatus(cellValue);
- } else if (j == 14) {
- entity.setRiskLevel(cellValue);
- } else if (j == 15) {
- entity.setSheReview(cellValue);
- } else if (j == 16) {
- entity.setRemarks(cellValue);
- } else if (j == 17) {
- entity.setCheckDate(DateUtils.parseDate(cellValue));
- }
- }
- entity.setCreaterCode(String.valueOf(userId));
- logger.info("entity:" + entity);
- list.add(entity);
- } catch (Exception e) {
- failNumber++;
- logger.info("e:" + JSON.toJSONString(e));
- failRow.add(i + 1);
- }
- }
- int successNumber = 0;
- int failNum = 0;
- for (TLockValve t : list
- ) {
- failNum++;
- try {
- //根据使用证、注册编号、位号,进行数据更新
- add(t);
- successNumber++;
- } catch (Exception e) {
- failNumber++;
- logger.info("e:" + e);
- failRow.add(failNum + 1);
- }
- }
- logger.info("list:" + JSON.toJSONString(list));
- logger.info("successNumber:" + successNumber);
- logger.info("failNumber:" + failNumber);
- logger.info("failRow:" + failRow);
- return AjaxResult.success(String.valueOf(successNumber), failRow);
- }
- }
|