liusheng
2026-10-12 26d1f59f0266672398975ba0337bb3d8267c2d95
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SmsRecordsServiceImpl.java
@@ -1,26 +1,18 @@
package com.ruoyi.system.service.impl;
import java.io.IOException;
import java.sql.Date;
import java.time.LocalDate;
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.system.domain.SysConfig;
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.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SmsRecordsMapper;
@@ -42,11 +34,11 @@
    @Autowired
    private ISysConfigService iSysConfigService;
    /**
     * 消息发送方工厂(短信),丽水短信已收口到 ruoyi-message
     */
    @Autowired
    private ServiceSubtaskMapper serviceSubtaskMapper;
    @Autowired
    private ISysConfigService configService;
    private SmsSenderFactory smsSenderFactory;
    /**
     * 查询短信记录
     *
@@ -109,10 +101,10 @@
        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;
@@ -120,40 +112,18 @@
    public Boolean sendSMS(String orgid, String phone, String content) {
        //丽水的短信发送方式
        Boolean isSuccess = false;
        //丽水的短信发送方式:已收口到 ruoyi-message 的 LishuiSmsSender
        //(机构配置从 sys_config 的 ls.msg.info 读取,token 由 smartor 注册的
        //  LishuiMessageConfigProvider 提供),这里不再自己拼报文
        try {
            SysConfig config = new SysConfig();
            config.setConfigKey("ls.msg.info");
            config.setOrgid(orgid);
            List<SysConfig> sysConfigs = configService.selectConfigList(config);
            Map<String, String> msgInfo = new HashMap<>();
            if (CollectionUtils.isNotEmpty(sysConfigs)) {
                String configValue = sysConfigs.get(0).getConfigValue();
                ObjectMapper objectMapper = new ObjectMapper();
                if (StringUtils.isNotEmpty(configValue)) {
                    msgInfo = objectMapper.readValue(configValue, Map.class);
                }
            }
            log.info("-----------map的值为:{}", msgInfo);
//
//            String url = configService.selectConfigByKey("token.360",orgid);
//            Map<String, String> map = MsgLSEnum.getAddressByCode(orgid);
            String token = LSHospTokenUtil.getToken(orgid,msgInfo.get("tokenUrl"));
            log.info("【sfHandlle】丽水短信发送,地址:{},参数:{},机构ID:{}", msgInfo.get("address"), orgid);
            String dxCode = getDXCode(msgInfo.get("address"), phone, content, msgInfo.get("sendPersonId"), msgInfo.get("sendPersonName"), MsgLSEnum.getHeaderByCode(msgInfo), 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;
    }
    /**
@@ -167,7 +137,6 @@
        smsRecords.setUpdateTime(DateUtils.getNowDate());
        return smsRecordsMapper.updateSmsRecords(smsRecords);
    }
    /**
     * 批量删除短信记录
     *
@@ -190,34 +159,8 @@
        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,
    // 此处已删除,避免第三套丽水报文实现继续存在。
    // ---------------------------------------------------------------------
}