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

diff --git a/cnas-personnel/src/main/java/com/ruoyi/personnel/service/impl/PersonTrainingServiceImpl.java b/cnas-personnel/src/main/java/com/ruoyi/personnel/service/impl/PersonTrainingServiceImpl.java
new file mode 100644
index 0000000..6a4bb62
--- /dev/null
+++ b/cnas-personnel/src/main/java/com/ruoyi/personnel/service/impl/PersonTrainingServiceImpl.java
@@ -0,0 +1,438 @@
+package com.ruoyi.personnel.service.impl;
+
+import com.alibaba.excel.EasyExcel;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+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.common.constant.MenuJumpPathConstants;
+import com.ruoyi.common.core.domain.entity.InformationNotification;
+import com.ruoyi.common.core.domain.entity.User;
+import com.ruoyi.common.utils.DateImageUtil;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.WxCpUtils;
+import com.ruoyi.framework.exception.ErrorException;
+import com.ruoyi.inspect.util.HackLoopTableRenderPolicy;
+import com.ruoyi.personnel.dto.PersonTrainingDetailedDto;
+import com.ruoyi.personnel.dto.PersonTrainingDto;
+import com.ruoyi.personnel.dto.PersonTrainingRecordDto;
+import com.ruoyi.personnel.dto.TrainingRecordExportDto;
+import com.ruoyi.personnel.excel.PersonTrainingDetailedListener;
+import com.ruoyi.personnel.excel.PersonTrainingDetailedUpload;
+import com.ruoyi.personnel.mapper.PersonTrainingDetailedFileMapper;
+import com.ruoyi.personnel.mapper.PersonTrainingDetailedMapper;
+import com.ruoyi.personnel.mapper.PersonTrainingMapper;
+import com.ruoyi.personnel.mapper.PersonTrainingRecordMapper;
+import com.ruoyi.personnel.pojo.PersonTraining;
+import com.ruoyi.personnel.pojo.PersonTrainingDetailed;
+import com.ruoyi.personnel.pojo.PersonTrainingDetailedFile;
+import com.ruoyi.personnel.service.PersonTrainingDetailedService;
+import com.ruoyi.personnel.service.PersonTrainingService;
+import com.ruoyi.system.mapper.UserMapper;
+import com.ruoyi.system.service.InformationNotificationService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URLEncoder;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * <p>
+ * 鍩硅璁″垝 鏈嶅姟瀹炵幇绫�
+ * </p>
+ *
+ * @author
+ * @since 2024-10-11 01:11:49
+ */
+@Service
+@Transactional(rollbackFor = Exception.class)
+public class PersonTrainingServiceImpl extends ServiceImpl<PersonTrainingMapper, PersonTraining> implements PersonTrainingService {
+
+    @Autowired
+    private PersonTrainingDetailedService personTrainingDetailedService;
+    @Autowired
+    private UserMapper userMapper;
+    @Autowired
+    private PersonTrainingDetailedMapper personTrainingDetailedMapper;
+    @Autowired
+    private PersonTrainingRecordMapper personTrainingRecordMapper;
+    @Autowired
+    private PersonTrainingDetailedFileMapper personTrainingDetailedFileMapper;
+    @Resource
+    private InformationNotificationService informationNotificationService;
+    @Resource
+    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
+    @Value("${file.path}")
+    private String imgUrl;
+
+    @Value("${wordUrl}")
+    private String wordUrl;
+
+    @Override
+    public IPage<PersonTrainingDto> personTrainingSelect(Page page, String compilerName, String departmentId) {
+
+        return baseMapper.personTrainingSelect(page, compilerName, departmentId);
+    }
+
+    @Override
+    public void personTrainingImport(MultipartFile file, PersonTraining training) {
+
+        Integer userId = SecurityUtils.getUserId().intValue();
+        // 骞村害璁″垝鐖剁骇鏂板鏁版嵁
+        PersonTraining personSupervisePlan = new PersonTraining();
+        String fileName = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf("."));
+        personSupervisePlan.setFileName(fileName);
+        personSupervisePlan.setPlanYear(training.getPlanYear());
+        personSupervisePlan.setCompilerId(userId);
+        personSupervisePlan.setReviewerId(training.getReviewerId());
+        personSupervisePlan.setCompilationDate(LocalDateTime.now());
+        baseMapper.insert(personSupervisePlan);
+        User user = userMapper.selectById(userId);
+        // 娑堟伅鍙戦��
+        InformationNotification info = new InformationNotification();
+        // 鍙戦�佷汉
+        info.setCreateUser(user.getName());
+        info.setMessageType("6");
+        info.setTheme("CNAS鍩硅璁″垝瀹℃牳閫氱煡");
+        info.setContent("鎮ㄦ湁涓�鏉″煿璁鍒掑緟瀹℃牳");
+        info.setSenderId(userId);
+        // 鎺ユ敹浜�
+        info.setConsigneeId(training.getApproverId());
+        info.setJumpPath(MenuJumpPathConstants.PERSONNEL);
+        informationNotificationService.addInformationNotification(info);
+
+        // 鍙戦�佷紒涓氬井淇¢�氱煡
+        threadPoolTaskExecutor.execute(() -> {
+            // 鏌ヨ鎺ユ敹浜�
+            User personnel = userMapper.selectById(training.getApproverId());
+
+            String message = "";
+            message += "CNAS鍩硅璁″垝瀹℃牳閫氱煡";
+            message += "\n璇峰幓璧勬簮绠$悊-浜哄憳-鍩硅璁″垝濉啓";
+            message += "\n" + fileName + "鐨勫煿璁鍒掑緟瀹℃牳";
+            //鍙戦�佷紒涓氬井淇℃秷鎭�氱煡
+            try {
+                WxCpUtils.inform(personnel.getAccount(), message, null);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        });
+
+        // 骞村害璁″垝璇︽儏 鏂板
+        try {
+            PersonTrainingDetailedListener personSupervisePlanDetailsListener = new PersonTrainingDetailedListener(personTrainingDetailedService);
+            personSupervisePlanDetailsListener.setPlanId(personSupervisePlan.getId());
+            EasyExcel.read(file.getInputStream(), PersonTrainingDetailedUpload.class, personSupervisePlanDetailsListener).sheet().doRead();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public void personTrainingDelete(Integer id) {
+        personTrainingDetailedService.remove(Wrappers.<PersonTrainingDetailed>lambdaQuery()
+                .eq(PersonTrainingDetailed::getPlanId, id));
+        baseMapper.deleteById(id);
+    }
+
+    @Override
+    public void reviewAnnualPersonnelTraining(PersonTraining training) {
+        PersonTraining personTraining = new PersonTraining();
+        personTraining.setId(training.getId());
+        personTraining.setApproverId(training.getApproverId());// 娣诲姞鎵瑰噯浜�
+        personTraining.setAuditDate(LocalDateTime.now());
+        personTraining.setAuditRemarks(training.getAuditRemarks());
+        personTraining.setReviewerStatus(training.getReviewerStatus());
+
+        PersonTraining old = baseMapper.selectById(training.getId());
+
+        // 娑堟伅鍙戦��
+        Integer userId = SecurityUtils.getUserId().intValue();
+        User user = userMapper.selectById(userId);
+        InformationNotification info = new InformationNotification();
+        // 鍙戦�佷汉
+        info.setCreateUser(user.getName());
+        info.setMessageType("6");
+        info.setTheme("CNAS鍩硅璁″垝瀹℃牳閫氱煡");
+        info.setContent("鎮ㄦ湁涓�鏉″煿璁鍒掑緟鎵瑰噯");
+        info.setSenderId(userId);
+        // 鎺ユ敹浜�
+        info.setConsigneeId(training.getApproverId());
+        info.setJumpPath(MenuJumpPathConstants.PERSONNEL);
+        informationNotificationService.addInformationNotification(info);
+
+        // 鍙戦�佷紒涓氬井淇¢�氱煡
+        threadPoolTaskExecutor.execute(() -> {
+            // 鏌ヨ鎺ユ敹浜�
+            User personnel = userMapper.selectById(training.getApproverId());
+
+            String message = "";
+            message += "CNAS鍩硅璁″垝鎵瑰噯閫氱煡";
+            message += "\n璇峰幓璧勬簮绠$悊-浜哄憳-鍩硅璁″垝濉啓";
+            message += "\n" + old.getFileName() + "鐨勫煿璁鍒掑緟鎵瑰噯";
+            //鍙戦�佷紒涓氬井淇℃秷鎭�氱煡
+            try {
+                WxCpUtils.inform(personnel.getAccount(), message, null);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        });
+
+        baseMapper.updateById(personTraining);
+    }
+
+    @Override
+    public void approveAnnualPersonnelTraining(PersonTraining training) {
+        LambdaUpdateWrapper<PersonTraining> wrapper = Wrappers.<PersonTraining>lambdaUpdate()
+                .eq(PersonTraining::getId, training.getId())
+                .set(PersonTraining::getApprovalDate, LocalDateTime.now())
+                .set(PersonTraining::getApprovalRemarks, training.getApprovalRemarks())
+                .set(PersonTraining::getApprovalStatus, training.getApprovalStatus());
+        baseMapper.update(new PersonTraining(), wrapper);
+    }
+
+    /**
+     * 瀵煎嚭浜哄憳鍩硅璁″垝
+     * @param id
+     * @param response
+     */
+    @Override
+    public void exportPersonTraining(Integer id, HttpServletResponse response) {
+
+        // 鏌ヨ璇︽儏
+        PersonTraining personTraining = baseMapper.selectById(id);
+
+        //鑾峰彇鎻愪氦浜虹殑绛惧悕鍦板潃
+        String writeUrl = userMapper.selectById(personTraining.getCompilerId()).getSignatureUrl();
+        if (ObjectUtils.isEmpty(writeUrl) || writeUrl.equals("")) {
+            throw new ErrorException("鎵句笉鍒版楠屼汉鐨勭鍚�");
+        }
+
+        //鑾峰彇澶嶆牳浜虹殑绛惧悕鍦板潃
+        String examineUrl = null;
+        if (personTraining.getReviewerId() != null) {
+            examineUrl = userMapper.selectById(personTraining.getReviewerId()).getSignatureUrl();
+            if (StringUtils.isBlank(examineUrl)) {
+                throw new ErrorException("鎵句笉鍒板鏍镐汉鐨勭鍚�");
+            }
+        }
+
+        //鑾峰彇鎵瑰噯浜虹殑绛惧悕鍦板潃
+        String ratifyUrl = null;
+        if (personTraining.getApproverId() != null) {
+            ratifyUrl = userMapper.selectById(personTraining.getApproverId()).getSignatureUrl();
+            if (StringUtils.isBlank(ratifyUrl)) {
+                throw new ErrorException("鎵句笉鍒板鏍镐汉鐨勭鍚�");
+            }
+        }
+
+        // 鏌ヨ璇︽儏
+        List<PersonTrainingDetailedDto> detailedDtos = personTrainingDetailedMapper.selectTrainingList(id);
+
+        int index = 1;
+        for (PersonTrainingDetailedDto detailedDto : detailedDtos) {
+            detailedDto.setTrainingDateString(detailedDto.getTrainingDate());
+            detailedDto.setIndex(index);
+            index++;
+        }
+
+        // 鑾峰彇璺緞
+        InputStream inputStream = this.getClass().getResourceAsStream("/static/person-training.docx");
+        String finalExamineUrl = examineUrl;
+        String finalRatifyUrl = ratifyUrl;
+        Configure configure = Configure.builder()
+                .bind("trainingDetailedList", new HackLoopTableRenderPolicy())
+                .build();
+        XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render(
+                new HashMap<String, Object>() {{
+                    put("year", personTraining.getPlanYear());
+                    put("trainingDetailedList", detailedDtos);
+                    put("writeUrl", StringUtils.isNotBlank(writeUrl) ? Pictures.ofLocal(imgUrl + "/" + writeUrl).create() : null);
+                    put("examineUrl", StringUtils.isNotBlank(finalExamineUrl) ? Pictures.ofLocal(imgUrl + "/" + finalExamineUrl).create() : null);
+                    put("ratifyUrl", StringUtils.isNotBlank(finalRatifyUrl) ? Pictures.ofLocal(imgUrl + "/" + finalRatifyUrl).create() : null);
+                    put("writeDateUrl", personTraining.getCompilationDate() != null ?
+                            Pictures.ofStream(DateImageUtil.createDateImage(personTraining.getCompilationDate())).create() : null);
+                    put("examineDateUrl", personTraining.getAuditDate() != null ?
+                            Pictures.ofStream(DateImageUtil.createDateImage(personTraining.getAuditDate())).create() : null);
+                    put("ratifyDateUrl", personTraining.getApprovalDate() != null ?
+                            Pictures.ofStream(DateImageUtil.createDateImage(personTraining.getApprovalDate())).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("瀵煎嚭澶辫触");
+        }
+
+    }
+
+    /**
+     * 瀵煎嚭浜哄憳鍩硅涓庤�冩牳璁板綍
+     * @param id
+     * @param response
+     */
+    @Override
+    public void exportPersonTrainingRecord(Integer id, HttpServletResponse response) {
+        // 鏌ヨ浜哄憳鍩硅鏄庣粏
+        PersonTrainingDetailedDto detailedDto = personTrainingDetailedMapper.selectTrainingDetail(id);
+
+        // 鐢熸垚鍩硅鑰佸笀绛惧悕
+        detailedDto.setTrainingLecturerRender(StringUtils.isNotBlank(detailedDto.getTrainingLecturerSignatureUrl())
+                    ? Pictures.ofLocal(imgUrl + "/" + detailedDto.getTrainingLecturerSignatureUrl()).create() : null);
+
+        // 鏌ヨ鍩硅鐨勪汉鍛�
+        List<PersonTrainingRecordDto> recordDtos = personTrainingRecordMapper.selectListByTrainingDetailedId(id);
+
+        List<TrainingRecordExportDto> exportDtoList = new ArrayList<>();
+        TrainingRecordExportDto exportDto = new TrainingRecordExportDto();
+
+        int count = 0;
+        for (PersonTrainingRecordDto recordDto : recordDtos) {
+            switch (count) {
+                case 0:
+                    exportDto.setUserNameRender1(StringUtils.isNotBlank(recordDto.getSignatureUrl())
+                            ? Pictures.ofLocal(imgUrl + "/" + recordDto.getSignatureUrl()).create() : null);
+                    exportDto.setDepartment1(recordDto.getDepartment());
+                    exportDto.setExaminationResults1(recordDto.getExaminationResults());
+                    count ++;
+                    break;
+                case 1:
+                    exportDto.setUserNameRender2(StringUtils.isNotBlank(recordDto.getSignatureUrl())
+                            ? Pictures.ofLocal(imgUrl + "/" + recordDto.getSignatureUrl()).create() : null);
+                    exportDto.setDepartment2(recordDto.getDepartment());
+                    exportDto.setExaminationResults2(recordDto.getExaminationResults());
+                    exportDtoList.add(exportDto);
+                    exportDto = new TrainingRecordExportDto();
+                    count = 0;
+                    break;
+            }
+        }
+        exportDtoList.add(exportDto);
+
+        // 璐ㄩ噺璐熻矗浜�
+        String assessmentUserUrl = null;
+        if (detailedDto.getAssessmentUserId() != null) {
+            assessmentUserUrl = userMapper.selectById(detailedDto.getAssessmentUserId()).getSignatureUrl();
+            if (StringUtils.isBlank(assessmentUserUrl)) {
+                throw new ErrorException("鎵句笉鍒拌瘎浠蜂汉鐨勭鍚�");
+            }
+        }
+
+
+        // 鑾峰彇璺緞
+        InputStream inputStream = this.getClass().getResourceAsStream("/static/person-training-record.docx");
+        Configure configure = Configure.builder()
+                .bind("trainingRecordsList", new HackLoopTableRenderPolicy())
+                .build();
+        String finalAssessmentUserUrl = assessmentUserUrl;
+        XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render(
+                new HashMap<String, Object>() {{
+                    put("trainingDetail", detailedDto);
+                    put("trainingRecordsList", exportDtoList);
+                    put("assessmentUserUrl", StringUtils.isNotBlank(finalAssessmentUserUrl) ? Pictures.ofLocal(imgUrl + "/" + finalAssessmentUserUrl).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("瀵煎嚭澶辫触");
+        }
+
+
+    }
+
+    /**
+     * 浜哄憳鍩硅璇︽儏闄勪欢鏂板
+     * @param trainingDetailedId
+     * @param file
+     * @return
+     */
+    @Override
+    public boolean uploadTrainingDetailedFile(Integer trainingDetailedId, MultipartFile file) {
+        if (trainingDetailedId == null) {
+            throw new ErrorException("缂哄皯楠屾敹id");
+        }
+
+        String urlString;
+        String pathName;
+        String path;
+        String filename = file.getOriginalFilename();
+        String contentType = file.getContentType();
+        PersonTrainingDetailedFile detailedFile = new PersonTrainingDetailedFile();
+        detailedFile.setTrainingDetailedId(trainingDetailedId);
+        detailedFile.setFileName(filename);
+        if (contentType != null && contentType.startsWith("image/")) {
+            // 鏄浘鐗�
+            path = imgUrl;
+            detailedFile.setType(1);
+        } else {
+            // 鏄枃浠�
+            path = wordUrl;
+            detailedFile.setType(2);
+        }
+        try {
+            File realpath = new File(path);
+            if (!realpath.exists()) {
+                realpath.mkdirs();
+            }
+            pathName = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmmss")) + "_" + file.getOriginalFilename();
+            urlString = realpath + "/" + pathName;
+            file.transferTo(new File(urlString));
+            detailedFile.setFileUrl(pathName);
+            personTrainingDetailedFileMapper.insert(detailedFile);
+            return true;
+        } catch (Exception e) {
+            e.printStackTrace();
+            System.err.println("闄勪欢涓婁紶閿欒");
+            return false;
+        }
+    }
+
+    /**
+     * 鏌ヨ浠婂勾浜哄憳鍩硅淇℃伅
+     * @return
+     */
+    @Override
+    public List<PersonTrainingDetailed> getThisYearTrainingDetailed() {
+        return personTrainingDetailedMapper.getThisYearTrainingDetailed();
+    }
+}

--
Gitblit v1.9.3