package com.huimv.acquisition.controller;

import com.huimv.acquisition.entity.EartagDataEntity;
import com.huimv.acquisition.entity.vo.EartagParamVo;
import com.huimv.acquisition.mapper.EartagDataDao;
import com.huimv.acquisition.result.R;
import com.huimv.acquisition.service.EartagDataService;
import com.huimv.acquisition.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.Arrays;
import java.util.Map;

/**
 * @author yinhao
 * @version ${version}
 * @date 2021-07-24 16:29:33
 */
@RestController
@RequestMapping("/eartagdata")
@CrossOrigin
public class EartagDataController {
    @Autowired
    private EartagDataService eartagDataService;

    @Autowired
    private EartagDataDao eartagDataDao;







    /**
     * 首页的数据
     */
    @RequestMapping("/listIndexNew")
    public R listIndexNew(@RequestParam Map<String, Object> params) {
        PageUtils page = eartagDataService.queryPage(params);
        return R.ok().put("page", page);
    }



    /**
     * 首页的数据
     */
    @GetMapping("/sout")
    public R sout(@RequestParam Map<String, Object> params) {
        System.out.println("test");
        return R.ok().put("page", "121");
    }







    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = eartagDataService.queryPage(params);
        return R.ok().put("page", page);
    }



    //根据耳标电量查询
    @RequestMapping("/findByConditions")
    public R findByFarmId( @RequestParam Map<String, Object> params  ) throws ParseException {
        PageUtils byConditions = eartagDataService.findByConditions(params);
        return R.ok().put("page", byConditions);
    }


    @RequestMapping("/list_deatils")
    public R listDeatils(@RequestParam Map<String, Object> params) throws ParseException {
        Map queryDetailsMap = eartagDataService.queryDetails(params);
        return R.ok().put("page", queryDetailsMap);
    }



    /**
     * 列表  耳标个体数据----杭电展示专用--耳标写死了的
     */
    @RequestMapping("/listEartagDeatils")
    public R listEartagDeatils( @RequestBody EartagParamVo eartagParamVo) throws ParseException {
        System.out.println(eartagParamVo.toString());
        System.out.println("ceshi");
        Map  map = eartagDataService.queryEartagDeatils(eartagParamVo);
        System.out.println(eartagParamVo.toString());
        return R.ok().put("data", map);
    }



    

    @RequestMapping("/list_deatils_byeartagno")
    public R listDeatils01(@RequestParam Map<String, Object> params) throws ParseException {
        Map queryDetailsMap = eartagDataService.queryDetailsByEarTag(params);
        return R.ok().put("page", queryDetailsMap);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        EartagDataEntity eartagData = eartagDataService.getById(id);
        return R.ok().put("eartagData", eartagData);
    }



    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody EartagDataEntity eartagData) {
        eartagDataService.save(eartagData);
        return R.ok();
    }


    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody EartagDataEntity eartagData) {
        eartagDataService.updateById(eartagData);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids) {
        eartagDataService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
