TAlarmCleanServiceImpl.java 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package com.szwl.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  4. import com.fasterxml.jackson.databind.JsonNode;
  5. import com.fasterxml.jackson.databind.ObjectMapper;
  6. import com.szwl.model.entity.TAlarmClean;
  7. import com.szwl.mapper.TAlarmCleanMapper;
  8. import com.szwl.model.entity.TEquipment;
  9. import com.szwl.model.utils.MailUtil;
  10. import com.szwl.model.utils.YunPianSms;
  11. import com.szwl.service.TAlarmCleanService;
  12. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  13. import com.szwl.service.TEquipmentService;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import java.io.IOException;
  17. import java.util.List;
  18. /**
  19. * <p>
  20. * 服务实现类
  21. * </p>
  22. *
  23. * @author wuhs
  24. * @since 2024-08-02
  25. */
  26. @Service
  27. public class TAlarmCleanServiceImpl extends ServiceImpl<TAlarmCleanMapper, TAlarmClean> implements TAlarmCleanService {
  28. @Autowired
  29. TEquipmentService equipmentService;
  30. private static final String appid = "07784f5fedb508046c841b391005b7de";
  31. public String getContent(String clientId) {
  32. String clientName = getClientNameById(clientId);
  33. StringBuffer content = new StringBuffer();
  34. String str = "Dear customer:<br>" +
  35. "<br>" +
  36. "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." +
  37. "<br>" +
  38. "<br>" +
  39. "Best Regards.<br>" +
  40. "Sunzee Intelligent";
  41. content.append(str);
  42. return content.toString();
  43. }
  44. @Override
  45. public void sendEmail(String email, String clientId) {
  46. String clientName = getClientNameById(clientId);
  47. String content;
  48. content = getContent(clientName);
  49. String subject = "Cleaning reminders";
  50. new MailUtil().send(email, subject, content);
  51. }
  52. @Override
  53. public String sendNote(String phone, String clientId) {
  54. String msg;
  55. try {
  56. String result = YunPianSms.sendSms(appid, getAlarmCleanMessage(clientId), phone);
  57. ObjectMapper om = new ObjectMapper();
  58. JsonNode jsonNode = om.readTree(result);
  59. msg = jsonNode.get("msg").asText();
  60. } catch (IOException e) {
  61. throw new RuntimeException(e);
  62. }
  63. return phone + ": " + msg;
  64. }
  65. private String getAlarmCleanMessage(String clientId) {
  66. String clientName = getClientNameById(clientId);
  67. return "【申泽智能】您机器名称为 " + clientName + " 的棉花糖机器人,炉头保养周期已到,请清洁炉头盖,以保持花型在最佳状态,如已清洁请忽略本提醒。";
  68. }
  69. public String getClientNameById(String clientId) {
  70. LambdaQueryWrapper<TEquipment> wrapper = Wrappers.lambdaQuery();
  71. wrapper.eq(TEquipment::getClientId, clientId);
  72. List<TEquipment> equipmentList = equipmentService.list(wrapper);
  73. TEquipment equipment = equipmentList.get(0);
  74. return equipment.getName();
  75. }
  76. }