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.ProtWarningInfo;
import com.huimv.admin.mapper.ProtWarningInfoMapper;
import com.huimv.admin.service.IProtWarningInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.netty.util.internal.StringUtil;
import org.apache.tomcat.util.buf.StringUtils;
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-14
 */
@Service
public class ProtWarningInfoServiceImpl extends ServiceImpl<ProtWarningInfoMapper, ProtWarningInfo> implements IProtWarningInfoService {

    @Autowired
    private ProtWarningInfoMapper protWarningInfoMapper;
    @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==""||pageSize==null) {
            pageSize = "10";
        }
        if (pageNo==""||pageNo==null) {
            pageNo = "1";
        }
        QueryWrapper<ProtWarningInfo> 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<ProtWarningInfo> page = new Page(Integer.parseInt(pageNo), Integer.parseInt(pageSize));
        return new Result(ResultCode.SUCCESS,protWarningInfoMapper.selectPage(page,queryWrapper));
    }
}
