|
@@ -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);*/
|
|
|
/*// 维修人自己发起报修自己验收
|