package com.dcsoft.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dcsoft.common.log.annotation.Log;
import com.dcsoft.common.log.enums.BusinessType;
import com.dcsoft.common.security.annotation.RequiresPermissions;
import com.dcsoft.system.domain.SysPoint;
import com.dcsoft.system.service.ISysPointService;
import com.dcsoft.common.core.web.controller.BaseController;
import com.dcsoft.common.core.web.domain.AjaxResult;
import com.dcsoft.common.core.utils.poi.ExcelUtil;
import com.dcsoft.common.core.web.page.TableDataInfo;

/**
 * 点位管理Controller
 *
 * @author nichun
 * @date 2023-03-08
 */
@RestController
@RequestMapping("/point")
public class SysPointController extends BaseController
{
    @Autowired
    private ISysPointService sysPointService;



    /**
     * 查询点位管理列表
     */
    @RequiresPermissions("system:point:list")
    @GetMapping("/list")
    public TableDataInfo list(SysPoint sysPoint)
    {
        startPage();
        List<SysPoint> list = sysPointService.selectSysPointList(sysPoint);
        return getDataTable(list);
    }

    /**
     * 导出点位管理列表
     */
    @RequiresPermissions("system:point:export")
    @Log(title = "点位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPoint sysPoint)
    {
        List<SysPoint> list = sysPointService.selectSysPointList(sysPoint);
        ExcelUtil<SysPoint> util = new ExcelUtil<SysPoint>(SysPoint.class);
        util.exportExcel(response, list, "点位管理数据");
    }

    /**
     * 获取点位管理详细信息
     */
    @RequiresPermissions("system:point:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysPointService.selectSysPointById(id));
    }

    /**
     * 新增点位管理
     */
    @RequiresPermissions("system:point:add")
    @Log(title = "点位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPoint sysPoint)
    {
        return toAjax(sysPointService.insertSysPoint(sysPoint));
    }

    /**
     * 修改点位管理
     */
    @RequiresPermissions("system:point:edit")
    @Log(title = "点位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPoint sysPoint)
    {
        return toAjax(sysPointService.updateSysPoint(sysPoint));
    }

    /**
     * 删除点位管理
     */
    @RequiresPermissions("system:point:remove")
    @Log(title = "点位管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysPointService.deleteSysPointByIds(ids));
    }


    @Log(title = "海康点位同步", businessType = BusinessType.INSERT)
    @PostMapping("/syncPoint")
    public AjaxResult syncPoint()
    {
        return toAjax(sysPointService.syncPoint());
    }
}
