package com.huimv.admin.service.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huimv.admin.common.utils.DataUill;
import com.huimv.admin.common.utils.Result;
import com.huimv.admin.common.utils.ResultCode;
import com.huimv.admin.entity.ProdFermentDevice;
import com.huimv.admin.entity.ProtData;
import com.huimv.admin.entity.ProtWarningInfo;
import com.huimv.admin.entity.WriteProtData;
import com.huimv.admin.entity.dto.ProCountDto;
import com.huimv.admin.entity.vo.ProCountVo;
import com.huimv.admin.entity.vo.ProDataVo;
import com.huimv.admin.entity.vo.WriteProtDataVo;
import com.huimv.admin.mapper.ProdFermentDeviceMapper;
import com.huimv.admin.mapper.ProtDataMapper;
import com.huimv.admin.mapper.ProtWarningInfoMapper;
import com.huimv.admin.mapper.WriteProtDataMapper;
import com.huimv.admin.service.IProtDataService;
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.text.SimpleDateFormat;
import java.util.*;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author author
 * @since 2023-02-14
 */
@Service
public class ProtDataServiceImpl extends ServiceImpl<ProtDataMapper, ProtData> implements IProtDataService {

    @Autowired
    private ProtDataMapper protDataMapper;
    @Autowired
    private ProtWarningInfoMapper protWarningInfoMapper;
    @Autowired
    private ProdFermentDeviceMapper fermentDeviceMapper;
    @Autowired
    private WriteProtDataMapper writeProtDataMapper;

    @Override
    public Result list(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        String displayType = paramsMap.get("displayType");//2为填报数据展示
        String startTime = paramsMap.get("startTime");
        String endTime = paramsMap.get("endTime");
        String type = paramsMap.get("type");
        String dataType = paramsMap.get("dataType");

        if (type == null || type == "") {
            type = "1";
        }
        if (dataType == null || dataType == "") {
            dataType = "1";
        }
        if (displayType == null || displayType == "") {
            displayType = "0";
        }
        ProCountDto proCountDto = new ProCountDto();
        if ("0".equals(displayType)) {
            QueryWrapper<ProtData> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("farm_id", farmId);
            //ph
            if ("1".equals(dataType)) {
                if ("4".equals(type)) {
                    startTime = startTime + " 00:00:00";
                    endTime = endTime + " 23:59:59";
                    queryWrapper.between("create_date", startTime, endTime);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listPh(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId);
                    queryWrapper2.between("create_date", startTime, endTime);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listPh(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId);
                    queryWrapper3.between("create_date", startTime, endTime);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listPh(queryWrapper3);
                    proCountDto.setOutList(protData3);

                }
                //本年
                else if ("3".equals(type)) {
                    Calendar dateTime = Calendar.getInstance();
                    int i = dateTime.get(Calendar.YEAR);
                    // DateTime dateTime = DateUtil.beginOfYear(new Date());
                    queryWrapper.ge("create_date", i);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listPhYear(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId).ge("create_date", i);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listPhYear(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId).ge("create_date", i);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listPhYear(queryWrapper3);
                    proCountDto.setOutList(protData3);
                }
                //本月
                else if ("2".equals(type)) {
                    Date timesMonthmorning = DataUill.getTimesMonthmorning();
                    queryWrapper.ge("create_date", timesMonthmorning);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listPh(queryWrapper);
                    proCountDto.setInList(protData1);
                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId).ge("create_date", timesMonthmorning);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listPh(queryWrapper2);
                    proCountDto.setDealList(protData2);
                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId).ge("create_date", timesMonthmorning);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listPh(queryWrapper3);
                    proCountDto.setOutList(protData3);
                }
                //本周
                else if ("1".equals(type)) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 7);
                    Date dateTime = calendar.getTime();
                    queryWrapper.ge("create_date", dateTime);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listPh(queryWrapper);
                    proCountDto.setInList(protData1);
                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId).ge("create_date", dateTime);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listPh(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId).ge("create_date", dateTime);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listPh(queryWrapper3);
                    proCountDto.setOutList(protData3);
                }
            }
            //cod
            else if ("2".equals(dataType)) {
                if ("4".equals(type)) {
                    startTime = startTime + " 00:00:00";
                    endTime = endTime + " 23:59:59";
                    queryWrapper.between("create_date", startTime, endTime);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listCod(queryWrapper);
                    proCountDto.setInList(protData1);
                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId);
                    queryWrapper2.between("create_date", startTime, endTime);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listCod(queryWrapper2);
                    proCountDto.setDealList(protData2);
                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId);
                    queryWrapper3.between("create_date", startTime, endTime);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listCod(queryWrapper3);
                    proCountDto.setOutList(protData3);
                }
                //本年
                else if ("3".equals(type)) {
                    Calendar dateTime = Calendar.getInstance();
                    int i = dateTime.get(Calendar.YEAR);
                    // DateTime dateTime = DateUtil.beginOfYear(new Date());
                    queryWrapper.ge("create_date", i);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listCodYear(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId).ge("create_date", i);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listCodYear(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId).ge("create_date", i);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listCodYear(queryWrapper3);
                    proCountDto.setOutList(protData3);


                }
                //本月
                else if ("2".equals(type)) {
                    Date timesMonthmorning = DataUill.getTimesMonthmorning();
                    queryWrapper.ge("create_date", timesMonthmorning);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listCod(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId).ge("create_date", timesMonthmorning);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listCod(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId).ge("create_date", timesMonthmorning);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listCod(queryWrapper3);
                    proCountDto.setOutList(protData3);


                }
                //本周
                else if ("1".equals(type)) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 7);
                    Date dateTime = calendar.getTime();

                    queryWrapper.ge("create_date", dateTime);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listCod(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId).ge("create_date", dateTime);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listCod(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId).ge("create_date", dateTime);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listCod(queryWrapper3);
                    proCountDto.setOutList(protData3);


                }
            }
            //NH3N
            else if ("3".equals(dataType)) {
                if ("4".equals(type)) {
                    startTime = startTime + " 00:00:00";
                    endTime = endTime + " 23:59:59";
                    queryWrapper.between("create_date", startTime, endTime);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listNh3n(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId);
                    queryWrapper2.between("create_date", startTime, endTime);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listNh3n(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId);
                    queryWrapper3.between("create_date", startTime, endTime);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listNh3n(queryWrapper3);

                    proCountDto.setOutList(protData3);


                    // protDataList=endList;
                }
                //本年
                else if ("3".equals(type)) {
                    Calendar dateTime = Calendar.getInstance();
                    int i = dateTime.get(Calendar.YEAR);
                    // DateTime dateTime = DateUtil.beginOfYear(new Date());
                    queryWrapper.ge("create_date", i);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listNh3nYear(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId).ge("create_date", i);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listNh3nYear(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId).ge("create_date", i);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listNh3nYear(queryWrapper3);
                    proCountDto.setOutList(protData3);


                }
                //本月
                else if ("2".equals(type)) {
                    Date timesMonthmorning = DataUill.getTimesMonthmorning();
                    queryWrapper.ge("create_date", timesMonthmorning);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listNh3n(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId).ge("create_date", timesMonthmorning);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listNh3n(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId).ge("create_date", timesMonthmorning);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listNh3n(queryWrapper3);
                    proCountDto.setOutList(protData3);


                }
                //本周
                else if ("1".equals(type)) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 7);
                    Date dateTime = calendar.getTime();

                    queryWrapper.ge("create_date", dateTime);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listNh3n(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId).ge("create_date", dateTime);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listNh3n(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId).ge("create_date", dateTime);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listNh3n(queryWrapper3);
                    proCountDto.setOutList(protData3);


                }
            }
            //TP
            else if ("4".equals(dataType)) {
                if ("4".equals(type)) {
                    startTime = startTime + " 00:00:00";
                    endTime = endTime + " 23:59:59";
                    queryWrapper.between("create_date", startTime, endTime);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listTp(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId);
                    queryWrapper2.between("create_date", startTime, endTime);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listTp(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId);
                    queryWrapper3.between("create_date", startTime, endTime);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listTp(queryWrapper3);

                    proCountDto.setOutList(protData3);


                    // protDataList=endList;
                }
                //本年
                else if ("3".equals(type)) {
                    Calendar dateTime = Calendar.getInstance();
                    int i = dateTime.get(Calendar.YEAR);
                    // DateTime dateTime = DateUtil.beginOfYear(new Date());
                    queryWrapper.ge("create_date", i);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listTpYear(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId).ge("create_date", i);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listTpYear(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId).ge("create_date", i);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listTpYear(queryWrapper3);
                    proCountDto.setOutList(protData3);


                }
                //本月
                else if ("2".equals(type)) {
                    Date timesMonthmorning = DataUill.getTimesMonthmorning();
                    queryWrapper.ge("create_date", timesMonthmorning);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listTp(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId).ge("create_date", timesMonthmorning);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listTp(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId).ge("create_date", timesMonthmorning);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listTp(queryWrapper3);
                    proCountDto.setOutList(protData3);


                }
                //本周
                else if ("1".equals(type)) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 7);
                    Date dateTime = calendar.getTime();

                    queryWrapper.ge("create_date", dateTime);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listTp(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId).ge("create_date", dateTime);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listTp(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId).ge("create_date", dateTime);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listTp(queryWrapper3);
                    proCountDto.setOutList(protData3);


                }
            }
            //TN
            else if ("5".equals(dataType)) {
                if ("4".equals(type)) {
                    startTime = startTime + " 00:00:00";
                    endTime = endTime + " 23:59:59";
                    queryWrapper.between("create_date", startTime, endTime);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listTn(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId);
                    queryWrapper2.between("create_date", startTime, endTime);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listTn(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId);
                    queryWrapper3.between("create_date", startTime, endTime);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listTn(queryWrapper3);

                    proCountDto.setOutList(protData3);


                    // protDataList=endList;
                }
                //本年
                else if ("3".equals(type)) {
                    Calendar dateTime = Calendar.getInstance();
                    int i = dateTime.get(Calendar.YEAR);
                    // DateTime dateTime = DateUtil.beginOfYear(new Date());
                    queryWrapper.ge("create_date", i);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listTnYear(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId).ge("create_date", i);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listTnYear(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId).ge("create_date", i);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listTnYear(queryWrapper3);
                    proCountDto.setOutList(protData3);


                }
                //本月
                else if ("2".equals(type)) {
                    Date timesMonthmorning = DataUill.getTimesMonthmorning();
                    queryWrapper.ge("create_date", timesMonthmorning);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listTn(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId).ge("create_date", timesMonthmorning);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listTn(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId).ge("create_date", timesMonthmorning);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listTn(queryWrapper3);
                    proCountDto.setOutList(protData3);


                }
                //本周
                else if ("1".equals(type)) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 7);
                    Date dateTime = calendar.getTime();

                    queryWrapper.ge("create_date", dateTime);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listTn(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId).ge("create_date", dateTime);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listTn(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId).ge("create_date", dateTime);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listTn(queryWrapper3);
                    proCountDto.setOutList(protData3);


                }
            }
            //FLOW
            else if ("6".equals(dataType)) {
                if ("4".equals(type)) {
                    startTime = startTime + " 00:00:00";
                    endTime = endTime + " 23:59:59";
                    queryWrapper.between("create_date", startTime, endTime);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listFlow(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId);
                    queryWrapper2.between("create_date", startTime, endTime);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listFlow(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId);
                    queryWrapper3.between("create_date", startTime, endTime);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listFlow(queryWrapper3);

                    proCountDto.setOutList(protData3);


                    // protDataList=endList;
                }
                //本年
                else if ("3".equals(type)) {
                    Calendar dateTime = Calendar.getInstance();
                    int i = dateTime.get(Calendar.YEAR);
                    // DateTime dateTime = DateUtil.beginOfYear(new Date());
                    queryWrapper.ge("create_date", i);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listFlowYear(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId).ge("create_date", i);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listFlowYear(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId).ge("create_date", i);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listFlowYear(queryWrapper3);
                    proCountDto.setOutList(protData3);


                }
                //本月
                else if ("2".equals(type)) {
                    Date timesMonthmorning = DataUill.getTimesMonthmorning();
                    queryWrapper.ge("create_date", timesMonthmorning);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listFlow(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId).ge("create_date", timesMonthmorning);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listFlow(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId).ge("create_date", timesMonthmorning);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listFlow(queryWrapper3);
                    proCountDto.setOutList(protData3);


                }
                //本周
                else if ("1".equals(type)) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 7);
                    Date dateTime = calendar.getTime();

                    queryWrapper.ge("create_date", dateTime);
                    queryWrapper.eq("loction_type", 1);
                    List<ProCountVo> protData1 = protDataMapper.listFlow(queryWrapper);
                    proCountDto.setInList(protData1);

                    QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("farm_id", farmId).ge("create_date", dateTime);
                    queryWrapper2.eq("loction_type", 2);
                    List<ProCountVo> protData2 = protDataMapper.listFlow(queryWrapper2);
                    proCountDto.setDealList(protData2);

                    QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
                    queryWrapper3.eq("farm_id", farmId).ge("create_date", dateTime);
                    queryWrapper3.eq("loction_type", 3);
                    List<ProCountVo> protData3 = protDataMapper.listFlow(queryWrapper3);
                    proCountDto.setOutList(protData3);


                }
            }
        } else {
            QueryWrapper<WriteProtData> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("farm_id", farmId);
            //ph
            List<ProCountVo> inList = new ArrayList<>();
            List<ProCountVo> dealList = new ArrayList<>();
            List<ProCountVo> outList = new ArrayList<>();
            List<WriteProtDataVo> writeProtDataVos;
            if ("1".equals(dataType)) {
                if ("3".equals(type)) {
                    Calendar dateTime = Calendar.getInstance();
                    int i = dateTime.get(Calendar.YEAR);
                    queryWrapper.ge("create_date", i);
                    writeProtDataVos = writeProtDataMapper.listWriteYear(queryWrapper);
                } else {
                    if ("4".equals(type)) {
                        startTime = startTime + " 00:00:00";
                        endTime = endTime + " 23:59:59";
                        queryWrapper.between("create_date", startTime, endTime);
                    } else if ("2".equals(type)) {
                        Date timesMonthmorning = DataUill.getTimesMonthmorning();
                        queryWrapper.ge("create_date", timesMonthmorning);
                    } else if ("1".equals(type)) {
                        Calendar calendar = Calendar.getInstance();
                        calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 7);
                        Date dateTime = calendar.getTime();
                        queryWrapper.ge("create_date", dateTime);
                    }
                    writeProtDataVos = writeProtDataMapper.listWrite(queryWrapper);
                }
                for (WriteProtDataVo writeProtDataVo : writeProtDataVos) {
                    ProCountVo proCountVo = new ProCountVo();
                    proCountVo.setValue(writeProtDataVo.getPh());
                    proCountVo.setCreateDate(writeProtDataVo.getCreateDate());
                    if (writeProtDataVo.getLoctionType().equals("1")) {
                        proCountVo.setLoctionType("1");
                        inList.add(proCountVo);
                    }
                    if (writeProtDataVo.getLoctionType().equals("2")) {
                        proCountVo.setLoctionType("2");
                        dealList.add(proCountVo);
                    }
                    if (writeProtDataVo.getLoctionType().equals("3")) {
                        proCountVo.setLoctionType("3");
                        outList.add(proCountVo);
                    }
                }
                proCountDto.setInList(inList);
                proCountDto.setDealList(dealList);
                proCountDto.setOutList(outList);
            }
            else if ("2".equals(dataType)) {
                if ("3".equals(type)) {
                    Calendar dateTime = Calendar.getInstance();
                    int i = dateTime.get(Calendar.YEAR);
                    queryWrapper.ge("create_date", i);
                    writeProtDataVos = writeProtDataMapper.listWriteYear(queryWrapper);
                } else {
                    if ("4".equals(type)) {
                        startTime = startTime + " 00:00:00";
                        endTime = endTime + " 23:59:59";
                        queryWrapper.between("create_date", startTime, endTime);
                    } else if ("2".equals(type)) {
                        Date timesMonthmorning = DataUill.getTimesMonthmorning();
                        queryWrapper.ge("create_date", timesMonthmorning);
                    } else if ("1".equals(type)) {
                        Calendar calendar = Calendar.getInstance();
                        calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 7);
                        Date dateTime = calendar.getTime();
                        queryWrapper.ge("create_date", dateTime);
                    }
                    writeProtDataVos = writeProtDataMapper.listWrite(queryWrapper);
                }
                for (WriteProtDataVo writeProtDataVo : writeProtDataVos) {
                    ProCountVo proCountVo = new ProCountVo();
                    proCountVo.setValue(writeProtDataVo.getCod());
                    proCountVo.setCreateDate(writeProtDataVo.getCreateDate());
                    if (writeProtDataVo.getLoctionType().equals("1")) {
                        proCountVo.setLoctionType("1");
                        inList.add(proCountVo);
                    }
                    if (writeProtDataVo.getLoctionType().equals("2")) {
                        proCountVo.setLoctionType("2");
                        dealList.add(proCountVo);
                    }
                    if (writeProtDataVo.getLoctionType().equals("3")) {
                        proCountVo.setLoctionType("3");
                        outList.add(proCountVo);
                    }
                }
                proCountDto.setInList(inList);
                proCountDto.setDealList(dealList);
                proCountDto.setOutList(outList);
            }
            else if ("3".equals(dataType)) {
                if ("3".equals(type)) {
                    Calendar dateTime = Calendar.getInstance();
                    int i = dateTime.get(Calendar.YEAR);
                    queryWrapper.ge("create_date", i);
                    writeProtDataVos = writeProtDataMapper.listWriteYear(queryWrapper);
                } else {
                    if ("4".equals(type)) {
                        startTime = startTime + " 00:00:00";
                        endTime = endTime + " 23:59:59";
                        queryWrapper.between("create_date", startTime, endTime);
                    } else if ("2".equals(type)) {
                        Date timesMonthmorning = DataUill.getTimesMonthmorning();
                        queryWrapper.ge("create_date", timesMonthmorning);
                    } else if ("1".equals(type)) {
                        Calendar calendar = Calendar.getInstance();
                        calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 7);
                        Date dateTime = calendar.getTime();
                        queryWrapper.ge("create_date", dateTime);
                    }
                    writeProtDataVos = writeProtDataMapper.listWrite(queryWrapper);
                }
                for (WriteProtDataVo writeProtDataVo : writeProtDataVos) {
                    ProCountVo proCountVo = new ProCountVo();
                    proCountVo.setValue(writeProtDataVo.getNh3n());
                    proCountVo.setCreateDate(writeProtDataVo.getCreateDate());
                    if (writeProtDataVo.getLoctionType().equals("1")) {
                        proCountVo.setLoctionType("1");
                        inList.add(proCountVo);
                    }
                    if (writeProtDataVo.getLoctionType().equals("2")) {
                        proCountVo.setLoctionType("2");
                        dealList.add(proCountVo);
                    }
                    if (writeProtDataVo.getLoctionType().equals("3")) {
                        proCountVo.setLoctionType("3");
                        outList.add(proCountVo);
                    }
                }
                proCountDto.setInList(inList);
                proCountDto.setDealList(dealList);
                proCountDto.setOutList(outList);
            }
            else if ("4".equals(dataType)) {
                if ("3".equals(type)) {
                    Calendar dateTime = Calendar.getInstance();
                    int i = dateTime.get(Calendar.YEAR);
                    queryWrapper.ge("create_date", i);
                    writeProtDataVos = writeProtDataMapper.listWriteYear(queryWrapper);
                } else {
                    if ("4".equals(type)) {
                        startTime = startTime + " 00:00:00";
                        endTime = endTime + " 23:59:59";
                        queryWrapper.between("create_date", startTime, endTime);
                    } else if ("2".equals(type)) {
                        Date timesMonthmorning = DataUill.getTimesMonthmorning();
                        queryWrapper.ge("create_date", timesMonthmorning);
                    } else if ("1".equals(type)) {
                        Calendar calendar = Calendar.getInstance();
                        calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 7);
                        Date dateTime = calendar.getTime();
                        queryWrapper.ge("create_date", dateTime);
                    }
                    writeProtDataVos = writeProtDataMapper.listWrite(queryWrapper);
                }
                for (WriteProtDataVo writeProtDataVo : writeProtDataVos) {
                    ProCountVo proCountVo = new ProCountVo();
                    proCountVo.setValue(writeProtDataVo.getTp());
                    proCountVo.setCreateDate(writeProtDataVo.getCreateDate());
                    if (writeProtDataVo.getLoctionType().equals("1")) {
                        proCountVo.setLoctionType("1");
                        inList.add(proCountVo);
                    }
                    if (writeProtDataVo.getLoctionType().equals("2")) {
                        proCountVo.setLoctionType("2");
                        dealList.add(proCountVo);
                    }
                    if (writeProtDataVo.getLoctionType().equals("3")) {
                        proCountVo.setLoctionType("3");
                        outList.add(proCountVo);
                    }
                }
                proCountDto.setInList(inList);
                proCountDto.setDealList(dealList);
                proCountDto.setOutList(outList);
            }
            else if ("5".equals(dataType)) {
                if ("3".equals(type)) {
                    Calendar dateTime = Calendar.getInstance();
                    int i = dateTime.get(Calendar.YEAR);
                    queryWrapper.ge("create_date", i);
                    writeProtDataVos = writeProtDataMapper.listWriteYear(queryWrapper);
                } else {
                    if ("4".equals(type)) {
                        startTime = startTime + " 00:00:00";
                        endTime = endTime + " 23:59:59";
                        queryWrapper.between("create_date", startTime, endTime);
                    } else if ("2".equals(type)) {
                        Date timesMonthmorning = DataUill.getTimesMonthmorning();
                        queryWrapper.ge("create_date", timesMonthmorning);
                    } else if ("1".equals(type)) {
                        Calendar calendar = Calendar.getInstance();
                        calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 7);
                        Date dateTime = calendar.getTime();
                        queryWrapper.ge("create_date", dateTime);
                    }
                    writeProtDataVos = writeProtDataMapper.listWrite(queryWrapper);
                }
                for (WriteProtDataVo writeProtDataVo : writeProtDataVos) {
                    ProCountVo proCountVo = new ProCountVo();
                    proCountVo.setValue(writeProtDataVo.getTn());
                    proCountVo.setCreateDate(writeProtDataVo.getCreateDate());
                    if (writeProtDataVo.getLoctionType().equals("1")) {
                        proCountVo.setLoctionType("1");
                        inList.add(proCountVo);
                    }
                    if (writeProtDataVo.getLoctionType().equals("2")) {
                        proCountVo.setLoctionType("2");
                        dealList.add(proCountVo);
                    }
                    if (writeProtDataVo.getLoctionType().equals("3")) {
                        proCountVo.setLoctionType("3");
                        outList.add(proCountVo);
                    }
                }
                proCountDto.setInList(inList);
                proCountDto.setDealList(dealList);
                proCountDto.setOutList(outList);
            }
            else if ("6".equals(dataType)) {
                if ("3".equals(type)) {
                    Calendar dateTime = Calendar.getInstance();
                    int i = dateTime.get(Calendar.YEAR);
                    queryWrapper.ge("create_date", i);
                    writeProtDataVos = writeProtDataMapper.listWriteYear(queryWrapper);
                } else {
                    if ("4".equals(type)) {
                        startTime = startTime + " 00:00:00";
                        endTime = endTime + " 23:59:59";
                        queryWrapper.between("create_date", startTime, endTime);
                    } else if ("2".equals(type)) {
                        Date timesMonthmorning = DataUill.getTimesMonthmorning();
                        queryWrapper.ge("create_date", timesMonthmorning);
                    } else if ("1".equals(type)) {
                        Calendar calendar = Calendar.getInstance();
                        calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 7);
                        Date dateTime = calendar.getTime();
                        queryWrapper.ge("create_date", dateTime);
                    }
                    writeProtDataVos = writeProtDataMapper.listWrite(queryWrapper);
                }
                for (WriteProtDataVo writeProtDataVo : writeProtDataVos) {
                    ProCountVo proCountVo = new ProCountVo();
                    proCountVo.setValue(writeProtDataVo.getFlow());
                    proCountVo.setCreateDate(writeProtDataVo.getCreateDate());
                    if (writeProtDataVo.getLoctionType().equals("1")) {
                        proCountVo.setLoctionType("1");
                        inList.add(proCountVo);
                    }
                    if (writeProtDataVo.getLoctionType().equals("2")) {
                        proCountVo.setLoctionType("2");
                        dealList.add(proCountVo);
                    }
                    if (writeProtDataVo.getLoctionType().equals("3")) {
                        proCountVo.setLoctionType("3");
                        outList.add(proCountVo);
                    }
                }
                proCountDto.setInList(inList);
                proCountDto.setDealList(dealList);
                proCountDto.setOutList(outList);
            }
        }
        return new Result(ResultCode.SUCCESS, proCountDto);
    }

    @Override
    public Result listProt(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {

        String farmId = paramsMap.get("farmId");
        QueryWrapper<ProtWarningInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("farm_id", farmId).orderByDesc("date").last(" limit 10");
        List<ProtWarningInfo> protWarningInfos = protWarningInfoMapper.selectList(queryWrapper);
        //今日
        Date timesmorning = DataUill.getTimesmorning();
        //本周
        DateTime dateTime = DateUtil.beginOfWeek(new Date());

        //本月
        Date timesMonthmorning = DataUill.getTimesMonthmorning();

        List<ProDataVo> voList = new LinkedList<>();
        for (int i = 0; i < protWarningInfos.size(); i++) {
            ProDataVo proDataVo = new ProDataVo();
            proDataVo.setContent(protWarningInfos.get(i).getWarningContent());
            proDataVo.setTime(protWarningInfos.get(i).getDate());
            voList.add(proDataVo);
        }
        QueryWrapper<ProtWarningInfo> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("farm_id", farmId).ge("date", timesmorning);
        Integer dayCount = protWarningInfoMapper.selectCount(queryWrapper1);

        QueryWrapper<ProtWarningInfo> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("farm_id", farmId).ge("date", dateTime);
        Integer weekCount = protWarningInfoMapper.selectCount(queryWrapper2);

        QueryWrapper<ProtWarningInfo> queryWrapper3 = new QueryWrapper<>();
        queryWrapper3.eq("farm_id", farmId).ge("date", timesMonthmorning);
        Integer monthCount = protWarningInfoMapper.selectCount(queryWrapper3);

        QueryWrapper<ProtWarningInfo> queryWrapper4 = new QueryWrapper<>();
        queryWrapper4.eq("farm_id", farmId);
        Integer count = protWarningInfoMapper.selectCount(queryWrapper4);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("dayCount", dayCount);
        jsonObject.put("weekCount", weekCount);
        jsonObject.put("monthCount", monthCount);
        jsonObject.put("count", count);
        jsonObject.put("data", voList);


        return new Result(ResultCode.SUCCESS, jsonObject);
    }

    @Override
    public Result listType(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        String displayType = paramsMap.get("displayType");
        if ("".equals(displayType) || null == displayType) {
            displayType = "0";
        }
        JSONObject jsonObject = new JSONObject();
        if ("0".equals(displayType)) {
            QueryWrapper<ProtData> queryWrapper = new QueryWrapper<>();
            // ProCountDto proCountDto = new ProCountDto();
            queryWrapper.eq("farm_id", farmId).eq("loction_type", 1).orderByDesc("create_date").last(" limit 1");
            ProtData protData = protDataMapper.selectOne(queryWrapper);
            if (ObjectUtil.isEmpty(protData)) {
                jsonObject.put("in", getWriteProtData() );
            } else {
                jsonObject.put("in", protData);
            }


            QueryWrapper<ProtData> queryWrapper1 = new QueryWrapper<>();
            queryWrapper1.eq("farm_id", farmId).eq("loction_type", 2).orderByDesc("create_date").last(" limit 1");
            ProtData protData1 = protDataMapper.selectOne(queryWrapper1);
            if (ObjectUtil.isEmpty(protData1)) {
                jsonObject.put("deal", getWriteProtData() );
            } else {
                jsonObject.put("deal", protData1);
            }


            QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
            queryWrapper2.eq("farm_id", farmId).eq("loction_type", 3).orderByDesc("create_date").last(" limit 1");
            ProtData protData2 = protDataMapper.selectOne(queryWrapper2);
            if (ObjectUtil.isEmpty(protData2)) {
                jsonObject.put("out", getWriteProtData() );
            } else {
                jsonObject.put("out", protData2);
            }

        } else {
            QueryWrapper<WriteProtData> queryWrapper = new QueryWrapper<>();
            // ProCountDto proCountDto = new ProCountDto();
            queryWrapper.eq("farm_id", farmId).eq("type", 1).orderByDesc("create_date").last(" limit 1");
            WriteProtData writeProtData = writeProtDataMapper.selectOne(queryWrapper);
            if (ObjectUtil.isEmpty(writeProtData)) {
                jsonObject.put("in", getWriteProtData() );
            } else {
                jsonObject.put("in", writeProtData);
            }

            QueryWrapper<WriteProtData> queryWrapper1 = new QueryWrapper<>();
            queryWrapper1.eq("farm_id", farmId).eq("type", 2).orderByDesc("create_date").last(" limit 1");
            WriteProtData writeProtData1 = writeProtDataMapper.selectOne(queryWrapper1);
            if (ObjectUtil.isEmpty(writeProtData1)) {
                jsonObject.put("deal", getWriteProtData() );
            } else {
                jsonObject.put("deal", writeProtData1);
            }

            QueryWrapper<WriteProtData> queryWrapper2 = new QueryWrapper<>();
            queryWrapper2.eq("farm_id", farmId).eq("type", 3).orderByDesc("create_date").last(" limit 1");
            WriteProtData writeProtData2 = writeProtDataMapper.selectOne(queryWrapper2);
            if (ObjectUtil.isEmpty(writeProtData2)) {
                jsonObject.put("out",getWriteProtData() );
            } else {
                jsonObject.put("out", writeProtData2);
            }

        }

        return new Result(ResultCode.SUCCESS, jsonObject);
    }

    private  WriteProtData getWriteProtData() {
      return new WriteProtData("0","0","0","0","0","0");
    }

    @Override
    public Result listScreen(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        Date timesmorning = DataUill.getTimesmorning();
        String farmId = paramsMap.get("farmId");
        QueryWrapper<ProtData> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("farm_id", farmId).ge("create_date", timesmorning);
        Integer count = protDataMapper.selectCount(queryWrapper);//监测数据条数
        QueryWrapper<ProtWarningInfo> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("farm_id", farmId);
        Integer count1 = protWarningInfoMapper.selectCount(queryWrapper1);//全年报警条数
        queryWrapper1.ge("date", timesmorning);
        Integer countDay = protWarningInfoMapper.selectCount(queryWrapper1);//今日报警条数

        QueryWrapper<ProdFermentDevice> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("farm_id", farmId);
        Integer day = fermentDeviceMapper.selectCount(queryWrapper2);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("locCount", 27);
        jsonObject.put("ProtCount", count);
        jsonObject.put("WarningCount", countDay);
        jsonObject.put("day", day);
        jsonObject.put("flowCount", count1);
        return new Result(ResultCode.SUCCESS, jsonObject);
    }

    @Override
    public Result listFlowScreen(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");

        QueryWrapper<ProtData> protDataQueryWrapper = new QueryWrapper<>();
        ArrayList<Map> maps = new ArrayList<>();
        Date now = new Date();
        for (int i = 8; i >=0 ; i--) {
            DateTime dateTime = DateUtil.offsetDay(now, -i);
            HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
            ProtData protData = getListFlowScreenWrapper(protDataQueryWrapper,1,dateTime,farmId);
            objectObjectHashMap.put("createDate",protData.getCreateDate());
            ProtData protData2 = getListFlowScreenWrapper(protDataQueryWrapper,2,dateTime,farmId);
            ProtData protData3 = getListFlowScreenWrapper(protDataQueryWrapper,3,dateTime,farmId);
            objectObjectHashMap.put("in",ObjectUtil.isEmpty(protData) ? "0": protData.getFlow());
            objectObjectHashMap.put("deal",ObjectUtil.isEmpty(protData2) ? "0": protData2.getFlow());
            objectObjectHashMap.put("out",ObjectUtil.isEmpty(protData3) ? "0": protData3.getFlow());
           maps.add(objectObjectHashMap);
        }
        return new Result(ResultCode.SUCCESS,maps);
    }

    @Override
    public Result listAllScreen(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        QueryWrapper<ProtData> queryWrapper = new QueryWrapper<ProtData>();
        Date date = new Date();
        List<ProtData> list   = new ArrayList();
        for (int i = 0; i < 8; i++) {
            DateTime dateTime = DateUtil.offsetDay(date, -i);
            queryWrapper.clear();
            queryWrapper.eq("farm_id", farmId);
            queryWrapper.select("create_date,MAX(CAST(ph AS DECIMAL(10,3) )) ph , MAX(CAST(cod AS DECIMAL(10,2) )) cod, MAX(CAST(NH3N AS DECIMAL(10,3) )) NH3N " +
                    ",MAX(CAST(other2 AS DECIMAL(10,3) )) other2 ");
            queryWrapper.between("create_date",DateUtil.beginOfDay(dateTime),DateUtil.endOfDay(dateTime));
            ProtData protData = protDataMapper.selectOne(queryWrapper);
            if (ObjectUtil.isEmpty(protData)){
                protData = new ProtData();
                protData.setPh("0");
                protData.setOther2("0");
                protData.setNh3n("0");
                protData.setCod("0");
                protData.setCreateDate(dateTime);
            }
            list.add(protData);
        }
        return new Result(ResultCode.SUCCESS,list);
    }

    private ProtData getListFlowScreenWrapper(QueryWrapper<ProtData> protDataQueryWrapper, int loctionType ,DateTime dateTime,String farmId) {
        protDataQueryWrapper.clear();
        protDataQueryWrapper.eq("farm_id",farmId);
        protDataQueryWrapper.between("create_date",DateUtil.beginOfDay(dateTime),DateUtil.endOfDay(dateTime));
        protDataQueryWrapper.eq("loction_type",loctionType);
        protDataQueryWrapper.orderByDesc("id").last("limit 1");
        return   this.getOne(protDataQueryWrapper);
    }

//    @Override
//    public Result listFlowScreen(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
//        QueryWrapper<ProtData> queryWrapper = new QueryWrapper<>();
//        Calendar calendar = Calendar.getInstance();
//        calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 7);
//        Date dateTime = calendar.getTime();
//
//        queryWrapper.ge("create_date", dateTime);
//        queryWrapper.eq("loction_type", 1);
//        List<ProCountVo> protData1 = protDataMapper.listFlow(queryWrapper);
//        proCountDto.setInList(protData1);
//
//        QueryWrapper<ProtData> queryWrapper2 = new QueryWrapper<>();
//        queryWrapper2.eq("farm_id", farmId).ge("create_date", dateTime);
//        queryWrapper2.eq("loction_type", 2);
//        List<ProCountVo> protData2 = protDataMapper.listFlow(queryWrapper2);
//        proCountDto.setDealList(protData2);
//
//        QueryWrapper<ProtData> queryWrapper3 = new QueryWrapper<>();
//        queryWrapper3.eq("farm_id", farmId).ge("create_date", dateTime);
//        queryWrapper3.eq("loction_type", 3);
//        List<ProCountVo> protData3 = protDataMapper.listFlow(queryWrapper3);
//        proCountDto.setOutList(protData3);
//    }


}
