package cn.qinys.platform.upms.api.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import cn.qinys.platform.entity.upms.SystemSmsLog;
import cn.qinys.platform.upms.api.mapper.SystemSmsLogMapper;
import cn.qinys.platform.upms.api.req.SmsLogPageQuery;
import cn.qinys.platform.upms.api.resp.SmsLogPageResp;
import lombok.AllArgsConstructor;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.qinys.platform.base.response.Result;
/**
 * 短信日志
 *
 * @author tanlie
 * Date: 2024/4/2 11:11
 */
@AllArgsConstructor
@RestController
@RequestMapping("/upms/sms-log")
public class SmsLogController {

    SystemSmsLogMapper smsLogMapper;

    /**
     * 短信日志分页
     *
     * @return
     */
    @GetMapping("/page")
    public Result<Page<SmsLogPageResp>> getPage(SmsLogPageQuery query) {
        query = query == null ? new SmsLogPageQuery() : query;
        Page<SystemSmsLog> page = new Page<>(query.getCurrent(), query.getSize());
        QueryWrapper<SystemSmsLog> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.like(StringUtils.hasLength(query.getMobile()), "mobile", query.getMobile());
        wrapper.like(StringUtils.hasLength(query.getContent()), "content", query.getContent());
        Page<SmsLogPageResp> logPage = smsLogMapper.selectLogPage(page, wrapper);
        return new Result<>(logPage);
    }


}
