| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import java.io.IOException; |
| | | import java.sql.Date; |
| | | import java.time.LocalDate; |
| | | import java.util.Arrays; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.google.gson.Gson; |
| | | import com.ruoyi.common.enums.MsgLSEnum; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.OkHttpExample; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.message.SendResult; |
| | | import com.ruoyi.message.sms.SmsSendRequest; |
| | | import com.ruoyi.message.sms.SmsSenderFactory; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.smartor.common.LSHospTokenUtil; |
| | | import com.smartor.domain.ServiceSubtask; |
| | | import com.smartor.mapper.ServiceSubtaskMapper; |
| | | import com.ruoyi.common.core.service.ISubtaskSmsService; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.ruoyi.system.mapper.SmsRecordsMapper; |
| | |
| | | @Autowired |
| | | private ISysConfigService iSysConfigService; |
| | | |
| | | /** |
| | | * 消息发送方工厂(短信),丽水短信已收口到 ruoyi-message |
| | | */ |
| | | @Autowired |
| | | private ServiceSubtaskMapper serviceSubtaskMapper; |
| | | |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | | |
| | | private SmsSenderFactory smsSenderFactory; |
| | | /** |
| | | * 查询短信记录 |
| | | * |
| | |
| | | List<SmsRecords> selectSmsRecordsList = smsRecordsMapper.selectSmsRecordsList(smsRecords); |
| | | for (SmsRecords record : selectSmsRecordsList) { |
| | | Boolean aBoolean = sendSMS(record.getOrgid(), record.getPhone(), record.getMsg()); |
| | | ServiceSubtask serviceSubtask = new ServiceSubtask(); |
| | | serviceSubtask.setId(record.getSubId()); |
| | | if (aBoolean) serviceSubtask.setVisitNotice(1); |
| | | serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); |
| | | if (aBoolean) { |
| | | ISubtaskSmsService subtaskSmsService = SpringUtils.getBean(ISubtaskSmsService.class); |
| | | subtaskSmsService.updateSubtaskVisitNotice(record.getSubId(), 1); |
| | | } |
| | | } |
| | | |
| | | return true; |
| | |
| | | |
| | | |
| | | public Boolean sendSMS(String orgid, String phone, String content) { |
| | | //丽水的短信发送方式 |
| | | Boolean isSuccess = false; |
| | | //丽水的短信发送方式:已收口到 ruoyi-message 的 LishuiSmsSender |
| | | //(机构配置从 sys_config 的 ls.msg.info 读取,token 由 smartor 注册的 |
| | | // LishuiMessageConfigProvider 提供),这里不再自己拼报文 |
| | | try { |
| | | String url = configService.selectConfigByKey("token.360",orgid); |
| | | Map<String, String> map = MsgLSEnum.getAddressByCode(orgid); |
| | | String token = LSHospTokenUtil.getToken(orgid,url); |
| | | log.info("【sfHandlle】丽水短信发送,地址:{},参数:{},机构ID:{}", map.get("address"), orgid); |
| | | String dxCode = getDXCode(map.get("address"), phone, content, map.get("sendPersonId"), map.get("sendPersonName"), MsgLSEnum.getHeaderByCode(orgid), token); |
| | | log.info("【sfHandlle】丽水短信发送结果:{}", dxCode); |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | Map<String, Object> textParam = null; |
| | | textParam = objectMapper.readValue(dxCode, Map.class); |
| | | String code = textParam.get("Code").toString(); |
| | | if (code.equals("0")) { |
| | | isSuccess = true; |
| | | } |
| | | SendResult sendResult = smsSenderFactory.send("ls", |
| | | SmsSendRequest.of(phone, content, orgid)); |
| | | log.info("【SmsRecordsServiceImpl】丽水短信发送结果:{}", sendResult); |
| | | return sendResult.isOk(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("【SmsRecordsServiceImpl】丽水短信发送异常,orgid:{},phone:{}", orgid, phone, e); |
| | | return false; |
| | | } |
| | | return isSuccess; |
| | | } |
| | | |
| | | /** |
| | |
| | | smsRecords.setUpdateTime(DateUtils.getNowDate()); |
| | | return smsRecordsMapper.updateSmsRecords(smsRecords); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除短信记录 |
| | | * |
| | |
| | | return smsRecordsMapper.deleteSmsRecordsByRecordid(recordid); |
| | | } |
| | | |
| | | |
| | | private String getDXCode(String address, String ShouJiHM, String FaSongNR, String FaSongRID, String FaSongRXM, Map<String, Object> headerMap, String token) { |
| | | Map<String, Object> map = new LinkedHashMap<>(); |
| | | |
| | | Map<String, Object> YeWuXX = new LinkedHashMap<>(); |
| | | Map<String, Object> DuanXinXX = new LinkedHashMap<>(); |
| | | DuanXinXX.put("ShouJiHM", ShouJiHM); |
| | | DuanXinXX.put("FaSongNR", FaSongNR); |
| | | DuanXinXX.put("FaSongRID", FaSongRID); |
| | | DuanXinXX.put("FaSongRXM", FaSongRXM); |
| | | YeWuXX.put("DuanXinXX", DuanXinXX); |
| | | |
| | | map.put("XiaoXiTou", headerMap); |
| | | map.put("YeWuXX", YeWuXX); |
| | | |
| | | String body = new Gson().toJson(map); |
| | | |
| | | // String result = HttpUtils.sendPost(address, body); |
| | | String result = null; |
| | | try { |
| | | result = OkHttpExample.sendPostRequest(address, body, token); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | log.info("【getDXCode】短信发送结果:{}", result); |
| | | |
| | | JSONObject jsonObject = JSONObject.parseObject(result); |
| | | String code = (String) jsonObject.toString(); |
| | | return code; |
| | | } |
| | | // --------------------------------------------------------------------- |
| | | // 说明:原 getDXCode 已随发送方一起收口到 ruoyi-message 的 LishuiSmsSender, |
| | | // 此处已删除,避免第三套丽水报文实现继续存在。 |
| | | // --------------------------------------------------------------------- |
| | | } |