xiongchao 3 éve
szülő
commit
e85309d08d

+ 3 - 0
platform-dao/src/main/java/com/platform/dao/dto/repair/RepairApplicationFormDTO.java

@@ -246,6 +246,9 @@ public class RepairApplicationFormDTO extends BaseDTO implements Serializable {
      */
     private List<SysFile> checkFileList;
 
+    /**
+     * 报修人
+     */
     private String actualUser;
 
     /**

+ 15 - 4
platform-dao/src/main/java/com/platform/dao/util/MessageTemplateUtil.java

@@ -84,6 +84,21 @@ public class MessageTemplateUtil {
         return String.format("有新的报修【%s】待认领", id);
     }
 
+    public static String getRepairDispatch(String id) {
+        return String.format("您有新的维修【%s】派工,请处理", id);
+    }
+
+    public static String getRepairDispatch(String url, String no, String userName, String sbName, String sbNo, String cph, String content) {
+        return String.format("有新的维修单【%s】请处理,单号:【%s】,报修人:【%s】,故障设备名称:【%s】,设备编号:【%s】,使用位置:【%s】,故障现象:【%s】。",
+                url,no,userName,sbName,sbNo,cph, content);
+    }
+
+    public static String getRepairDispatchByFtl(String url, String no, String userName, String sbName, String sbNo, String cph, String content) {
+
+        return String.format("有新的维修单【%s】请处理,单号:【%s】,报修人:【%s】,故障设备名称:【%s】,设备编号:【%s】,使用位置:【%s】,故障现象:【%s】。",
+                url,no,userName,sbName,sbNo,cph, content);
+    }
+
     public static String getRepairApplicationForNotFinishNotic(String id, int hour) {
         return String.format("报修【%s】已超过%d小时未完成", id);
     }
@@ -96,10 +111,6 @@ public class MessageTemplateUtil {
         return String.format("报修【%s】已完成,请验收", id);
     }
 
-    public static String getRepairDispatch(String id) {
-        return String.format("您有新的维修【%s】派工,请处理", id);
-    }
-
     public static String getRepairBack(String id) {
         return String.format("您的维修【%s】被驳回,请重新处理", id);
     }

+ 3 - 0
platform-dao/src/main/resources/mapper/repair/RepairApplicationFormMapper.xml

@@ -30,6 +30,9 @@
             <if test="sbId != null and sbId != ''">
                 and application.sb_id = #{sbId}
             </if>
+            <if test="no != null and no != ''">
+                and application.no = #{no}
+            </if>
             <if test="mainRepairId != null and mainRepairId != ''">
                 and application.main_repair_id = #{mainRepairId}
             </if>

+ 8 - 0
platform-rest/src/main/java/com/platform/rest/controller/repair/RepairApplicationFormController.java

@@ -1,5 +1,6 @@
 package com.platform.rest.controller.repair;
 
+import com.platform.common.exception.BusinessException;
 import com.platform.common.util.BeanConverterUtil;
 import com.platform.common.util.R;
 import com.platform.common.validation.group.AddGroup;
@@ -12,14 +13,19 @@ import com.platform.dao.entity.repair.RepairApplicationForm;
 import com.platform.dao.util.ExcelUtil;
 import com.platform.dao.vo.export.repair.ExportRepairApplicationFormVO;
 import com.platform.dao.vo.repair.RepairApplicationFormVO;
+import com.platform.rest.RestApplication;
 import com.platform.rest.log.annotation.SysLog;
 import com.platform.service.repair.RepairApplicationFormService;
+import freemarker.template.Configuration;
+import freemarker.template.Template;
 import lombok.AllArgsConstructor;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.StringWriter;
 import java.util.List;
 
 /**
@@ -67,9 +73,11 @@ public class RepairApplicationFormController {
     @PostMapping
     @PreAuthorize("@pms.hasPermission('repair-application-forms-add')")
     public R save(@Validated({AddGroup.class}) @RequestBody RepairApplicationFormDTO repairApplicationFormDTO) {
+
         return new R<>(repairApplicationFormService.saveModelByDTO(repairApplicationFormDTO));
     }
 
+
     /**
      * 修改记录
      *

+ 32 - 0
platform-rest/src/main/resources/templates/repairEmail.ftl

@@ -0,0 +1,32 @@
+<div>维修通知</div>
+<div>有新的报修单等待处理:
+    <table border="1">
+        <tr>
+            <td>维修单号</td>
+            <td>${no}</td>
+        </tr>
+        <tr>
+            <td>设备名称</td>
+            <td>${sbName}</td>
+        </tr>
+        <tr>
+            <td>设备编号</td>
+            <td>${sbNo}</td>
+        </tr>
+        <tr>
+            <td>设备使用位置</td>
+            <td>${sbCph}</td>
+        </tr>
+        <tr>
+            <td>报修人</td>
+            <td>${actualUser}</td>
+        </tr>
+        <tr>
+            <td>故障描述</td>
+            <td>${repairDesc}</td>
+        </tr>
+    </table>
+</div>
+<div>
+    <a href="${url}">点击链接跳转处理报修单</a>
+</div>

+ 1 - 1
platform-service/src/main/java/com/platform/service/event/EventListenerBean.java

@@ -61,7 +61,7 @@ public class EventListenerBean {
         if (CollectionUtil.isNotEmpty(mails)) {
             mails.forEach(item -> {
                 if (StringUtils.isNotEmpty(item)) {
-                    mailService.sendSimpleMail(item, model.getContent(), model.getContent());
+                    mailService.sendHtmlMail(item, "设备管理系统通知", model.getContent());
                 }
             });
         }

+ 1 - 1
platform-service/src/main/java/com/platform/service/mail/MailServiceImpl.java

@@ -74,7 +74,7 @@ public class MailServiceImpl implements MailService {
             //邮件发送人
             messageHelper.setFrom(from);
             //邮件接收人
-            messageHelper.setTo(subject);
+            messageHelper.setTo(to);
             //邮件主题
             message.setSubject(subject);
             //邮件内容,html格式

+ 0 - 2
platform-service/src/main/java/com/platform/service/purchase/impl/PurchaseContractServiceImpl.java

@@ -309,7 +309,6 @@ public class PurchaseContractServiceImpl extends BaseServiceImpl<PurchaseContrac
         cfg.setTemplateLoader(stringLoader);
         try {
             Template temp = cfg.getTemplate("contract", "utf-8");
-
             String path = CommonConstants.RESOURCE_PREFIX + "/html/" + DateUtil.formatDate(new Date()) + "/" + IdGeneratorUtils.getObjectId() + "/";
             String filePath = UPLOAD_ROOT_FOLDER + path;
             File targetFile = new File(filePath);
@@ -318,7 +317,6 @@ public class PurchaseContractServiceImpl extends BaseServiceImpl<PurchaseContrac
             }
             String name = record.getNo() + "_contract.html";
             File outFile = new File(filePath + name);
-
             Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8"));
             temp.process(record, out);
             out.flush();

+ 86 - 37
platform-service/src/main/java/com/platform/service/repair/impl/RepairApplicationFormServiceImpl.java

@@ -2,6 +2,7 @@ package com.platform.service.repair.impl;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.github.pagehelper.PageHelper;
@@ -44,20 +45,24 @@ import com.platform.service.repair.RepairFormService;
 import com.platform.service.sb.SbInfoService;
 import com.platform.service.upms.SysUserDeptService;
 import com.platform.service.upms.SysUserService;
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
 import lombok.AllArgsConstructor;
+import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import tk.mybatis.mapper.weekend.Weekend;
 import tk.mybatis.mapper.weekend.WeekendCriteria;
 
 import javax.annotation.Resource;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
 import java.lang.reflect.Array;
 import java.time.LocalDateTime;
 import java.time.temporal.ChronoUnit;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -190,34 +195,37 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
         //model.setCheckUserId(userInfo.getUserId());
         // 查询对应的维修人,保存维修单
         String sbId = model.getSbId();
-        if (StringUtils.isNotEmpty(sbId)) {
-            SbInfoVO sb = sbInfoService.getById(sbId);
-            model.setModelId(sb.getModelId());
-            // 根据配置判断是否可以多个提交
-            String only = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.REPAIR_ONLY_ONE.name());
-            if(StringUtils.isNotBlank(only) && Integer.valueOf(only).equals(RepairOnlyOneEnum.ONLY_ONE.getValue())){
-                if (sb.getStatus().intValue() == SbInfoStatusEnum.IN_MAINTAIN.getValue()) {
-                    throw new BusinessException("设备已经在维修中,请等待维修完成, sbId" + model.getSbId());
-                }
-            }
+        SbInfoVO sb = sbInfoService.getById(sbId);
+        if (sb== null) {
+            throw new BusinessException("设备不存在,无法报修");
+        }
 
-            // 如果保修的设备位置和设备本身不一样,则可以更新该设备
-            boolean updateSb = false;
-            SbInfo info = new SbInfo();
-            info.setId(sb.getId());
-            if(!StringUtils.isBlank(sb.getCph()) || !model.getSbCph().equalsIgnoreCase((sb.getCph()))){
-                info.setCph(model.getSbCph());
-                updateSb = true;
-            }
-            // 如果选择了设备停机,则要修改设备状态
-            if (model.getNeedStop().intValue() == RepairApplicationFormStopEnum.STOP.getValue()) {
-                info.setStatus(SbInfoStatusEnum.IN_MAINTAIN.getValue());
-                updateSb = true;
-            }
-            if(updateSb){
-                sbInfoService.modModelByPrimaryKey(info);
+        model.setModelId(sb.getModelId());
+        // 根据配置判断是否可以多个提交
+        String only = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.REPAIR_ONLY_ONE.name());
+        if(StringUtils.isNotBlank(only) && Integer.valueOf(only).equals(RepairOnlyOneEnum.ONLY_ONE.getValue())){
+            if (sb.getStatus().intValue() == SbInfoStatusEnum.IN_MAINTAIN.getValue()) {
+                throw new BusinessException("设备已经在维修中,请等待维修完成, sbId" + model.getSbId());
             }
         }
+
+        // 如果保修的设备位置和设备本身不一样,则可以更新该设备
+        boolean updateSb = false;
+        SbInfo info = new SbInfo();
+        info.setId(sb.getId());
+        if(!StringUtils.isBlank(sb.getCph()) || !model.getSbCph().equalsIgnoreCase((sb.getCph()))){
+            info.setCph(model.getSbCph());
+            updateSb = true;
+        }
+        // 如果选择了设备停机,则要修改设备状态
+        if (model.getNeedStop().intValue() == RepairApplicationFormStopEnum.STOP.getValue()) {
+            info.setStatus(SbInfoStatusEnum.IN_MAINTAIN.getValue());
+            updateSb = true;
+        }
+        if(updateSb){
+            sbInfoService.modModelByPrimaryKey(info);
+        }
+
         model.setOutNo(model.getOutNo());
         model.setNo(IdGeneratorUtils.getRepairApplicaitonFormNo(++count));
         String repairUserId = model.getRepairUserId();
@@ -230,6 +238,15 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
         RepairApplicationForm form = super.saveModelHaveCreateInfo(model);
         List<String> userIds = new ArrayList<>();
         List<String> mails = new ArrayList<>();
+
+        String domain = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.SYSTEM_DOMAIN.name());
+        if(StringUtils.isBlank(domain)){
+            throw new BusinessException("请先设置系统域名地址,系统管理-》系统参数配置-》SYSTEM_DOMAIN");
+        }
+        if(!domain.endsWith("/")){
+            domain = domain + "/";
+        }
+        String repairUrl = domain + "repair/form?no=" + model.getNo();
         if (StringUtils.isEmpty(repairUserId)) {
             List<SysUser> users = sysUserService.getRepairUser(new SysUserDTO());
             List<SysUser> filterUsers = users.stream().filter(item -> item.getWorkFlag()).collect(Collectors.toList());
@@ -242,7 +259,8 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
             });
             // 通过给当天值班维修人员
             SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.REPAIR.getValue(), WorkplaceBacklogDetailTypeEnum.REPAIR_APPLICATION.getValue(),
-                    model.getId(), MessageTemplateUtil.getRepairApplicationForReceive(model.getNo()),
+                    model.getId(),
+                    getFreemarkerHtmlContent(repairUrl,model,sb),
                     model.getId(), userIds, mails));
         } else {
             SysUserVO user = sysUserService.selectUserVO(repairUserId);
@@ -250,14 +268,45 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
             mails.add(user.getEmail());
             // 通过给当天值班维修人员
             SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.REPAIR.getValue(), WorkplaceBacklogDetailTypeEnum.REPAIR_APPLICATION.getValue(),
-                    model.getId(), MessageTemplateUtil.getRepairDispatch(model.getNo()),
+                    model.getId(),
+                    getFreemarkerHtmlContent(repairUrl,model,sb),
                     model.getId(), userIds, mails));
         }
 
-
         return form;
     }
 
+    private String getFreemarkerHtmlContent(String url, RepairApplicationFormDTO model, SbInfoVO vo){
+        // 首先配置 FreeMarker 模版位置
+        Configuration configuration = new Configuration(Configuration.VERSION_2_3_0);
+        ClassLoader loader = RepairApplicationFormServiceImpl.class.getClassLoader();
+        configuration.setClassLoaderForTemplateLoading(loader,"templates");
+
+        // 配置模版文件
+        try {
+            Template template = configuration.getTemplate("repairEmail.ftl");
+            StringWriter mail = new StringWriter();
+            //构造填充数据的Map
+            Map map = new HashMap();
+            map.put("no", model.getNo());
+            map.put("sbName", vo.getName());
+            map.put("sbNo", vo.getNo());
+            map.put("sbCph", model.getSbCph());
+            map.put("actualUser", model.getActualUser());
+            if(StringUtils.isBlank(model.getContent())){
+                map.put("repairDesc", "无法断定,请维修人员现场检查");
+            }else{
+                map.put("repairDesc", model.getContent());
+            }
+            map.put("url", url);
+            template.process(map,mail);
+            System.out.println(map.toString());
+            return mail.toString();
+        } catch (IOException | TemplateException e) {
+            throw new BusinessException("报修邮件模板解析出错。" + e.getMessage());
+        }
+    }
+
     @Override
     public void modModelByDTO(RepairApplicationFormDTO model) {
         if(StringUtils.isBlank(model.getSbId())){
@@ -451,16 +500,16 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
         applicationForm.setRepairEndTime(LocalDateTime.now());
         applicationForm.setRepairMinutes(DateUtils.dateDiff(applicationForm.getRepairEndTime(), applicationForm.getRepairStartTime()));
         applicationForm.setCheckStartTime(applicationForm.getRepairEndTime());
+        applicationForm.setCheckEndTime(applicationForm.getRepairEndTime());
         applicationForm.setRepairContent(dto.getRepairContent());
         applicationForm.setNeedStop(dto.getNeedStop());
-        applicationForm.setLevel(dto.getLevel());
+        //applicationForm.setLevel(dto.getLevel());
         applicationForm.setRepairContent(dto.getRepairContent());
-        applicationForm.setRepairErrorTypeId(dto.getRepairErrorTypeId());
+        //applicationForm.setRepairErrorTypeId(dto.getRepairErrorTypeId());
         applicationForm.setUpdateTime(LocalDateTime.now());
-        applicationForm.setContent(dto.getContent());
+        //applicationForm.setContent(dto.getContent());
         applicationForm.setOutType(dto.getOutType());
 
-
         Weekend<SysFile> weekend = new Weekend<>(SysFile.class);
         weekend.weekendCriteria().andEqualTo(SysFile::getTargetId, dto.getId());
         weekend.weekendCriteria().andEqualTo(SysFile::getType, SysFileTypeEnum.REPAIR_REPAIR_IMGS.getValue());
@@ -478,7 +527,7 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
         if (CollectionUtil.isNotEmpty(list)) {
             sysFileMapper.insertListforComplex(list);
         }
-
+        super.modModelByPrimaryKey(applicationForm);
         /*String userId = applicationForm.getUserId();
         applicationForm.setCheckUserId(userId);*/
         /*// 维修人自己发起报修自己验收