package com.huimv.eartag.controller;

import com.huimv.eartag.service.IEartagManageService;
import com.huimv.eartag.utils.DateUtil;
import com.huimv.eartag.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * @Project : huimv.shiwan
 * @Package : com.huimv.biosafety.uface.controller
 * @Description : TODO
 * @Version : 1.0
 * @Author : ZhuoNing
 * @Create : 2020-12-25
 **/
@CrossOrigin
@RestController
@RequestMapping(value = "/eartag")
@Slf4j
public class EartagManageController {
    @Autowired
    private IEartagManageService eartagService;

    /**
     * @Method      : listEartagOnlineAllStatus
     * @Description : 显示耳标前N天在线记录
     * @Params      : [farmId, days]
     * @Return      : com.huimv.eartag2.common.utils.Result
     *
     * @Author      : ZhuoNing
     * @Date        : 2022/3/30
     * @Time        : 20:04
     */
    @RequestMapping(value = "/listManyEartagOnlineStatus",method = RequestMethod.GET)
    public Result listManyEartagOnlineStatus(@RequestParam(value = "farmId",required = true) String farmId, @RequestParam(value = "days",required = true) Integer days) throws ParseException {
        log.info("<listManyDaysAllStatus>输入参数 farmId>>"+farmId);
        log.info("<listManyDaysAllStatus>输入参数 days>>"+days);
        if(days == null){
            //默认7天数据
            days = 7;
        }
        //{}
        return eartagService.listManyEartagOnlineStatus(farmId,days);
    }

    /**
     * @Method      : getEartagRegisterByEarmark
     * @Description : 读取耳标注册信息，设备在线页面调用
     * @Params      : [earmark]
     * @Return      : com.huimv.eartag2.common.utils.Result
     *
     * @Author      : ZhuoNing
     * @Date        : 2022/3/7
     * @Time        : 18:39
     */
    @RequestMapping(value = "/getEartagRegisterByEarmark",method = RequestMethod.GET)
    public Result getEartagRegisterByEarmark(@RequestParam(value = "earmark",required = true) String earmark) throws ParseException {
        log.info("<getEartagRegisterByEarmark> 输入参数earmark>>"+earmark);
        //
        return eartagService.getEartagRegisterByEarmark(earmark);
    }

    /**
     * @Method      : getEartagFlowByEarmarkAndToday
     * @Description :读取耳标今天所有耳标流水，设备在线页面调用
     * @Params      : [earmark]
     * @Return      : com.huimv.eartag2.common.utils.Result
     *
     * @Author      : ZhuoNing
     * @Date        : 2022/3/7
     * @Time        : 18:41
     */
    @RequestMapping(value = "/listEartagFlowByEarmarkAndToday",method = RequestMethod.GET)
    public Result listEartagFlowByEarmarkAndToday(@RequestParam(value = "earmark",required = true) String earmark) throws ParseException {
        log.info("<listEartagFlowByEarmarkAndToday> 输入参数 earmark>>"+earmark);
        //
        return eartagService.listEartagFlowByEarmarkAndToday(earmark);
    }

    /**
     * @Method      : listEartagFlowByEarmarkAndTodayInPager
     * @Description :
     * @Params      : [earmark, pageNo, pageSize]
     * @Return      : com.huimv.eartag2.common.utils.Result
     *
     * @Author      : ZhuoNing
     * @Date        : 2022/3/8
     * @Time        : 20:18
     */
    @RequestMapping(value = "/listEartagFlowByEarmarkAndTodayInPager",method = RequestMethod.GET)
    public Result listEartagFlowByEarmarkAndTodayInPager(@RequestParam(value = "earmark",required = true) String earmark,
                                                         @RequestParam(value = "pageNo",required = true) Integer pageNo,
                                                         @RequestParam(value = "pageSize",required = true) Integer pageSize,
                                                         @RequestParam(value = "createDate",required = false) String createDate,
                                                         @RequestParam(value = "deviceCode",required = false) String deviceCode) throws ParseException {
        log.info("<listEartagFlowByEarmarkAndTodayInPager> 输入参数 earmark>>"+earmark);
        log.info("<listEartagFlowByEarmarkAndTodayInPager> 输入参数 pageNo>>"+pageNo);
        log.info("<listEartagFlowByEarmarkAndTodayInPager> 输入参数 pageSize>>"+pageSize);
        log.info("<listEartagFlowByEarmarkAndTodayInPager> 输入参数 createDate>>"+createDate);
        log.info("<listEartagFlowByEarmarkAndTodayInPager> 输入参数 deviceCode>>"+deviceCode);
        if(createDate == null || createDate.trim().length() == 0){
            createDate = new DateUtil().getTodayDateText();
        }
        //
        return eartagService.listEartagFlowByEarmarkAndTodayInPager(earmark,pageNo,pageSize,createDate,deviceCode);
    }

    /**
     * @Method      : listEartagFlowByDeviceCodeAndEarmarkAndToday
     * @Description : 读取设备下和该耳标今天所有耳标流水，设备在线页面调用
     * @Params      : [earmark, deviceCode]
     * @Return      : com.huimv.eartag2.common.utils.Result
     *
     * @Author      : ZhuoNing
     * @Date        : 2022/3/7
     * @Time        : 18:56
     */
    @RequestMapping(value = "/listEartagFlowByDeviceCodeAndEarmarkAndToday",method = RequestMethod.GET)
    public Result listEartagFlowByDeviceCodeAndEarmarkAndToday(@RequestParam(value = "earmark",required = true) String earmark,
                                                               @RequestParam(value = "deviceCode",required = true) String deviceCode) throws ParseException {
        log.info("<listEartagFlowByDeviceCodeAndEarmarkAndToday> 输入参数 earmark>>"+earmark);
        log.info("<listEartagFlowByDeviceCodeAndEarmarkAndToday> 输入参数 deviceCode>"+deviceCode);
        //
        return eartagService.listEartagFlowByDeviceCodeAndEarmarkAndToday(earmark,deviceCode);
    }

    /**
     * @Method      : listEartagFlowByDeviceCodeAndEarmarkAndToday
     * @Description : 读取设备下和该耳标今天所有耳标流水，设备在线页面调用（分页）
     * @Params      : [earmark, deviceCode]
     * @Return      : com.huimv.eartag2.common.utils.Result
     *
     * @Author      : ZhuoNing
     * @Date        : 2022/3/7
     * @Time        : 18:56
     */
    @RequestMapping(value = "/listEartagFlowByDeviceCodeAndEarmarkAndDateInPager",method = RequestMethod.GET)
    public Result listEartagFlowByDeviceCodeAndEarmarkAndDateInPager(@RequestParam(value = "earmark",required = true) String earmark,
                                                                     @RequestParam(value = "deviceCode",required = true) String deviceCode,
                                                                     @RequestParam(value = "addDate",required = false) String addDate,
                                                                     @RequestParam(value = "pageNo",required = true) Integer pageNo,
                                                                     @RequestParam(value = "pageSize",required = true) Integer pageSize) throws ParseException {
        log.info("<listEartagFlowByDeviceCodeAndEarmarkAndDateInPager> 输入参数 earmark>>"+earmark);
        log.info("<listEartagFlowByDeviceCodeAndEarmarkAndDateInPager> 输入参数 deviceCode>"+deviceCode);
        log.info("<listDeviceEnvtempByDeviceCodeInPager>输入参数 addDate>>"+addDate);
        log.info("<listDeviceEnvtempByDeviceCodeInPager>输入参数 pageNo>>"+pageNo);
        log.info("<listDeviceEnvtempByDeviceCodeInPager>输入参数 pageSize>>"+pageSize);
        //
        if(addDate == null){
            addDate  =  new DateUtil().getTodayDateText();
        }
        //
        return eartagService.listEartagFlowByDeviceCodeAndEarmarkAndDateInPager(earmark,deviceCode,addDate,pageNo,pageSize);
    }

    /**
     * @Method      : listEartagFlowByDeviceCodeAndEarmarkAndTodayInPager
     * @Description : 读取设备下和该耳标今天所有耳标流水，设备在线页面调用（分页）
     * @Params      : [earmark, deviceCode]
     * @Return      : com.huimv.eartag2.common.utils.Result
     *
     * @Author      : ZhuoNing
     * @Date        : 2022/3/8
     * @Time        : 20:34
     */
    @RequestMapping(value = "/listEartagFlowByDeviceCodeAndEarmarkAndTodayInPager",method = RequestMethod.GET)
    public Result listEartagFlowByDeviceCodeAndEarmarkAndTodayInPager(@RequestParam(value = "earmark",required = true) String earmark,
                                                                      @RequestParam(value = "deviceCode",required = true) String deviceCode,
                                                                      @RequestParam(value = "createDate",required = true) String createDate,
                                                                      @RequestParam(value = "pageNo",required = true) Integer pageNo,
                                                                      @RequestParam(value = "pageSize",required = true) Integer pageSize) throws ParseException {
        log.info("<listEartagFlowByDeviceCodeAndEarmarkAndTodayInPager> 输入参数 earmark>>"+earmark);
        log.info("<listEartagFlowByDeviceCodeAndEarmarkAndTodayInPager> 输入参数 deviceCode>"+deviceCode);
        log.info("<listEartagFlowByDeviceCodeAndEarmarkAndTodayInPager> 输入参数 createDate>"+createDate);
        log.info("<listEartagFlowByDeviceCodeAndEarmarkAndTodayInPager> 输入参数 pageNo>>"+pageNo);
        log.info("<listEartagFlowByDeviceCodeAndEarmarkAndTodayInPager> 输入参数 pageSize>>"+pageSize);
        if(createDate == null || createDate.trim().length() == 0){
            createDate = new DateUtil().getTodayDateText();
        }
        //
        return eartagService.listEartagFlowByDeviceCodeAndEarmarkAndTodayInPager(earmark,deviceCode,createDate,pageNo,pageSize);
    }

    /**
     * @Method      : listEartagOnlineCountByEarmarkAndDate
     * @Description : 显示耳标在线统计
     * @Params      : [earmark, pastDays]
     * @Return      : com.huimv.eartag2.common.utils.Result
     *
     * @Author      : ZhuoNing
     * @Date        : 2022/3/8
     * @Time        : 18:28
     */
    @RequestMapping(value = "/listEartagOnlineCountByEarmarkAndDate",method = RequestMethod.GET)
    public Result listEartagCountByEarmarkAndDate(@RequestParam(value = "earmark",required = true) String earmark,
                                                  @RequestParam(value = "pastDays",required = true) Integer pastDays,
                                                  @RequestParam(value = "showMode",required = true) Integer showMode) throws ParseException {
        log.info("<listEartagOnlineCountByEarmarkAndDate> 输入参数 earmark>>"+earmark);
        log.info("<listEartagOnlineCountByEarmarkAndDate> 输入参数 pastDays>"+pastDays);
        log.info("<listEartagOnlineStatusByEarmarkAndDate> 输入参数 showMode>"+showMode);
        if(showMode == null){
            showMode = 1;
        }
        //
        return eartagService.listEartagOnlineCountByEarmarkAndDate(earmark,pastDays,showMode);
    }

    /**
     * @Method      : listEartagOnlineStatusByEarmarkAndDate
     * @Description : 显示耳标在线状态
     * @Params      : [earmark, pastDays]
     * @Return      : com.huimv.eartag2.common.utils.Result
     *
     * @Author      : ZhuoNing
     * @Date        : 2022/3/8
     * @Time        : 19:52
     */
    @RequestMapping(value = "/listEartagOnlineStatusByEarmarkAndDate",method = RequestMethod.GET)
    public Result listEartagOnlineStatusByEarmarkAndDate(@RequestParam(value = "earmark",required = true) String earmark,
                                                         @RequestParam(value = "pastDays",required = true) Integer pastDays) throws ParseException {
        log.info("<listEartagOnlineStatusByEarmarkAndDate> 输入参数 earmark>>"+earmark);
        log.info("<listEartagOnlineStatusByEarmarkAndDate> 输入参数 pastDays>"+pastDays);
        //
        return eartagService.listEartagOnlineStatusByEarmarkAndDate(earmark,pastDays);
    }

    /**
     * @Method      : listEartagOnlineAllStatus
     * @Description : 前N天耳标在线状态
     * @Params      : [farmId, days]
     * @Return      : com.huimv.eartag2.common.utils.Result
     *
     * @Author      : ZhuoNing
     * @Date        : 2022/3/10
     * @Time        : 20:43
     */
    @RequestMapping(value = "/listEartagOnlineAllStatus",method = RequestMethod.GET)
    public Result listEartagOnlineAllStatus(@RequestParam(value = "farmId",required = true) String farmId,
                                            @RequestParam(value = "days",required = true) Integer days) throws ParseException {
        log.info("<listEartagOnlineAllStatus>输入参数 farmId>>"+farmId);
        log.info("<listEartagOnlineAllStatus>输入参数 days>>"+days);
        if(days == null){
            //默认7天数据
            days = 7;
        }
        //
        return eartagService.listEartagOnlineAllStatus(farmId,days);
    }

    /**
     * @Method      : listEartagOnlineCount
     * @Description : 列表展示某一天的在线记录
     * @Params      : [farmId, addDate, pageNo, pageSize]
     * @Return      : com.huimv.eartag2.common.utils.Result
     *
     * @Author      : ZhuoNing
     * @Date        : 2022/3/10
     * @Time        : 21:50
     */
    @RequestMapping(value = "/listOnlineEartagCount",method = RequestMethod.GET)
    public Result listEartagOnlineCount(@RequestParam(value = "farmId",required = true) String farmId,
                                        @RequestParam(value = "addDate",required = false) String addDate,
                                        @RequestParam(value = "pageNo",required = true) Integer pageNo,
                                        @RequestParam(value = "pageSize",required = true) Integer pageSize,
                                        @RequestParam(value = "showMode",required = true) Integer showMode) throws ParseException {
        log.info("<listOnlineEartagCount>输入参数 farmId>>"+farmId);
        log.info("<listOnlineEartagCount>输入参数 addDate>>"+addDate);
        log.info("<listOnlineEartagCount>输入参数 pageNo>>"+pageNo);
        log.info("<listOnlineEartagCount>输入参数 pageSize>>"+pageSize);
        log.info("<listOnlineEartagCount>输入参数 showMode>>"+showMode);
        if(addDate == null || addDate.trim().length() == 0){
            addDate = new DateUtil().getTodayDateText();
        }
        //
        return eartagService.listOnlineEartagCount(farmId,addDate,pageNo,pageSize,showMode);
    }

    /**
     * @Method      : listEartagDeviceByEarmarkAndAddDate
     * @Description : 根据耳标和日期，查询关联设备记录
     * @Params      : [earmark, addDate]
     * @Return      : com.huimv.eartag2.common.utils.Result
     *
     * @Author      : ZhuoNing
     * @Date        : 2022/3/10
     * @Time        : 22:33
     */
    @RequestMapping(value = "/listEartagDeviceByEarmarkAndAddDate",method = RequestMethod.GET)
    public Result listEartagDeviceByEarmarkAndAddDate(@RequestParam(value = "earmark",required = true) String earmark,
                                                      @RequestParam(value = "addDate",required = false) String addDate) throws ParseException {
        log.info("<listEartagDeviceByEarmarkAndAddDate>输入参数 earmark>>"+earmark);
        log.info("<listEartagDeviceByEarmarkAndAddDate>输入参数 addDate>>"+addDate);
        if(addDate == null || addDate.trim().length() == 0){
            addDate = new DateUtil().getTodayDateText();
        }
        //
        return eartagService.listEartagDeviceByEarmarkAndAddDate(earmark,addDate);
    }

    /**
     * @Method      : listAllEartagRegister
     * @Description : 展示所有耳标注册列表
     * @Params      : [farmId]
     * @Return      : com.huimv.eartag2.common.utils.Result
     *
     * @Author      : ZhuoNing
     * @Date        : 2022/3/11
     * @Time        : 9:35
     */
    @RequestMapping(value = "/listAllEartagRegister",method = RequestMethod.GET)
    public Result listAllEartagRegister(@RequestParam(value = "farmId",required = true) String farmId,
                                        @RequestParam(value = "earmark",required = false) String earmark,
                                        @RequestParam(value = "activeStatus",required = false) Integer activeStatus,
                                        @RequestParam(value = "liveStatus",required = false) Integer liveStatus,
                                        @RequestParam(value = "registerType",required = false) Integer registerType,
                                        @RequestParam(value = "startDate",required = false) String startDate,
                                        @RequestParam(value = "endDate",required = false) String endDate,
                                        @RequestParam(value = "pageNo",required = true) Integer pageNo,
                                        @RequestParam(value = "pageSize",required = true) Integer pageSize) throws ParseException {
        log.info("<listAllEartagRegister> 输入参数 farmId>>"+farmId);
        log.info("<listAllEartagRegister> 输入参数 earmark>>"+earmark);
        log.info("<listAllEartagRegister> 输入参数 activeStatus>>"+activeStatus);
        log.info("<listAllEartagRegister> 输入参数 liveStatus>>"+liveStatus);
        log.info("<listAllEartagRegister> 输入参数 registerType>>"+registerType);
        log.info("<listAllEartagRegister> 输入参数 startDate>>"+startDate);
        log.info("<listAllEartagRegister> 输入参数 endDate>>"+endDate);
        log.info("<listAllEartagRegister> 输入参数 pageNo>>"+pageNo);
        log.info("<listAllEartagRegister> 输入参数 pageSize>>"+pageSize);
        //
        return eartagService.listAllEartagRegister(farmId,earmark,activeStatus,liveStatus,registerType,startDate,endDate,pageNo,pageSize);
    }

    /**
     * @Method      : listAllEartagFlow
     * @Description : 展示所有流水列表
     * @Params      : [farmId, createDate, deviceCode, earmark, pageNo, pageSize]
     * @Return      : com.huimv.eartag2.common.utils.Result
     *
     * @Author      : ZhuoNing
     * @Date        : 2022/3/11
     * @Time        : 20:29
     */
    @RequestMapping(value = "/listAllEartagFlow",method = RequestMethod.GET)
    public Result listAllEartagFlow(@RequestParam(value = "farmId",required = true) String farmId,
                                    @RequestParam(value = "createDate",required = false) String createDate,
                                    @RequestParam(value = "deviceCode",required = false) String deviceCode,
                                    @RequestParam(value = "earmark",required = false) String earmark,
                                    @RequestParam(value = "pageNo",required = true) Integer pageNo,
                                    @RequestParam(value = "pageSize",required = true) Integer pageSize) throws ParseException {
        log.info("<listAllEartagRegister> 输入参数 farmId>>"+farmId);
        log.info("<listAllEartagRegister> 输入参数 createDate>>"+createDate);
        log.info("<listAllEartagRegister> 输入参数 deviceCode>>"+deviceCode);
        log.info("<listAllEartagRegister> 输入参数 earmark>>"+earmark);
        log.info("<listAllEartagRegister> 输入参数 pageNo>>"+pageNo);
        log.info("<listAllEartagRegister> 输入参数 pageSize>>"+pageSize);
        if(createDate == null || createDate.trim().length() == 0){
            createDate = new DateUtil().getTodayDateText();
        }
        //{}
        return eartagService.listAllEartagFlow(farmId,createDate,deviceCode,earmark,pageNo,pageSize);
    }
}
