cloudroam
2024-12-27 c885a03818d37dceb22c558b9f23164e1f2ae749
add:阿里云短信模板获取签名和模板信息3
已修改7个文件
已添加2个文件
168 ■■■■ 文件已修改
src/main/java/com/mzl/flower/dto/request/sms/SmsTaskDetailQueryDTO.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/response/sms/SmsPhoneResultVO.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/response/sms/SmsTaskDetailVO.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/mapper/SmsTaskDetailMapper.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/impl/sms/SmsTaskDetailServiceImpl.java 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/impl/sms/SmsTaskServiceImpl.java 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/sms/SmsTaskDetailService.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/web/v2/sms/SmsTaskDetailController.java 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/sms/SmsTaskDetailMapper.xml 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/request/sms/SmsTaskDetailQueryDTO.java
对比新文件
@@ -0,0 +1,11 @@
package com.mzl.flower.dto.request.sms;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class SmsTaskDetailQueryDTO {
    @ApiModelProperty(value = "任务ID")
    private Long smsTaskId;
}
src/main/java/com/mzl/flower/dto/response/sms/SmsPhoneResultVO.java
对比新文件
@@ -0,0 +1,17 @@
package com.mzl.flower.dto.response.sms;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class SmsPhoneResultVO {
    @ApiModelProperty("ID")
    private Long id;
    @ApiModelProperty("接收号码")
    private String phone;
    @ApiModelProperty("发送结果")
    private String result;
}
src/main/java/com/mzl/flower/dto/response/sms/SmsTaskDetailVO.java
@@ -4,20 +4,29 @@
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
public class SmsTaskDetailVO extends AbstractTransDTO {
    @ApiModelProperty(value = "任务详情id")
    private Long id;
    @ApiModelProperty("短信任务表ID")
    private Long smsTaskId;
    @ApiModelProperty("任务名称")
    private String smsTaskName;
    @ApiModelProperty("短信模板表ID")
    private Long smsTemplateId;
    @ApiModelProperty("模板名称")
    private String smsTemplateName;
    @ApiModelProperty("接收号码")
    private String phone;
    @ApiModelProperty("号码数量")
    private Long totalNum;
    @ApiModelProperty("发送结果")
    private String result;
    @ApiModelProperty("成功数量")
    private Long successNum;
    @ApiModelProperty("失败数量")
    private Long failureNum;
    @ApiModelProperty("发送中数量")
    private Long sendingNum;
}
src/main/java/com/mzl/flower/mapper/SmsTaskDetailMapper.java
@@ -1,11 +1,14 @@
package com.mzl.flower.mapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzl.flower.dto.request.sms.SmsTaskDetailQueryDTO;
import com.mzl.flower.dto.request.sms.SmsTaskQueryDTO;
import com.mzl.flower.dto.response.sms.SmsPhoneResultVO;
import com.mzl.flower.dto.response.sms.SmsTaskDetailVO;
import com.mzl.flower.entity.SmsTaskDetailDO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@@ -19,5 +22,17 @@
 */
public interface SmsTaskDetailMapper extends BaseMapper<SmsTaskDetailDO> {
    List<SmsTaskDetailVO> queryPage(@Param("dto") SmsTaskQueryDTO dto, Page page);
    List<SmsPhoneResultVO> queryPage(@Param("dto") SmsTaskDetailQueryDTO dto, Page page);
    @Select("SELECT\n" +
            "\tt.id,\n" +
            "\tt.NAME AS smsTaskName ,\n" +
            "\tt.num as totalNum,\n" +
            "\tst.`name` as smsTemplateName\n" +
            "FROM\n" +
            "\tt_sms_task t\n" +
            "\tLEFT JOIN t_sms_template st ON t.sms_template_id = st.id\n" +
            "\tleft join t_sms_task_detail std ON t.id = std.sms_task_id")
    SmsTaskDetailVO getCountBySmsTaskId(Long id);
}
src/main/java/com/mzl/flower/service/impl/sms/SmsTaskDetailServiceImpl.java
@@ -1,23 +1,24 @@
package com.mzl.flower.service.impl.sms;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzl.flower.dto.request.sms.SmsTaskQueryDTO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mzl.flower.config.exception.ValidationException;
import com.mzl.flower.dto.request.sms.SmsTaskDetailQueryDTO;
import com.mzl.flower.dto.response.sms.SmsPhoneResultVO;
import com.mzl.flower.dto.response.sms.SmsTaskDetailVO;
import com.mzl.flower.dto.response.sms.SmsTaskVO;
import com.mzl.flower.entity.SmsTaskDetailDO;
import com.mzl.flower.mapper.SmsTaskDetailMapper;
import com.mzl.flower.mapper.SmsTaskMapper;
import com.mzl.flower.service.sms.SmsTaskDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.List;
/**
 * <p>
 *  服务实现类
 * 服务实现类
 * </p>
 *
 * @author @TaoJie
@@ -29,10 +30,19 @@
public class SmsTaskDetailServiceImpl extends ServiceImpl<SmsTaskDetailMapper, SmsTaskDetailDO> implements SmsTaskDetailService {
    private final SmsTaskDetailMapper smsTaskDetailMapper;
    @Override
    public Page<SmsTaskDetailVO> queryPage(SmsTaskQueryDTO dto, Page page) {
        List<SmsTaskDetailVO> list = smsTaskDetailMapper.queryPage(dto, page);
    public Page<SmsPhoneResultVO> queryPage(SmsTaskDetailQueryDTO dto, Page page) {
        if (StringUtils.isEmpty(dto.getSmsTaskId())) {
            throw new ValidationException("任务ID不能为空");
        }
        List<SmsPhoneResultVO> list = smsTaskDetailMapper.queryPage(dto, page);
        page.setRecords(list);
        return page;
    }
    @Override
    public SmsTaskDetailVO getCountBySmsTaskId(Long id) {
        return smsTaskDetailMapper.getCountBySmsTaskId(id);
    }
}
src/main/java/com/mzl/flower/service/impl/sms/SmsTaskServiceImpl.java
@@ -137,10 +137,13 @@
        try {
            // 下载Excel文件到本地临时文件
            File tempFile = File.createTempFile("temp", ".xlsx");
            ossClient.getObject(new GetObjectRequest(bucketName, smsTaskDTO.getFileUrl()), tempFile);
            String fileUrl = smsTaskDTO.getFileUrl();
            String objectKey = fileUrl.replaceFirst("^https?://[^/]+/", ""); // 去掉协议部分
            ossClient.getObject(new GetObjectRequest(bucketName, objectKey), tempFile);
            // 解析Excel文件
            try (FileInputStream inputStream = new FileInputStream(tempFile); Workbook workbook = new XSSFWorkbook(inputStream)) {
            try (FileInputStream inputStream = new FileInputStream(tempFile);
                 Workbook workbook = new XSSFWorkbook(inputStream)) {
                Sheet sheet = workbook.getSheetAt(0); // 获取第一个工作表
                int rowCount = sheet.getPhysicalNumberOfRows();
@@ -156,8 +159,14 @@
                    Row row = sheet.getRow(i);
                    if (row != null) {
                        Cell cell = row.getCell(0); // 假设手机号在第一列
                        if (cell != null && cell.getCellType() == CellType.STRING) {
                            String phoneNumber = cell.getStringCellValue();
                        if (cell != null ) {
                            String phoneNumber = "";
                            if (cell.getCellType() == CellType.STRING) {
                                phoneNumber = cell.getStringCellValue();
                            } else if (cell.getCellType() == CellType.NUMERIC) {
                                // 将数字类型的手机号转换为字符串
                                phoneNumber = String.valueOf((long) cell.getNumericCellValue());
                            }
                            if (!PHONE_NUMBER_PATTERN.matcher(phoneNumber).matches()) {
                                message.append("第" + (i + 1) + "行手机号" + phoneNumber + "格式不正确");
                                isValid = false;
@@ -166,7 +175,7 @@
                                phones.append(phoneNumber).append("\n");
                            }
                        } else {
                            message.append("行上的单元格为空或无效 " + (i + 1));
                            message.append("第" + (i + 1)+ "行上的单元格为空或无效 ");
                            isValid = false;
                            break; // 退出循环
                        }
@@ -181,7 +190,7 @@
                    throw new ValidationException(message.toString());
                } else {
                    smsTaskDTO.setPhones(phones.toString());
                    smsTaskDTO.setNum((long) rowCount);
                    smsTaskDTO.setNum((long) rowCount - 1);
                }
            } catch (IOException e) {
                e.printStackTrace();
src/main/java/com/mzl/flower/service/sms/SmsTaskDetailService.java
@@ -2,7 +2,8 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.mzl.flower.dto.request.sms.SmsTaskQueryDTO;
import com.mzl.flower.dto.request.sms.SmsTaskDetailQueryDTO;
import com.mzl.flower.dto.response.sms.SmsPhoneResultVO;
import com.mzl.flower.dto.response.sms.SmsTaskDetailVO;
import com.mzl.flower.entity.SmsTaskDetailDO;
@@ -16,6 +17,8 @@
 */
public interface SmsTaskDetailService extends IService<SmsTaskDetailDO> {
    Page<SmsTaskDetailVO> queryPage(SmsTaskQueryDTO dto, Page page);
    Page<SmsPhoneResultVO> queryPage(SmsTaskDetailQueryDTO dto, Page page);
    SmsTaskDetailVO getCountBySmsTaskId(Long id);
}
src/main/java/com/mzl/flower/web/v2/sms/SmsTaskDetailController.java
@@ -5,7 +5,9 @@
import com.mzl.flower.base.BaseController;
import com.mzl.flower.base.R;
import com.mzl.flower.base.ReturnDataDTO;
import com.mzl.flower.dto.request.sms.SmsTaskDetailQueryDTO;
import com.mzl.flower.dto.request.sms.SmsTaskQueryDTO;
import com.mzl.flower.dto.response.sms.SmsPhoneResultVO;
import com.mzl.flower.dto.response.sms.SmsTaskDetailVO;
import com.mzl.flower.service.sms.SmsTaskDetailService;
import io.swagger.annotations.Api;
@@ -16,20 +18,32 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
/**
* @author @TaoJie
* @since 2024-12-25
*/
 * @author @TaoJie
 * @since 2024-12-25
 */
@Api(value = "任务详情管理", tags = "任务详情管理")
@RestController
@RequestMapping("/v2/sms-task-detail")
@RequiredArgsConstructor
public class SmsTaskDetailController  extends BaseController {
public class SmsTaskDetailController extends BaseController {
    private final SmsTaskDetailService smsTaskDetailService;
    @GetMapping("/list")
    @ApiOperation(value = "任务详情列表", httpMethod = "GET")
    public ResponseEntity<ReturnDataDTO<Page<SmsTaskDetailVO>>> getSmsTaskList(Page page, SmsTaskQueryDTO dto) {
    public ResponseEntity<ReturnDataDTO<Page<SmsPhoneResultVO>>> getSmsTaskList(Page page, SmsTaskDetailQueryDTO dto) {
        return returnData(R.SUCCESS.getCode(), smsTaskDetailService.queryPage(dto, page));
    }
    @GetMapping("/taskStatistics")
    @ApiOperation(value = "任务详情列表", httpMethod = "GET")
    public ResponseEntity<ReturnDataDTO<SmsTaskDetailVO> >taskStatistics(@NotNull(message = "id不能为空") Long id ) {
        return returnData(R.SUCCESS.getCode(), smsTaskDetailService.getCountBySmsTaskId(id));
    }
}
src/main/resources/mapper/sms/SmsTaskDetailMapper.xml
@@ -5,27 +5,9 @@
    <select id="queryPage" resultType="com.mzl.flower.dto.response.sms.SmsTaskDetailVO">
        select t.* from t_sms_task_detail t
        where t.deleted= 0
        <if test="dto.id!=null ">
            and t.id = #{dto.id}
        <if test="dto.smsTaskId!=null ">
            and t.sms_task_id = #{dto.smsTaskId}
        </if>
        <if test="dto.result != null and dto.result != ''">
            and t.result like concat('%', #{dto.result}, '%')
        </if>
        <if test="dto.phone != null and dto.phone != ''">
            and t.phone like concat('%', #{dto.phone}, '%')
        </if>
        <if test="dto.startDate!=null ">
            <![CDATA[
               AND t.create_time >= #{dto.startDate}
            ]]>
        </if>
        <if test="dto.endDate!=null ">
            <![CDATA[
               AND t.create_time <= #{dto.endDate}
            ]]>
        </if>
    </select>
</mapper>