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-device/src/main/java/com/ruoyi/device/service/impl/DeviceExternalApplyServiceImpl.java |  162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 162 insertions(+), 0 deletions(-)

diff --git a/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceExternalApplyServiceImpl.java b/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceExternalApplyServiceImpl.java
new file mode 100644
index 0000000..901948b
--- /dev/null
+++ b/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceExternalApplyServiceImpl.java
@@ -0,0 +1,162 @@
+package com.ruoyi.device.service.impl;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+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.ruoyi.common.core.domain.entity.User;
+import com.ruoyi.common.utils.QueryWrappers;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.device.mapper.DeviceExternalApplyMapper;
+import com.ruoyi.device.pojo.DeviceExternalApply;
+import com.ruoyi.device.service.DeviceExternalApplyService;
+import com.ruoyi.inspect.util.UserUtils;
+import com.ruoyi.system.mapper.UserMapper;
+import org.springframework.beans.BeanUtils;
+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.time.LocalDate;
+import java.util.HashMap;
+
+/**
+ * <p>
+ * 鍒╃敤澶栭儴璁惧鐢宠琛� 鏈嶅姟瀹炵幇绫�
+ * </p>
+ *
+ * @author 姹熻嫃榈烽洀缃戠粶绉戞妧鏈夐檺鍏徃
+ * @since 2024-12-17 10:28:43
+ */
+@Service
+public class DeviceExternalApplyServiceImpl extends ServiceImpl<DeviceExternalApplyMapper, DeviceExternalApply> implements DeviceExternalApplyService {
+
+    @Resource
+    private UserMapper userMapper;
+
+    /**
+     * 鍒╃敤澶栭儴璁惧鐢宠鍒楄〃
+     * @param page
+     * @param deviceExternalApply
+     * @return
+     */
+    @Override
+    public IPage<DeviceExternalApply> pageDeviceExternalApply(Page page, DeviceExternalApply deviceExternalApply) {
+        return baseMapper.pageDeviceExternalApply(page, QueryWrappers.queryWrappers(deviceExternalApply));
+    }
+
+    /**
+     * 鏂板鍒╃敤澶栭儴璁惧鐢宠
+     * @param deviceExternalApply
+     * @return
+     */
+    @Override
+    public boolean addDeviceExternalApply(DeviceExternalApply deviceExternalApply) {
+        DeviceExternalApply apply = new DeviceExternalApply();
+        // 褰撳墠鐧诲綍鐢ㄦ埛淇℃伅鍜岄儴闂�
+        User user = userMapper.selectById(SecurityUtils.getUserId().intValue());
+        switch (deviceExternalApply.getFlowType()) {
+            case 0:
+                BeanUtils.copyProperties(deviceExternalApply, apply);
+                // 鐢宠
+                apply.setUseReason(deviceExternalApply.getUseReason());
+                apply.setApplicantUserId(user.getId());
+                apply.setApplicantUser(user.getName());
+                apply.setApplicantDate(LocalDate.now());
+
+                // 澶勭悊浜轰俊鎭�
+                User departmentHeadUser = userMapper.selectById(deviceExternalApply.getDepartmentHeadUserId());
+                apply.setApplicantUserId(departmentHeadUser.getId());
+                apply.setApplicantUser(departmentHeadUser.getName());
+
+                baseMapper.insert(apply);
+                break;
+            case 1:
+                apply.setExternalApplyId(deviceExternalApply.getExternalApplyId());
+                // 鐢宠閮ㄩ棬璐熻矗浜烘剰瑙�
+                apply.setDepartmentHeadOpinion(deviceExternalApply.getDepartmentHeadOpinion());
+                apply.setDepartmentHeadDate(LocalDate.now());
+
+                // 璁¢噺瀹や俊鎭�
+                User meteringRoomUser = userMapper.selectById(deviceExternalApply.getMeteringRoomUserId());
+                apply.setMeteringRoomUserId(meteringRoomUser.getId());
+                apply.setMeteringRoomUser(meteringRoomUser.getName());
+
+                baseMapper.updateById(apply);
+                break;
+            case 2:
+                apply.setExternalApplyId(deviceExternalApply.getExternalApplyId());
+                // 璁¢噺瀹ゆ剰瑙�
+                apply.setMeteringRoomOpinion(deviceExternalApply.getMeteringRoomOpinion());
+                apply.setMeteringRoomDate(LocalDate.now());
+
+                // 鎵瑰噯浜轰俊鎭�
+                User approverUser = userMapper.selectById(deviceExternalApply.getApproverUserId());
+                apply.setApproverUserId(approverUser.getId());
+                apply.setApproverUser(approverUser.getName());
+
+                baseMapper.updateById(apply);
+                break;
+            case 3:
+                apply.setExternalApplyId(deviceExternalApply.getExternalApplyId());
+                //鎵瑰噯浜�
+                apply.setApproverOpinion(deviceExternalApply.getApproverOpinion());
+                apply.setApproverDate(LocalDate.now());
+
+                apply.setIsFinish(1);
+                baseMapper.updateById(apply);
+                break;
+        }
+
+        return true;
+    }
+
+    /**
+     * 瀵煎嚭鍒╃敤澶栭儴璁惧鐢宠
+     *
+     * @param externalApplyId 澶栭儴璁惧鐢宠id
+     * @param response
+     */
+    @Override
+    public void exportDeviceExternalApply(Integer externalApplyId, HttpServletResponse response) {
+        // 鏌ヨ澶栭儴璁惧鐢宠
+        DeviceExternalApply deviceAccidentReport = baseMapper.selectDeviceExternalById(externalApplyId);
+
+        // 鑾峰彇璺緞
+        InputStream inputStream = this.getClass().getResourceAsStream("/static/word/device-external-apply.docx");
+        Configure configure = Configure.builder()
+                .build();
+        XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render(
+                new HashMap<String, Object>() {{
+                    put("deviceAccidentReport", deviceAccidentReport);
+                    // 鐢宠浜虹鍚�
+                    put("applicantUserUrl", UserUtils.getFinalUserSignatureUrl(deviceAccidentReport.getApplicantUserId()));
+                    // 閮ㄩ棬璐熻矗浜虹鍚�
+                    put("departmentHeadUserUrl", UserUtils.getFinalUserSignatureUrl(deviceAccidentReport.getDepartmentHeadUserId()));
+                    // 璁¢噺瀹や汉绛惧悕
+                    put("meteringRoomUserUrl", UserUtils.getFinalUserSignatureUrl(deviceAccidentReport.getMeteringRoomUserId()));
+                    // 鎵瑰噯浜虹鍚�
+                    put("approverUserUrl", UserUtils.getFinalUserSignatureUrl(deviceAccidentReport.getApproverUserId()));
+                }});
+
+        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