| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.ExcelImportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import cn.afterturn.easypoi.excel.entity.ImportParams; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.WebUtils; |
| | | import com.ruoyi.system.export.CleanToiletMaintenanceExport; |
| | | import com.ruoyi.system.export.CleanToiletMaintenanceExportNoImg; |
| | | import com.ruoyi.system.model.CleanToiletMaintenance; |
| | | import com.ruoyi.system.model.CleanToiletMaintenance; |
| | | import com.ruoyi.system.query.CleanSludgeListQuery; |
| | | import com.ruoyi.system.service.CleanToiletMaintenanceService; |
| | | import com.ruoyi.system.service.CleanToiletMaintenanceService; |
| | | import com.ruoyi.system.utils.ExcelStyleUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDate; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @since 2025-10-17 |
| | | */ |
| | | @RestController |
| | | @Api(tags = "厕所维保记录") |
| | | @RequestMapping("/clean-toilet-maintenance") |
| | | @Slf4j |
| | | public class CleanToiletMaintenanceController { |
| | | @Resource |
| | | private CleanToiletMaintenanceService cleanToiletMaintenanceService; |
| | | |
| | | @ApiOperation(value = "厕所维保记录分页列表") |
| | | @PostMapping(value = "/pageList") |
| | | public R<PageInfo<CleanToiletMaintenance>> pageList(@RequestBody CleanSludgeListQuery query) { |
| | | PageInfo<CleanToiletMaintenance> cleanToiletSanitizationPageInfo = cleanToiletMaintenanceService.pageList(query); |
| | | return R.ok(cleanToiletSanitizationPageInfo); |
| | | } |
| | | |
| | | @Log(title = "厕所维保记录导入", businessType = BusinessType.INSERT) |
| | | @ApiOperation(value = "厕所维保记录导入") |
| | | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) |
| | | @PostMapping("/import") |
| | | public R<String> importCleaner(@RequestPart("file") MultipartFile file) { |
| | | ImportParams params = new ImportParams(); |
| | | params.setHeadRows(1); //表头行数 |
| | | InputStream inputStream = null; |
| | | List<CleanToiletMaintenanceExport> locationExcelList; |
| | | try { |
| | | inputStream = file.getInputStream(); |
| | | locationExcelList = ExcelImportUtil.importExcel(inputStream, |
| | | CleanToiletMaintenanceExport.class, params); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("厕所维保记录导入失败:{}", e.getMessage()); |
| | | throw new ServiceException("厕所维保记录导入失败!"); |
| | | } finally { |
| | | try { |
| | | inputStream.close(); |
| | | } catch (IOException e) { |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | | if (CollectionUtils.isEmpty(locationExcelList)) { |
| | | throw new ServiceException("厕所维保记录数据为空!"); |
| | | } |
| | | List<CleanToiletMaintenance> cleanToiletSanitizations = new ArrayList<>(); |
| | | for (CleanToiletMaintenanceExport locationExcel : locationExcelList) { |
| | | CleanToiletMaintenance cleanToiletSanitization = new CleanToiletMaintenance(); |
| | | String recordDate = locationExcel.getRecordDate(); |
| | | LocalDate localDate = LocalDate.parse(recordDate); |
| | | cleanToiletSanitization.setRecordDate(localDate); |
| | | cleanToiletSanitization.setMaintainer(locationExcel.getMaintainer()); |
| | | cleanToiletSanitization.setMaintenanceTime(locationExcel.getMaintenanceTime()); |
| | | cleanToiletSanitization.setMaintenanceImages(locationExcel.getMaintenanceImages()); |
| | | cleanToiletSanitization.setRemarks(locationExcel.getRemarks()); |
| | | cleanToiletSanitizations.add(cleanToiletSanitization); |
| | | } |
| | | cleanToiletMaintenanceService.saveBatch(cleanToiletSanitizations); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation(value = "厕所维保记录导出") |
| | | @Log(title = "厕所维保记录导出", businessType = BusinessType.OTHER) |
| | | @PostMapping(value = "/export") |
| | | public void export(@RequestBody CleanSludgeListQuery query) { |
| | | List<CleanToiletMaintenance> list = cleanToiletMaintenanceService.lambdaQuery() |
| | | .like(StringUtils.hasLength(query.getRecordDate()), CleanToiletMaintenance::getRecordDate, query.getRecordDate()) |
| | | .list(); |
| | | |
| | | List<CleanToiletMaintenanceExport> cleanToiletSanitizationExports = new ArrayList<>(); |
| | | |
| | | int i = 1; |
| | | for (CleanToiletMaintenance cleanToiletSanitization : list) { |
| | | CleanToiletMaintenanceExport cleanToiletSanitizationExport = new CleanToiletMaintenanceExport(); |
| | | cleanToiletSanitizationExport.setNumber(i); |
| | | LocalDate recordDate = cleanToiletSanitization.getRecordDate(); |
| | | cleanToiletSanitizationExport.setRecordDate(recordDate.toString()); |
| | | cleanToiletSanitizationExport.setMaintainer(cleanToiletSanitization.getMaintainer()); |
| | | cleanToiletSanitizationExport.setMaintenanceTime(cleanToiletSanitization.getMaintenanceTime()); |
| | | |
| | | // 处理图片URL,将逗号分隔的URL转换为EasyPOI需要的格式 |
| | | String imageUrls = cleanToiletSanitization.getMaintenanceImages(); |
| | | if (StringUtils.hasLength(imageUrls)) { |
| | | // 将逗号分隔的URL转换为分号分隔(EasyPOI支持多图片用分号分隔) |
| | | cleanToiletSanitizationExport.setMaintenanceImages(imageUrls.replace(",", ";")); |
| | | } |
| | | |
| | | cleanToiletSanitizationExport.setRemarks(cleanToiletSanitization.getRemarks()); |
| | | cleanToiletSanitizationExports.add(cleanToiletSanitizationExport); |
| | | i++; |
| | | } |
| | | |
| | | // 设置导出参数,支持图片 |
| | | ExportParams exportParams = new ExportParams(); |
| | | exportParams.setStyle(ExcelStyleUtil.class); |
| | | |
| | | // 获取excel模板 |
| | | Workbook workbook = ExcelExportUtil.exportExcel(exportParams, CleanToiletMaintenanceExport.class, cleanToiletSanitizationExports); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | ServletOutputStream outputStream = null; |
| | | try { |
| | | String fileName = URLEncoder.encode("厕所维保记录.xls", "utf-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName); |
| | | outputStream = response.getOutputStream(); |
| | | workbook.write(outputStream); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | if (outputStream != null) { |
| | | outputStream.close(); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "厕所维保记录导入模板下载") |
| | | @GetMapping("/download") |
| | | public void download() { |
| | | List<CleanToiletMaintenanceExportNoImg> locationImportExcels = new ArrayList<>(); |
| | | CleanToiletMaintenanceExportNoImg tLocationImportExcel = new CleanToiletMaintenanceExportNoImg(); |
| | | locationImportExcels.add(tLocationImportExcel); |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), CleanToiletMaintenanceExportNoImg.class, locationImportExcels); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | ServletOutputStream outputStream = null; |
| | | try { |
| | | String fileName = URLEncoder.encode("厕所维保记录导入模板.xls", "utf-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName); |
| | | response.setHeader("content-Type", "application/vnd.ms-excel"); |
| | | response.setHeader("Pragma", "no-cache"); |
| | | response.setHeader("Cache-Control", "no-cache"); |
| | | outputStream = response.getOutputStream(); |
| | | workbook.write(outputStream); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | System.out.println("厕所维保记录导入模板下载失败!"); |
| | | } finally { |
| | | try { |
| | | outputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "添加") |
| | | @Transactional |
| | | @Log(title = "厕所维保记录-添加", businessType = BusinessType.INSERT) |
| | | @PostMapping(value = "/add") |
| | | public R<Boolean> save(@RequestBody CleanToiletMaintenance entity) { |
| | | cleanToiletMaintenanceService.save(entity); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation(value = "修改") |
| | | @Transactional |
| | | @Log(title = "厕所维保记录-修改", businessType = BusinessType.UPDATE) |
| | | @PostMapping(value = "/edit") |
| | | public R<Boolean> edit(@RequestBody CleanToiletMaintenance entity) { |
| | | cleanToiletMaintenanceService.updateById(entity); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation(value = "详情") |
| | | @GetMapping(value = "/detail") |
| | | public R<CleanToiletMaintenance> detail(String id) { |
| | | return R.ok(cleanToiletMaintenanceService.getById(id)); |
| | | } |
| | | |
| | | @Log(title = "厕所维保记录-删除", businessType = BusinessType.DELETE) |
| | | @Transactional |
| | | @ApiOperation(value = "厕所维保记录-删除") |
| | | @DeleteMapping(value = "/delete") |
| | | public R delete(@RequestParam String ids) { |
| | | cleanToiletMaintenanceService.removeBatchByIds(Arrays.asList(ids.split(","))); |
| | | return R.ok(); |
| | | } |
| | | } |