yangys
2024-03-27 e48aa2ac8dea1be5db11c63edf0b912c4ad5ce65
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.qianwen.smartman.modules.notify.business;
 
import com.baomidou.mybatisplus.core.toolkit.BeanUtils;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import com.qianwen.smartman.common.constant.DateConstant;
import com.qianwen.smartman.common.constant.NotifyConstant;
import com.qianwen.smartman.modules.notify.dto.MaintainDTO;
import com.qianwen.smartman.modules.notify.dto.MaintainPlanSendDTO;
import com.qianwen.smartman.modules.notify.dto.NotifyBusinessSendDTO;
import com.qianwen.smartman.modules.notify.dto.NotifySendDTO;
import com.qianwen.smartman.modules.notify.service.IBusinessNotifyService;
import com.qianwen.smartman.modules.tpm.entity.MaintainPlan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
 
@Component
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/notify/business/MaintenanceSend.class */
public class MaintenanceSend implements BusinessSend<MaintainPlan> {
    @Autowired
    private IBusinessNotifyService businessNotifyService;
    @Autowired
    private TemplateEngine templateEngine;
 
    @Override // org.springblade.modules.notify.business.BusinessSend
    public void sendMessage(MaintainPlan maintainPlan, NotifyBusinessSendDTO notifyBusinessSendDTO) {
        Integer intervalTime = maintainPlan.getIntervalTime();
        LocalDateTime maintainDate = maintainPlan.getMaintainDate();
        DateTimeFormatter df = DateTimeFormatter.ofPattern(DateConstant.PATTERN_DATE_TIME1);
        String deviceCode = maintainPlan.getDeviceCode() != null ? maintainPlan.getDeviceCode() : "-";
        String deviceName = maintainPlan.getDeviceName() != null ? maintainPlan.getDeviceName() : "-";
        String code = maintainPlan.getCode() != null ? maintainPlan.getCode() : "-";
        List<Long> empIds = notifyBusinessSendDTO.getEmpIds();
        List<Long> orgIds = notifyBusinessSendDTO.getOrgIds();
        MaintainPlanSendDTO maintainPlanSendDTO = new MaintainPlanSendDTO();
        maintainPlanSendDTO.setCode(code);
        if (maintainDate != null) {
            maintainPlanSendDTO.setPlanStartTime(maintainDate.format(df));
            if (intervalTime != null) {
                maintainPlanSendDTO.setPlanEndTime(maintainDate.plusDays(intervalTime.intValue()).format(df));
            } else {
                maintainPlanSendDTO.setPlanEndTime("-");
            }
        }
        Context context = new Context();
        MaintainDTO maintainDTO = new MaintainDTO();
        maintainDTO.setName(deviceName);
        maintainDTO.setCode(deviceCode);
        List<MaintainDTO> machineList = new ArrayList<>();
        machineList.add(maintainDTO);
        context.setVariable("machineList", machineList);
        String machinesHtml = this.templateEngine.process("machines", context);
        maintainPlanSendDTO.setMaintains(machinesHtml);
        NotifySendDTO notifySendDTO = new NotifySendDTO();
        notifySendDTO.setData(BeanUtils.beanToMap(maintainPlanSendDTO));
        notifySendDTO.setEmpIds(empIds);
        notifySendDTO.setOrgIds(orgIds);
        notifySendDTO.setBusinessKey(NotifyConstant.MAINTENANCE);
        this.businessNotifyService.sendMessage(notifySendDTO);
    }
 
    @Override // org.springblade.modules.notify.business.BusinessSend
    @Async
    public void saveState(MaintainPlan maintainPlan, NotifyBusinessSendDTO notifyBusinessSend) {
        sendMessage(maintainPlan, notifyBusinessSend);
    }
}