package com.huimv.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huimv.admin.common.utils.Result;
import com.huimv.admin.common.utils.ResultCode;
import com.huimv.admin.entity.GasWarningInfo;
import com.huimv.admin.mapper.GasWarningInfoMapper;
import com.huimv.admin.service.IGasWarningInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2023-02-21
 */
@Service
public class GasWarningInfoServiceImpl extends ServiceImpl<GasWarningInfoMapper, GasWarningInfo> implements IGasWarningInfoService {

    @Autowired
    private GasWarningInfoMapper gasWarningInfoMapper;
    @Override
    public Result list(HttpServletRequest httpServletRequest, Map<String,String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        String pageSize = paramsMap.get("pageSize");
        String pageNo = paramsMap.get("pageNo");
        String userIds = paramsMap.get("userIds");
        if (pageSize == null || pageSize == "") {
            pageSize = "10";
        }
        if (pageNo == null || pageNo == "") {
            pageNo = "1";
        }
        QueryWrapper<GasWarningInfo> queryWrapper = new QueryWrapper<>();
        if ("1".equals(userIds)) {
            queryWrapper.eq("farm_id", farmId).orderByDesc("date");
        } else {
            queryWrapper.eq("farm_id", farmId).orderByDesc("date").like("user_ids",userIds);
        }
        Page<GasWarningInfo> page = new Page(Integer.parseInt(pageNo), Integer.parseInt(pageSize));
        return new Result(ResultCode.SUCCESS,gasWarningInfoMapper.selectPage(page,queryWrapper));
    }
}
