package com.fkzy.warn.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fkzy.warn.common.request.RequestParameter;
import com.fkzy.warn.mapper.AuditRecordsMapper;
import com.fkzy.warn.service.AuditRecordsService;
import com.fkzy.warn.model.AuditRecords;
import com.fkzy.warn.model.vo.UserVO;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhangjing
 * @date 2023/10/16 18:17
 * @description
 */
@Service
public class AuditRecordsServiceImpl extends ServiceImpl<AuditRecordsMapper, AuditRecords> implements
    AuditRecordsService {


    @Override
    public void saveModel(AuditRecords entity, String ticket) {
        save(entity);
    }

    @Override
    public void updateModel(AuditRecords entity,String ticket) {
        updateById(entity);
    }

    @Override
    public void deleteModel(List<String> ids) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.in("id", ids);
        remove(wrapper);
    }

    @Override
    public AuditRecords getNowRecord(Integer businessId) {
        //查询audit_date 为最新的一条数据
        // 按 audit_date 降序排列
        // 限制结果为1条
        QueryWrapper<AuditRecords> wrapper = new QueryWrapper<>();
        wrapper.eq("business_id", businessId)
            .orderByDesc("audit_date")
            .last("LIMIT 1");
        return getOne(wrapper);
    }

    @Override
    public Page<UserVO> queryPage(RequestParameter parameter) {
        Page<UserVO> page = new Page<>(parameter.getCurrent(), parameter.getSize());
        Map<String, Object> map = new HashMap<String, Object>();
        return baseMapper.queryPage(page,map);
    }

    @Override
    public List<AuditRecords> record(Integer businessId) {
        QueryWrapper<AuditRecords> wrapper = new QueryWrapper<>();
        wrapper.eq("business_id", businessId);
        return list(wrapper);
    }
}
