package com.bonus.bracelet.controller;

import com.bonus.bracelet.service.IBraceletService;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.entity.bracelet.vo.*;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.annotation.RequiresPermissions;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * BraceletController 手环管理
 */
@RestController
@RequestMapping("/bracelet/")
@Slf4j
public class BraceletController extends BaseController {

    @Resource(name = "IBraceletService")
    private IBraceletService braceletservice;


    /**
     * 展示手环列表
     * @param data
     * @return
     */
    @GetMapping("list")
    @SysLog(title = "手环管理", businessType = OperaType.QUERY,  module = "基础管理->手环管理", details = "查询手环列表")
    public TableDataInfo list(BraceletVo data) {
        startPage();
        List<BraceletVo> list = braceletservice.getBraceletLists(data);
        return getDataTable(list);
    }

    /**
     * 展示手环箱绑定手环列表
     * @param data
     * @return
     */
    @GetMapping("listShBind")
    @SysLog(title = "手环管理", businessType = OperaType.QUERY,  module = "基础管理->手环管理", details = "查询手环箱绑定手环列表")
    public TableDataInfo listShBind(BraceletVo data) {
        startPage();
        List<BraceletVo> list = braceletservice.getShBindLists(data);
        return getDataTable(list);
    }

    /**
     * 展示未绑定手环列表
     * @param data
     * @return
     */
    @GetMapping("listShNoBind")
    @SysLog(title = "手环管理", businessType = OperaType.QUERY,  module = "基础管理->手环管理", details = "查询未绑定手环列表")
    public TableDataInfo listShNoBind(BraceletVo data) {
        startPage();
        List<BraceletVo> list = braceletservice.getShBindNoLists(data);
        return getDataTable(list);
    }


    /**
     * 展示手环箱列表
     * @param data
     * @return
     */
    @GetMapping("listShbox")
    @SysLog(title = "手环管理", businessType = OperaType.QUERY,  module = "基础管理->手环管理", details = "查询手环箱列表")
    public TableDataInfo listShbox(ShboxVo data) {
        startPage();
        List<ShboxVo> list = braceletservice.getShboxLists(data);
        return getDataTable(list);
    }

    /**
     * 展示手环箱管理页面手环箱列表
     * @param data
     * @return
     */
    @GetMapping("listShboxall")
    @SysLog(title = "手环管理", businessType = OperaType.QUERY,  module = "基础管理->手环管理", details = "查询手环箱管理页面手环箱列表")
    public TableDataInfo listShboxall(ShboxVo data) {
        startPage();
        List<ShboxVo> list = braceletservice.getShboxallLists(data);
        return getDataTable(list);
    }

    /**
     * 展示手环绑定选择列表
     * @param data
     * @return
     */
    @GetMapping("listShboxBind")
    @SysLog(title = "手环管理", businessType = OperaType.QUERY,  module = "基础管理->手环管理", details = "查询手环绑定选择列表")
    public TableDataInfo listShboxBind(ShboxVo data) {
        startPage();
        List<ShboxVo> list = braceletservice.getShboxBindLists(data);
        return getDataTable(list);
    }


    /**
     * 根据手环箱id获取详细信息
     */
//    @RequiresPermissions("bracelet:shbox:query")
    @GetMapping(value = "/{shboxId}")
    public AjaxResult getInfo(@PathVariable Integer shboxId) {
        return braceletservice.selectBoxById(shboxId);
    }

    /**
     * 根据手环箱id获取刷新详细信息
     */
//    @RequiresPermissions("bracelet:shbox:query")
    @GetMapping(value = "/new/{shboxId}")
    public AjaxResult getNewInfo(@PathVariable Integer shboxId) {
        return braceletservice.selectBoxNewById(shboxId);
    }


    /**
     * 新增手环信息
     * @param vo
     * @return
     */
    @PostMapping("addSh")
    @SysLog(title = "手环管理", businessType = OperaType.INSERT,  module = "基础管理->手环管理", details = "新增手环")
    public AjaxResult addSh(@Validated @RequestBody ShboxVo vo) {
        return braceletservice.addSh(vo);
    }

    /**
     * 新增设备属性信息
     * @param vo
     * @return
     */
    @PostMapping("addAttribute")
    @SysLog(title = "手环管理", businessType = OperaType.INSERT,  module = "基础管理->手环管理", details = "新增设备属性")
    public AjaxResult addAttribute(@Validated @RequestBody AttributeVo vo) {
        return braceletservice.addAttribute(vo);
    }


    /**
     * 新增手环箱信息
     * @param vo
     * @return
     */
    @PostMapping("addBox")
    @SysLog(title = "手环管理", businessType = OperaType.INSERT,  module = "基础管理->手环管理", details = "新增手环箱")
    public AjaxResult addBox(@Validated @RequestBody ShboxVo vo) {
        return braceletservice.addBox(vo);
    }



    /**
     * 手环绑定选择页面绑定手环信息
     * @param vo
     * @return
     */
    @PostMapping("addShBind")
    @SysLog(title = "手环管理", businessType = OperaType.INSERT,  module = "基础管理->手环管理", details = "绑定手环")
    public AjaxResult addShBind(@Validated @RequestBody ShboxVo vo) {
        return braceletservice.addShBind(vo);
    }

    /**
     * 修改手环信息
     * @param vo
     * @return
     */
    @PostMapping("editSh")
    @SysLog(title = "手环管理", businessType = OperaType.UPDATE, module = "基础管理->手环管理", details = "修改手环")
    public AjaxResult editSh(@Validated @RequestBody ShboxVo vo) {
        return braceletservice.editSh(vo);
    }

    /**
     * 修改手环箱信息
     * @param vo
     * @return
     */
    @PostMapping("editBox")
    @SysLog(title = "手环管理", businessType = OperaType.UPDATE, module = "基础管理->手环管理", details = "修改手环箱")
    public AjaxResult editBox(@Validated @RequestBody ShboxVo vo) {
        return braceletservice.editBox(vo);
    }

    /**
     * 删除手环
     */

    @PostMapping("delShById")
    @SysLog(title = "手环管理", businessType = OperaType.UPDATE,module = "基础管理->手环管理",details = "删除手环")
    public AjaxResult delShById(@RequestBody BraceletVo vo) {
            return braceletservice.delShById(vo.getShId());

    }

    /**
     * 删除手环箱
     */

    @PostMapping("delShboxById")
    @SysLog(title = "手环管理", businessType = OperaType.UPDATE,module = "基础管理->手环管理",details = "删除手环箱")
    public AjaxResult delShboxById(@RequestBody ShboxVo vo) {
        return braceletservice.delShboxById(vo.getShboxId());

    }

    /**
     * 解除绑定
     * @param vo
     * @return
     */
    @PostMapping("delSh")
    @SysLog(title = "手环管理", businessType = OperaType.QUERY, logType = 0, module = "基础管理->手环管理", details = "解除绑定")
    public AjaxResult delSh(@RequestBody BraceletVo vo) {
        return braceletservice.delSh(vo);
    }

    /**
     * 绑定手环
     */
    @PostMapping("bindSh")
    @SysLog(title = "手环管理", businessType = OperaType.UPDATE,module = "基础管理->手环管理")
    public AjaxResult bindSh(@RequestBody BraceletVo vo) {
        int shboxId = vo.getShboxId();
        return braceletservice.bindSh(shboxId,vo.getShIds());
    }

}
