package com.szwl.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.szwl.model.entity.TAlarmClean; import com.szwl.mapper.TAlarmCleanMapper; import com.szwl.model.entity.TEquipment; import com.szwl.model.utils.MailUtil; import com.szwl.model.utils.YunPianSms; import com.szwl.service.TAlarmCleanService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.szwl.service.TEquipmentService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.io.IOException; import java.util.List; /** *

* 服务实现类 *

* * @author wuhs * @since 2024-08-02 */ @Service public class TAlarmCleanServiceImpl extends ServiceImpl implements TAlarmCleanService { @Autowired TEquipmentService equipmentService; private static final String appid = "07784f5fedb508046c841b391005b7de"; public String getContent(String clientId) { String clientName = getClientNameById(clientId); StringBuffer content = new StringBuffer(); String str = "Dear customer:
" + "
" + "Your machine name is <" + clientName + "> marshmallow robot, the stove maintenance cycle has arrived, please clean the stove cover to keep the pattern in the best condition, if it has been cleaned, please ignore this reminder." + "
" + "
" + "Best Regards.
" + "Sunzee Intelligent"; content.append(str); return content.toString(); } @Override public void sendEmail(String email, String clientId) { String clientName = getClientNameById(clientId); String content; content = getContent(clientName); String subject = "Cleaning reminders"; new MailUtil().send(email, subject, content); } @Override public String sendNote(String phone, String clientId) { String msg; try { String result = YunPianSms.sendSms(appid, getAlarmCleanMessage(clientId), phone); ObjectMapper om = new ObjectMapper(); JsonNode jsonNode = om.readTree(result); msg = jsonNode.get("msg").asText(); } catch (IOException e) { throw new RuntimeException(e); } return phone + ": " + msg; } private String getAlarmCleanMessage(String clientId) { String clientName = getClientNameById(clientId); return "【申泽智能】您机器名称为 " + clientName + " 的棉花糖机器人,炉头保养周期已到,请清洁炉头盖,以保持花型在最佳状态,如已清洁请忽略本提醒。"; } public String getClientNameById(String clientId) { LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); wrapper.eq(TEquipment::getClientId, clientId); List equipmentList = equipmentService.list(wrapper); TEquipment equipment = equipmentList.get(0); return equipment.getName(); } }