123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- package com.ruoyi.project.pssr.controller;
- import com.alibaba.fastjson.JSON;
- import com.ruoyi.common.utils.DateUtils;
- import com.ruoyi.common.utils.StringUtils;
- 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.TPssrSafetyBreath;
- import com.ruoyi.project.pssr.mapper.TPssrSafetyBreathMapper;
- import com.ruoyi.project.pssr.service.ITPssrFileService;
- import com.ruoyi.project.pssr.service.ITPssrSafetyBreathService;
- import com.ruoyi.project.pssr.service.ITPssrTurndownService;
- import com.ruoyi.project.system.domain.SysDept;
- import com.ruoyi.project.system.domain.SysUser;
- import com.ruoyi.project.system.service.ISysDeptService;
- import com.ruoyi.project.system.service.ISysUserService;
- import org.apache.poi.ss.usermodel.*;
- 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 org.springframework.web.multipart.MultipartFile;
- import javax.annotation.Resource;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.UUID;
- /**
- * 安全设施-呼吸阀Controller
- *
- * @author ssy
- * @date 2024-09-18
- */
- @RestController
- @RequestMapping("/pssr/safetyBreath")
- public class TPssrSafetyBreathController extends BaseController {
- @Resource
- private TPssrSafetyBreathMapper tPssrSafetyBreathMapper;
- @Autowired
- private ITPssrFileService tPssrFileService;
- @Autowired
- private ITPssrTurndownService tPssrTurndownService;
- @Autowired
- private ITPssrSafetyBreathService tPssrSafetyBreathService;
- @Autowired
- private ISysUserService sysUserService;
- private String forShort = "aqss-bh";
- @Autowired
- private ISysDeptService iSysDeptService;
- @Autowired
- private ISysUserService userService;
- /**
- * 批量导入
- */
- @PreAuthorize("@ss.hasPermi('pssr:safetyBreath:add')")
- @PostMapping("/importData")
- public AjaxResult importInterlockData(MultipartFile file, Long subId) throws IOException
- {
- //获取操作人员ID
- Long userId = getUserId();
- //报错行数统计
- List<Integer> failRow =new ArrayList<Integer>();
- Workbook workbook = ExcelUtils.getWorkBook(file);
- Sheet sheet = workbook.getSheetAt(0);
- List<TPssrSafetyBreath> list = new ArrayList<TPssrSafetyBreath>();
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- //部门查询
- List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
- int rowNum = sheet.getPhysicalNumberOfRows();
- int failNumber = 0;
- for (int i = 2; i <= rowNum; i++) {
- try {
- logger.info("读取行数:" + i);
- Row row = sheet.getRow(i);
- int cellNum = row.getLastCellNum();
- TPssrSafetyBreath entity = new TPssrSafetyBreath();
- entity.setDeptId(userService.selectUserById(getUserId()).getDeptId());
- entity.setSubId(subId);
- entity.setApproveStatus(0L);
- for (int j = 0; j < cellNum; j++) {
- Cell cell = row.getCell(j);
- String cellValue = ExcelUtils.getCellValue(cell);
- logger.info("cellValue:" + cellValue);
- if (j == 0) {
- entity.setUnit(cellValue);
- } else if (j == 1) {
- entity.setPidNo(cellValue);
- } else if (j == 2) {
- entity.setDevNo(cellValue);
- } else if (j == 3) {
- entity.setInstallLocation(cellValue);
- } else if (j == 4) {
- entity.setSetPressure(cellValue);
- }
- }
- entity.setCreaterCode(userId.toString());
- logger.info("entity:" + entity);
- list.add(entity);
- }catch (Exception e){
- failNumber++;
- failRow.add(i+1);
- }
- }
- int successNumber = 0;
- int failNum = 0;
- for (TPssrSafetyBreath t : list
- ) {
- failNum++;
- try {
- this.add(t);
- successNumber++;
- }catch (Exception e){
- failNumber++;
- logger.info("e:" + e);
- failRow.add(failNum+1);
- }
- }
- logger.info("list:" + JSON.toJSONString(list));
- logger.info("successNumber:" +String.valueOf(successNumber));
- logger.info("failNumber:" +String.valueOf(failNumber));
- logger.info("failRow:" +String.valueOf(failRow));
- return AjaxResult.success("导入成功行数:" + String.valueOf(successNumber));
- }
- /**
- * 查询安全设施-呼吸阀列表
- */
- @PreAuthorize("@ss.hasPermi('pssr:safetyBreath:list')")
- @GetMapping("/list")
- public TableDataInfo list(TPssrSafetyBreath tPssrSafetyBreath) {
- startPage();
- List<TPssrSafetyBreath> list = tPssrSafetyBreathService.selectTPssrSafetyBreathList(tPssrSafetyBreath);
- list.forEach(item -> {
- item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "aqss-bh"));
- if (item.getApproveStatus() != 2)
- item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "aqss-bh"));
- });
- return getDataTable(list);
- }
- /**
- * 导出安全设施-呼吸阀列表
- */
- @PreAuthorize("@ss.hasPermi('pssr:safetyBreath:export')")
- @Log(title = "安全设施-呼吸阀", businessType = BusinessType.EXPORT)
- @GetMapping("/export")
- public AjaxResult export(TPssrSafetyBreath tPssrSafetyBreath) {
- List<TPssrSafetyBreath> list = tPssrSafetyBreathService.selectTPssrSafetyBreathList(tPssrSafetyBreath);
- return AjaxResult.success(exportTmpl(list));
- }
- public String exportTmpl(List<TPssrSafetyBreath> list) {
- OutputStream out = null;
- String filename = null;
- try {
- String tempUrl = "static/word/pssr/aqsshxf.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 (TPssrSafetyBreath 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.getVerify());
- row.createCell(5).setCellValue(t.getInValidity());
- row.createCell(6).setCellValue(t.getInstallLocation());
- row.createCell(7).setCellValue(t.getInstallAccuracy());
- row.createCell(8).setCellValue(t.getPutUse());
- row.createCell(9).setCellValue(t.getSetPressure());
- row.createCell(10).setCellValue(t.getUniformPressure());
- row.createCell(11);
- row.createCell(12);
- 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(), 11, 1, 1);
- ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 12, 1, 1);
- } catch (NumberFormatException e) {
- throw new RuntimeException(e);
- }
- row.createCell(13).setCellValue(DateUtils.dateTime(t.getConfirmationTime()));
- row.createCell(14).setCellValue(t.getRemarks());
- //渲染样式
- for (int i = 0; i < 15; i++) {
- row.getCell(i).setCellStyle(originalStyle);
- }
- num++;
- rowIndex++;
- }
- filename = "PSSR_14_安全设施_呼吸阀" + ".xlsx";
- out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
- wb.write(out);
- wb.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return filename;
- }
- /**
- * 获取安全设施-呼吸阀详细信息
- */
- @PreAuthorize("@ss.hasPermi('pssr:safetyBreath:query')")
- @GetMapping(value = "/{id}")
- public AjaxResult getInfo(@PathVariable("id") Long id) {
- TPssrSafetyBreath item = tPssrSafetyBreathService.selectTPssrSafetyBreathById(id);
- item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "aqss-bh"));
- if (item.getApproveStatus() != 2)
- item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "aqss-bh"));
- return AjaxResult.success(item);
- }
- /**
- * 新增安全设施-呼吸阀
- */
- @PreAuthorize("@ss.hasPermi('pssr:safetyBreath:add')")
- @Log(title = "安全设施-呼吸阀", businessType = BusinessType.INSERT)
- @PostMapping
- public AjaxResult add(@RequestBody TPssrSafetyBreath tPssrSafetyBreath) {
- if (StringUtils.isNotEmpty(tPssrSafetyBreath.getConfirmer1())&&tPssrSafetyBreath.getConfirmer1().equals(tPssrSafetyBreath.getConfirmer2())) {
- return AjaxResult.error("确认人不能为同一人,请重新选择!");
- }
- tPssrSafetyBreath.setApproveStatus(0L);
- return toAjax(tPssrSafetyBreathService.insertTPssrSafetyBreath(tPssrSafetyBreath));
- }
- /**
- * 修改安全设施-呼吸阀
- */
- @PreAuthorize("@ss.hasPermi('pssr:safetyBreath:edit')")
- @Log(title = "安全设施-呼吸阀", businessType = BusinessType.UPDATE)
- @PutMapping
- public AjaxResult edit(@RequestBody TPssrSafetyBreath tPssrSafetyBreath) {
- if (tPssrSafetyBreath.getConfirmer1().equals(tPssrSafetyBreath.getConfirmer2())){
- return AjaxResult.error("确认人不能为同一人,请重新选择!");
- }
- tPssrFileService.updateFileRelevance(tPssrSafetyBreath.getFileIds(), "aqss-bh", tPssrSafetyBreath.getId(), tPssrSafetyBreath.getSubId());
- return toAjax(tPssrSafetyBreathService.updateTPssrSafetyBreath(tPssrSafetyBreath));
- }
- /**
- * 修改安全设施-呼吸阀
- */
- @PreAuthorize("@ss.hasPermi('pssr:safetyBreath:edit')")
- @Log(title = "安全设施-呼吸阀", businessType = BusinessType.UPDATE)
- @PutMapping("/editBatch")
- public AjaxResult editb(@RequestBody TPssrSafetyBreath tPssrSafetyBreath) {
- if (tPssrSafetyBreath.getConfirmer1().equals(tPssrSafetyBreath.getConfirmer2())){
- return AjaxResult.error("确认人不能为同一人,请重新选择!");
- }
- return toAjax(tPssrSafetyBreathMapper.updateTPssrSafetyBreathByIds(tPssrSafetyBreath));
- }
- /**
- * 删除安全设施-呼吸阀
- */
- @PreAuthorize("@ss.hasPermi('pssr:safetyBreath:remove')")
- @Log(title = "安全设施-呼吸阀", businessType = BusinessType.DELETE)
- @DeleteMapping("/{ids}")
- public AjaxResult remove(@PathVariable Long[] ids) {
- return toAjax(tPssrSafetyBreathService.deleteTPssrSafetyBreathByIds(ids));
- }
- }
|