package com.ruoyi.project.pssr.controller; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.file.ExcelUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.framework.aspectj.lang.annotation.Log; import com.ruoyi.framework.aspectj.lang.enums.BusinessType; import com.ruoyi.framework.web.controller.BaseController; import com.ruoyi.framework.web.domain.AjaxResult; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.project.pssr.domain.TPssrSafetyValve; import com.ruoyi.project.pssr.mapper.TPssrSafetyValveMapper; import com.ruoyi.project.pssr.service.ITPssrFileService; import com.ruoyi.project.pssr.service.ITPssrSafetyValveService; import com.ruoyi.project.pssr.service.ITPssrTurndownService; import com.ruoyi.project.system.domain.SysUser; import com.ruoyi.project.system.service.ISysUserService; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFSheet; 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 javax.annotation.Resource; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.List; import java.util.UUID; /** * 安全设施-安全阀Controller * * @author ssy * @date 2024-09-18 */ @RestController @RequestMapping("/pssr/safetyValve") public class TPssrSafetyValveController extends BaseController { @Resource private TPssrSafetyValveMapper tPssrSafetyValveMapper; @Autowired private ITPssrFileService tPssrFileService; @Autowired private ITPssrTurndownService tPssrTurndownService; @Autowired private ITPssrSafetyValveService tPssrSafetyValveService; @Autowired private ISysUserService sysUserService; private String forShort = "aqss-v"; /** * 查询安全设施-安全阀列表 */ @PreAuthorize("@ss.hasPermi('pssr:safetyValve:list')") @GetMapping("/list") public TableDataInfo list(TPssrSafetyValve tPssrSafetyValve) { startPage(); List list = tPssrSafetyValveService.selectTPssrSafetyValveList(tPssrSafetyValve); list.forEach(item -> { item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "aqss-v")); if (item.getApproveStatus() != 2) item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "aqss-v")); }); return getDataTable(list); } /** * 导出安全设施-安全阀列表 */ @PreAuthorize("@ss.hasPermi('pssr:safetyValve:export')") @Log(title = "安全设施-安全阀", businessType = BusinessType.EXPORT) @GetMapping("/export") public AjaxResult export(TPssrSafetyValve tPssrSafetyValve) { List list = tPssrSafetyValveService.selectTPssrSafetyValveList(tPssrSafetyValve); return AjaxResult.success(exportTmpl(list)); } public String exportTmpl(List list) { OutputStream out = null; String filename = null; try { String tempUrl = "static/word/pssr/aqssaqf.xlsx"; // 模板文件 InputStream is = null; is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl); XSSFWorkbook wb = null; wb = new XSSFWorkbook(is); XSSFSheet sheet = wb.getSheetAt(0); //填充数据 int rowIndex = 3; int num = 1; Row originalRow = sheet.getRow(3); Cell originalcell = originalRow.getCell(0); // 获取单元格样式 CellStyle originalStyle = originalcell.getCellStyle(); for (TPssrSafetyValve t : list) { Row row = sheet.createRow(rowIndex); row.setHeight((short) 800); row.createCell(0).setCellValue(num); row.createCell(1).setCellValue(t.getUnit()); row.createCell(2).setCellValue(t.getPidNo()); row.createCell(3).setCellValue(t.getDevNo()); row.createCell(4).setCellValue(t.getSafetyDev()); row.createCell(5).setCellValue(t.getVerify()); row.createCell(6).setCellValue(t.getInValidity()); row.createCell(7).setCellValue(t.getInstallLocation()); row.createCell(8).setCellValue(t.getInstallAccuracy()); row.createCell(9).setCellValue(t.getPutUse()); row.createCell(10).setCellValue(t.getSetPressure()); row.createCell(11).setCellValue(t.getUniformPressure()); row.createCell(12); row.createCell(13); try { SysUser sysUser1 = sysUserService.selectUserById(Long.valueOf(t.getConfirmer1())); SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirmer2())); String confirm1 = sysUser1.getSignUrl(); String confirm2 = sysUser2.getSignUrl(); ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 12, 1, 1); ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 13, 1, 1); } catch (NumberFormatException e) { throw new RuntimeException(e); } row.createCell(14).setCellValue(DateUtils.dateTime(t.getConfirmationTime())); row.createCell(15).setCellValue(t.getRemarks()); //渲染样式 for (int i = 0; i < 16; i++) { row.getCell(i).setCellStyle(originalStyle); } num++; rowIndex++; } filename = "PSSR_14_安全设施_安全阀_" + UUID.randomUUID().toString() + ".xlsx"; out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename)); wb.write(out); wb.close(); } catch (IOException e) { e.printStackTrace(); } return filename; } /** * 获取安全设施-安全阀详细信息 */ @PreAuthorize("@ss.hasPermi('pssr:safetyValve:query')") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { TPssrSafetyValve item = tPssrSafetyValveService.selectTPssrSafetyValveById(id); item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "aqss-v")); if (item.getApproveStatus() != 2) item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "aqss-v")); return AjaxResult.success(item); } /** * 新增安全设施-安全阀 */ @PreAuthorize("@ss.hasPermi('pssr:safetyValve:add')") @Log(title = "安全设施-安全阀", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody TPssrSafetyValve tPssrSafetyValve) { if (tPssrSafetyValve.getConfirmer1().equals(tPssrSafetyValve.getConfirmer2())){ return AjaxResult.error("确认人不能为同一人,请重新选择!"); } tPssrSafetyValve.setApproveStatus(0L); return toAjax(tPssrSafetyValveService.insertTPssrSafetyValve(tPssrSafetyValve)); } /** * 修改安全设施-安全阀 */ @PreAuthorize("@ss.hasPermi('pssr:safetyValve:edit')") @Log(title = "安全设施-安全阀", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody TPssrSafetyValve tPssrSafetyValve) { if (tPssrSafetyValve.getConfirmer1().equals(tPssrSafetyValve.getConfirmer2())){ return AjaxResult.error("确认人不能为同一人,请重新选择!"); } tPssrFileService.updateFileRelevance(tPssrSafetyValve.getFileIds(), "aqss-v", tPssrSafetyValve.getId(), tPssrSafetyValve.getSubId()); return toAjax(tPssrSafetyValveService.updateTPssrSafetyValve(tPssrSafetyValve)); } /** * 修改安全设施-安全阀 */ @PreAuthorize("@ss.hasPermi('pssr:safetyValve:edit')") @Log(title = "安全设施-安全阀", businessType = BusinessType.UPDATE) @PutMapping("/editBatch") public AjaxResult editb(@RequestBody TPssrSafetyValve tPssrSafetyValve) { if (tPssrSafetyValve.getConfirmer1().equals(tPssrSafetyValve.getConfirmer2())){ return AjaxResult.error("确认人不能为同一人,请重新选择!"); } return toAjax(tPssrSafetyValveMapper.updateTPssrSafetyValveByIds(tPssrSafetyValve)); } /** * 删除安全设施-安全阀 */ @PreAuthorize("@ss.hasPermi('pssr:safetyValve:remove')") @Log(title = "安全设施-安全阀", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(tPssrSafetyValveService.deleteTPssrSafetyValveByIds(ids)); } }