From 4f3a98f19143865cdc1de4791e8a95d96bd40c65 Mon Sep 17 00:00:00 2001 From: maven <2163098428@qq.com> Date: 星期五, 01 八月 2025 13:27:59 +0800 Subject: [PATCH] yys 密码已重置 --- cnas-require/src/main/java/com/ruoyi/require/service/impl/FePowerStableServiceImpl.java | 124 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 124 insertions(+), 0 deletions(-) diff --git a/cnas-require/src/main/java/com/ruoyi/require/service/impl/FePowerStableServiceImpl.java b/cnas-require/src/main/java/com/ruoyi/require/service/impl/FePowerStableServiceImpl.java new file mode 100644 index 0000000..07ba8f3 --- /dev/null +++ b/cnas-require/src/main/java/com/ruoyi/require/service/impl/FePowerStableServiceImpl.java @@ -0,0 +1,124 @@ +package com.ruoyi.require.service.impl; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.deepoove.poi.XWPFTemplate; +import com.deepoove.poi.config.Configure; +import com.deepoove.poi.data.Pictures; +import com.ruoyi.framework.exception.ErrorException; +import com.ruoyi.inspect.util.HackLoopTableRenderPolicy; +import com.ruoyi.require.dto.FePowerStableDto; +import com.ruoyi.require.dto.FePowerStableExportDto; +import com.ruoyi.require.mapper.FeMeasuredQuantityMapper; +import com.ruoyi.require.mapper.FePowerStableMapper; +import com.ruoyi.require.pojo.FeMeasuredQuantity; +import com.ruoyi.require.pojo.FePowerStable; +import com.ruoyi.require.service.FePowerStableService; +import com.ruoyi.system.mapper.UserMapper; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URLEncoder; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * <p> + * 璁炬柦鍜岀幆澧冩潯浠�-璁炬柦鍜岀幆澧冩潯浠惰姹�-鐢垫簮绋冲畾鎬� 鏈嶅姟瀹炵幇绫� + * </p> + * + * @author + * @since 2024-11-07 04:16:52 + */ +@Service +public class FePowerStableServiceImpl extends ServiceImpl<FePowerStableMapper, FePowerStable> implements FePowerStableService { + + @Resource + private FeMeasuredQuantityMapper feMeasuredQuantityMapper; + @Resource + private UserMapper userMapper; + + @Value("${file.path}") + private String imgUrl; + + @Override + public IPage<FePowerStableDto> getLaboratoryFacilityPowerStablePage(Page page) { + return baseMapper.getLaboratoryFacilityPowerStablePage(page); + } + + @Override + public Map<String, Objects> getCalibrationDate(Integer deviceId) { + return baseMapper.getCalibrationDate(deviceId); + } + + /** + * 瀵煎嚭鐢垫簮绋冲畾鎬� + * @param powerStableId + * @param response + */ + @Override + public void exportFePowerStable(Integer powerStableId, HttpServletResponse response) { + FePowerStableExportDto powerStable = baseMapper.selectPowerStable(powerStableId); + + // 妫�娴嬩汉 + String testerUrl = null; + if (powerStable.getTesterId() != null) { + testerUrl = userMapper.selectById(powerStable.getTesterId()).getSignatureUrl(); + if (StringUtils.isBlank(testerUrl)) { + throw new ErrorException("鎵句笉鍒版娴嬩汉鐨勭鍚�"); + } + } + + // 鏍告煡浜� + String checkerUrl = null; + if (powerStable.getCheckerId() != null) { + checkerUrl = userMapper.selectById(powerStable.getCheckerId()).getSignatureUrl(); + if (StringUtils.isBlank(checkerUrl)) { + throw new ErrorException("鎵句笉鍒版牳鏌ヤ汉鐨勭鍚�"); + } + } + + // 鏌ヨ璇︽儏 + List<FeMeasuredQuantity> feMeasuredQuantities = feMeasuredQuantityMapper.selectList(Wrappers.<FeMeasuredQuantity>lambdaQuery() + .eq(FeMeasuredQuantity::getPowerStableId, powerStableId)); + + // 鑾峰彇璺緞 + InputStream inputStream = this.getClass().getResourceAsStream("/static/power-stable.docx"); + Configure configure = Configure.builder() + .bind("measuredQuantityList", new HackLoopTableRenderPolicy()) + .build(); + String finalTesterUrl = testerUrl; + String finalCheckerUrl = checkerUrl; + XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render( + new HashMap<String, Object>() {{ + put("stable", powerStable); + put("measuredQuantityList", feMeasuredQuantities); + put("testerUrl", StringUtils.isNotBlank(finalTesterUrl) ? Pictures.ofLocal(imgUrl + "/" + finalTesterUrl).create() : null); + put("checkerUrl", StringUtils.isNotBlank(finalCheckerUrl) ? Pictures.ofLocal(imgUrl + "/" + finalCheckerUrl).create() : null); + }}); + try { + response.setContentType("application/msword"); + String fileName = URLEncoder.encode( + "鐢垫簮绋冲畾鎬ф祴璇曞鍑�", "UTF-8"); + response.setHeader("Content-disposition", + "attachment;filename=" + fileName + ".docx"); + OutputStream os = response.getOutputStream(); + template.write(os); + os.flush(); + os.close(); + inputStream.close(); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("瀵煎嚭澶辫触"); + } + } +} -- Gitblit v1.9.3