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/DeviceMaintenancePlanServiceImpl.java | 292 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 292 insertions(+), 0 deletions(-) diff --git a/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceMaintenancePlanServiceImpl.java b/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceMaintenancePlanServiceImpl.java new file mode 100644 index 0000000..d4c7fcb --- /dev/null +++ b/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceMaintenancePlanServiceImpl.java @@ -0,0 +1,292 @@ +package com.ruoyi.device.service.impl; + +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +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.ruoyi.common.constant.MenuJumpPathConstants; +import com.ruoyi.common.core.domain.Result; +import com.ruoyi.common.core.domain.entity.InformationNotification; +import com.ruoyi.common.core.domain.entity.User; +import com.ruoyi.common.utils.QueryWrappers; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.WxCpUtils; +import com.ruoyi.device.dto.DeviceMaintenancePlanDetailsDto; +import com.ruoyi.device.dto.DeviceMaintenancePlanDto; +import com.ruoyi.device.mapper.DeviceMaintenancePlanDetailsMapper; +import com.ruoyi.device.mapper.DeviceMaintenancePlanMapper; +import com.ruoyi.device.pojo.DeviceMaintenancePlan; +import com.ruoyi.device.pojo.DeviceMaintenancePlanDetails; +import com.ruoyi.device.service.DeviceMaintenancePlanDetailsService; +import com.ruoyi.device.service.DeviceMaintenancePlanService; +import com.ruoyi.inspect.util.HackLoopTableRenderPolicy; +import com.ruoyi.inspect.util.UserUtils; +import com.ruoyi.system.mapper.UserMapper; +import com.ruoyi.system.service.InformationNotificationService; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.BeanUtils; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +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.LocalDateTime; +import java.util.HashMap; +import java.util.List; +import java.util.stream.Collectors; + +/** + * <p> + * 璁惧淇濆吇璁″垝琛� 鏈嶅姟瀹炵幇绫� + * </p> + * + * @author 姹熻嫃榈烽洀缃戠粶绉戞妧鏈夐檺鍏徃 + * @since 2024-12-16 06:10:52 + */ +@Service +public class DeviceMaintenancePlanServiceImpl extends ServiceImpl<DeviceMaintenancePlanMapper, DeviceMaintenancePlan> implements DeviceMaintenancePlanService { + + @Resource + private DeviceMaintenancePlanDetailsService deviceMaintenancePlanDetailsService; + @Resource + private DeviceMaintenancePlanDetailsMapper deviceMaintenancePlanDetailsMapper; + @Resource + private ThreadPoolTaskExecutor threadPoolTaskExecutor; + @Resource + private InformationNotificationService informationNotificationService; + @Resource + private UserMapper userMapper; + + /** + * 鍒嗛〉鏌ヨ璁惧淇濆吇璁″垝 + * + * @param page + * @return + */ + @Override + public Result<IPage<DeviceMaintenancePlan>> selectDeviceMaintenancePlanByPage(Page page, DeviceMaintenancePlanDto deviceMaintenancePlanDto) { + IPage<DeviceMaintenancePlan> iPage = baseMapper.selectDeviceParameterPage(page, QueryWrappers.queryWrappers(deviceMaintenancePlanDto)); + return Result.success(iPage); + } + + /** + * 鏂板璁惧淇濆吇璁″垝 + * + * @param deviceMaintenancePlanDto 璁惧淇濆吇璁″垝 + */ + @Override + public Result addMaintenancePlan(DeviceMaintenancePlanDto deviceMaintenancePlanDto) { + Integer userId = SecurityUtils.getUserId().intValue(); + User user = userMapper.selectById(userId); + deviceMaintenancePlanDto.setCompilerId(userId); + deviceMaintenancePlanDto.setCompiler(user.getName()); + deviceMaintenancePlanDto.setDatePreparation(LocalDateTime.now()); + + // 鏌ヨ瀹℃牳浜篿d + if (deviceMaintenancePlanDto.getAuditId() != null) { + User auditUser = userMapper.selectById(deviceMaintenancePlanDto.getAuditId()); + deviceMaintenancePlanDto.setAudit(auditUser.getName()); + } + this.saveOrUpdate(deviceMaintenancePlanDto); + + // 璇︽儏璧嬪�煎苟淇濆瓨 + List<DeviceMaintenancePlanDetailsDto> deviceMaintenancePlanDetails = deviceMaintenancePlanDto.getDeviceMaintenancePlanDetails(); + if (CollectionUtils.isNotEmpty(deviceMaintenancePlanDetails)) { // 璇︽儏涓嶄负绌� + List<DeviceMaintenancePlanDetails> collect = deviceMaintenancePlanDetails.stream().map(deviceMaintenancePlanDetail -> { // 閬嶅巻璇︽儏 + deviceMaintenancePlanDetail.setDeviceId(deviceMaintenancePlanDetail.getDeviceId()); // 璁惧ID + deviceMaintenancePlanDetail.setMaintenancePlanId(deviceMaintenancePlanDto.getMaintenancePlanId()); // 淇濆吇璁″垝ID + DeviceMaintenancePlanDetails planDetails = new DeviceMaintenancePlanDetails(); + BeanUtils.copyProperties(deviceMaintenancePlanDetail, planDetails); + return planDetails; + }).collect(Collectors.toList()); + deviceMaintenancePlanDetailsService.saveBatch(collect); + } + + return Result.success(); + } + + /** + * 淇敼璁惧淇濆吇璁″垝 + * @param deviceMaintenancePlanDto 璁惧淇濆吇璁″垝 + */ + @Override + public Result updateMaintenancePlan(DeviceMaintenancePlanDto deviceMaintenancePlanDto) { + // 鏌ヨ瀹℃牳浜篿d + if (deviceMaintenancePlanDto.getAuditId() != null) { + User auditUser = userMapper.selectById(deviceMaintenancePlanDto.getAuditId()); + deviceMaintenancePlanDto.setAudit(auditUser.getName()); + } + this.saveOrUpdate(deviceMaintenancePlanDto); + + // 鍒犻櫎鍘熸湰鐨勮鎯� + deviceMaintenancePlanDetailsService.remove(Wrappers.<DeviceMaintenancePlanDetails>lambdaQuery().eq(DeviceMaintenancePlanDetails::getMaintenancePlanId, deviceMaintenancePlanDto.getMaintenancePlanId())); + // 璇︽儏璧嬪�煎苟淇濆瓨 + List<DeviceMaintenancePlanDetailsDto> deviceMaintenancePlanDetails = deviceMaintenancePlanDto.getDeviceMaintenancePlanDetails(); + if (CollectionUtils.isNotEmpty(deviceMaintenancePlanDetails)) { // 璇︽儏涓嶄负绌� + List<DeviceMaintenancePlanDetails> collect = deviceMaintenancePlanDetails.stream().map(deviceMaintenancePlanDetail -> { // 閬嶅巻璇︽儏 + deviceMaintenancePlanDetail.setDeviceId(deviceMaintenancePlanDto.getDeviceId()); // 璁惧ID + deviceMaintenancePlanDetail.setMaintenancePlanId(deviceMaintenancePlanDto.getMaintenancePlanId()); // 淇濆吇璁″垝ID + DeviceMaintenancePlanDetails planDetails = new DeviceMaintenancePlanDetails(); + BeanUtils.copyProperties(deviceMaintenancePlanDetail, planDetails); + return planDetails; + }).collect(Collectors.toList()); + deviceMaintenancePlanDetailsService.saveBatch(collect); + } + return Result.success(); + } + + /** + * 鍒犻櫎璁惧淇濆吇璁″垝 + * + * @param deviceMaintenancePlanDto 璁惧淇濆吇璁″垝 + */ + @Override + public Result deleteMaintenancePlan(DeviceMaintenancePlanDto deviceMaintenancePlanDto) { + this.removeById(deviceMaintenancePlanDto); + deviceMaintenancePlanDetailsService.remove(Wrappers.<DeviceMaintenancePlanDetails>lambdaQuery().eq(DeviceMaintenancePlanDetails::getMaintenancePlanId, deviceMaintenancePlanDto.getMaintenancePlanId())); + return Result.success(); + } + + /** + * 瀵煎嚭璁惧淇濆吇璁″垝 + * + * @param maintenancePlanId 璁惧淇濆吇璁″垝id + * @param response 鍝嶅簲 + */ + @Override + public Result exportDeviceMaintenancePlanDto(Integer maintenancePlanId, HttpServletResponse response) { + // 鏌ヨ璁惧淇濆吇璁″垝 + DeviceMaintenancePlanDto deviceMaintenancePlan = baseMapper.selectMaintenancePlanById(maintenancePlanId); + + // 鏌ヨ璁惧淇濆吇璁″垝璇︽儏 + List<DeviceMaintenancePlanDetailsDto> deviceMaintenancePlanDetailsDtoList = deviceMaintenancePlanDetailsMapper.deviceInspectionRecordDetailsList(maintenancePlanId); + // 璁剧疆搴忓彿 + deviceMaintenancePlanDetailsDtoList.forEach(deviceInspectionRecordDetails -> { + deviceInspectionRecordDetails.setIndex(deviceMaintenancePlanDetailsDtoList.indexOf(deviceInspectionRecordDetails) + 1); + }); + + // 鑾峰彇璺緞 + InputStream inputStream = this.getClass().getResourceAsStream("/static/word/maintenance-plan.docx"); + Configure configure = Configure.builder() + .bind("deviceMaintenancePlanDetailsDtoList", new HackLoopTableRenderPolicy()) + .build(); + XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render( + new HashMap<String, Object>() {{ + put("deviceMaintenancePlan", deviceMaintenancePlan); + put("deviceMaintenancePlanDetailsDtoList", deviceMaintenancePlanDetailsDtoList); + // 缂栧埗浜虹鍚嶅湴鍧� + put("compilerUrl", UserUtils.getFinalUserSignatureUrl(deviceMaintenancePlan.getCompilerId())); + // 瀹℃牳浜虹鍚嶅湴鍧� + put("auditUrl", UserUtils.getFinalUserSignatureUrl(deviceMaintenancePlan.getAuditId())); + }}); + + 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("瀵煎嚭澶辫触"); + } + return Result.success(); + } + + /** + * 鏌ヨ璁惧淇濆吇璁″垝璇︽儏 + * + * @param maintenancePlanId 璁惧淇濆吇璁″垝id + */ + @Override + public Result<DeviceMaintenancePlanDto> getMaintenancePlanDetail(Integer maintenancePlanId) { + // 鏌ヨ璁惧淇濆吇璁″垝 + DeviceMaintenancePlan deviceMaintenancePlan = baseMapper.selectById(maintenancePlanId); + // 鏌ヨ璇︽儏 + DeviceMaintenancePlanDto deviceMaintenancePlanDto = new DeviceMaintenancePlanDto(); + BeanUtils.copyProperties(deviceMaintenancePlan, deviceMaintenancePlanDto); + deviceMaintenancePlanDto.setDeviceMaintenancePlanDetails(deviceMaintenancePlanDetailsMapper.deviceInspectionRecordDetailsList(maintenancePlanId)); + return Result.success(deviceMaintenancePlanDto); + } + + /** + * 鎻愪氦瀹℃牳 + * @param deviceMaintenancePlanDto + * @return + */ + @Override + public Result submitReviewMaintenancePlanStatus(DeviceMaintenancePlanDto deviceMaintenancePlanDto) { + User audit = userMapper.selectById(deviceMaintenancePlanDto.getAuditId()); + this.update(Wrappers.<DeviceMaintenancePlan>lambdaUpdate() + .eq(DeviceMaintenancePlan::getMaintenancePlanId, deviceMaintenancePlanDto.getMaintenancePlanId()) + .set(DeviceMaintenancePlan::getAuditId, audit.getId()) + .set(DeviceMaintenancePlan::getAudit, audit.getName()) + .set(DeviceMaintenancePlan::getStatus, null) + .set(DeviceMaintenancePlan::getAuditRemark, null) + .set(DeviceMaintenancePlan::getAuditDate, null) + ); + + DeviceMaintenancePlan deviceMaintenancePlan = baseMapper.selectById(deviceMaintenancePlanDto.getMaintenancePlanId()); + + // 鍙戦�佹秷鎭� + 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(deviceMaintenancePlan.getPlanYear() + "骞寸殑璁惧淇濆吇璁″垝寰呭鏍�"); + info.setSenderId(userId); + // 鎺ユ敹浜� + info.setConsigneeId(audit.getId()); + info.setJumpPath(MenuJumpPathConstants.DEVICE); + informationNotificationService.addInformationNotification(info); + + // 鍙戦�佷紒涓氬井淇¢�氱煡 + threadPoolTaskExecutor.execute(() -> { + String message = ""; + message += "CNAS璁惧淇濆吇璁″垝鏍搁�氱煡"; + message += "\n璇峰幓璧勬簮绠$悊-璁惧涓�灞傜洰褰�-璁惧淇濆吇璁″垝濉啓"; + message += "\n" + deviceMaintenancePlan.getPlanYear() + "骞寸殑璁惧淇濆吇璁″垝寰呮牳"; + //鍙戦�佷紒涓氬井淇℃秷鎭�氱煡 + try { + WxCpUtils.inform(audit.getAccount(), message, null); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + return Result.success(); + } + + /** + * 瀹℃牳璁惧淇濆吇璁″垝 + * + * @param deviceMaintenancePlanDto 璁惧淇濆吇璁″垝 + */ + @Override + public Result reviewMaintenancePlanStatus(DeviceMaintenancePlanDto deviceMaintenancePlanDto) { + LambdaUpdateWrapper<DeviceMaintenancePlan> wrapper = Wrappers.<DeviceMaintenancePlan>lambdaUpdate() + .eq(DeviceMaintenancePlan::getMaintenancePlanId, deviceMaintenancePlanDto.getMaintenancePlanId()) + .set(DeviceMaintenancePlan::getStatus, deviceMaintenancePlanDto.getStatus()) + .set(DeviceMaintenancePlan::getAuditRemark, deviceMaintenancePlanDto.getAuditRemark()) + .set(DeviceMaintenancePlan::getAuditDate, LocalDateTime.now()); + + this.update(wrapper); // 鏇存柊 + return Result.success(); + } + + +} -- Gitblit v1.9.3