package com.bonus.bracelet.controller;

import com.bonus.bracelet.service.ISidebandService;
import com.bonus.bracelet.service.ITeamMgeService;
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.BraceletParamsDto;
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.Date;
import java.util.List;
import java.util.Map;

/**
 * @className:SidebandController
 * @author:cwchen
 * @date:2024-07-29-10:36
 * @version:1.0
 * @description:边带管理-controller
 */
@RestController
@RequestMapping("/sideband/")
@Slf4j
public class SidebandController extends BaseController {

    @Resource(name = "ISidebandService")
    private ISidebandService sidebandservice;


    /**
     * 展示边带列表
     * @param data
     * @return
     */
    @GetMapping("list")
    @SysLog(title = "边带管理", businessType = OperaType.QUERY,  module = "施工管控->边带管理", details = "查询边带列表")
    public TableDataInfo list(SidebandVo data) {
        startPage();
        List<SidebandVo> list = sidebandservice.getSidebandLists(data);
        return getDataTable(list);
    }

    /**
     * 展示杆塔绑定设备列表
     * @param data
     * @return
     */
    @GetMapping("listDevice")
    @SysLog(title = "边带管理", businessType = OperaType.QUERY,  module = "施工管控->边带管理", details = "查询杆塔绑定设备列表")
    public TableDataInfo listDevice(SidebandDeviceVo data) {
        startPage();
        List<SidebandDeviceVo> list = sidebandservice.getDeviceLists(data);
        return getDataTable(list);
    }

    /**
     * 展示杆塔未绑定设备列表
     * @param data
     * @return
     */
    @GetMapping("listDeviceNoBind")
    @SysLog(title = "边带管理", businessType = OperaType.QUERY,  module = "施工管控->边带管理", details = "查询杆塔未绑定设备列表")
    public TableDataInfo listDeviceNoBind(SidebandDeviceVo data) {
        startPage();
        List<SidebandDeviceVo> list = sidebandservice.getDeviceNoLists(data);
        return getDataTable(list);
    }

    /**
     * 施工杆塔下拉选
     * @param dto
     * @return AjaxResult
     * @author cwchen
     * @date 2024/7/17 15:58
     */
    @GetMapping("/getGtList")
    public AjaxResult getGtList(ProjectPowerVo dto) {
        return sidebandservice.getGtList(dto);
    }

    /**
     * 工程下拉选
     * @param dto
     * @return AjaxResult
     * @author cwchen
     * @date 2024/7/17 15:58
     */
    @GetMapping("/getProList")
    public AjaxResult getProList(ProjectTwoVo dto) {
        return sidebandservice.getProList(dto);
    }

    /**
     * 根据边带id获取详细信息
     */
    @RequiresPermissions("bracelet:sideband:query")
    @GetMapping(value = "/{sidebandId}")
    public AjaxResult getInfo(@PathVariable Integer sidebandId) {
        return sidebandservice.selectSidebandById(sidebandId);
    }

    /**
     * 新增边带信息
     * @param vo
     * @return
     */
    @PostMapping("addSideband")
    @SysLog(title = "班组管理", businessType = OperaType.INSERT,  module = "基础管理->班组管理", details = "新增班组")
    public AjaxResult addSideband(@Validated @RequestBody SidebandVo vo) {
//        String name = sidebandservice.queryProjectName(vo.getProjectName());
//        vo.setProjectName(name);
        return sidebandservice.addSideband(vo);
    }

    /**
     * 修改边带信息
     * @param vo
     * @return
     */
    @PostMapping("editSideband")
    @SysLog(title = "边带管理", businessType = OperaType.UPDATE, module = "施工管控->边带管理", details = "修改边带")
    public AjaxResult editSideband(@Validated @RequestBody SidebandVo vo) {
//        String name = sidebandservice.queryProjectName(vo.getProjectName());
//        vo.setProjectName(name);
        return sidebandservice.editSideband(vo);
    }

        //    @RequiresPermissions("basic:team:del")
    @PostMapping("delSideband")
    @SysLog(title = "边带管理", businessType = OperaType.QUERY, logType = 0, module = "施工管控->边带管理", details = "删除边带")
    public AjaxResult delSideband(@RequestBody SidebandVo vo) {
        return sidebandservice.delSideband(vo);
    }

    /**
     * 解除绑定
     * @param vo
     * @return
     */
    @PostMapping("delDevice")
    @SysLog(title = "边带管理", businessType = OperaType.QUERY, module = "施工管控->边带管理", details = "解除绑定")
    public AjaxResult delDevice(@RequestBody SidebandDeviceVo vo) {
        return sidebandservice.delDevice(vo);
    }

    /**
     * 绑定
     * @param vo
     * @return
     */
    @PostMapping("bindDevice")
    @SysLog(title = "边带管理", businessType = OperaType.QUERY, module = "施工管控->边带管理", details = "绑定")
    public AjaxResult bindDevice(@RequestBody BindDeviceVo vo) {
        int sidebandId = vo.getSidebandId();
        List<Map<String,Object>> list= vo.getDeviceIds();
        return  sidebandservice.bindDevice(sidebandId,list);
    }

}
