package io.renren.modules.snoop.controller;

import io.renren.common.utils.PageUtils;
import io.renren.modules.snoop.entity.SnoopAndSnoopValueEntity;
import io.renren.modules.snoop.entity.SnoopEntity;
import io.renren.modules.snoop.entity.SnoopValueEntity;
import io.renren.modules.snoop.service.SnoopService;
import io.renren.modules.sys.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.renren.common.utils.R;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/snoop")
public class SnoopController extends AbstractController {

    @Autowired
    private SnoopService snoopService;

    /**
     * 根据名称进行搜索
     */
    @RequestMapping("/selectByName")
    public R selectByName(@RequestParam(defaultValue = "1") Integer page,
                          @RequestParam(defaultValue = "100") Integer size,
                          @RequestParam(value = "name") String name){

        List<SnoopEntity> snoopEntityList = snoopService.selectByName(page, size, name);
        Integer total = snoopService.getCountByName(name);
        return R.ok().put("count", total).put("snoopList", snoopEntityList);
    }

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

    /**
     * 删除探查
     */
    @RequestMapping("/delete/{measureID}")
    public R delete(@PathVariable("measureID") Integer snoopIds){
        snoopService.deleteBatch(snoopIds);
        return R.ok();
    }

    /**
     * 增加探查
     * snoopEntity：探查名、备注、Hbase表名
     * snoopValueEntityList[i]：探查哪一列、探查该列的哪种类型
     */
    @RequestMapping("/save")
    public R save(@RequestBody SnoopAndSnoopValueEntity snoopAndSnoopValueEntity){

        snoopAndSnoopValueEntity.getHbaseName();
        snoopAndSnoopValueEntity.getRemark();
        snoopService.saveMeasure(snoopAndSnoopValueEntity);
        return R.ok();
    }
}
