package com.xinelu.manage.controller.projectdevice;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.projectdevice.ProjectDevice;
import com.xinelu.manage.service.projectdevice.IProjectDeviceService;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 检测项目设备Controller
 *
 * @author haown
 * @date 2024-03-11
 */
@RestController
@RequestMapping("/manage/projectdevice")
public class ProjectDeviceController extends BaseController {
    @Resource
    private IProjectDeviceService projectDeviceService;

	/**
	 * 查询检测项目设备列表
	 */
	@PreAuthorize("@ss.hasPermi('manage:projectdevice:list')")
	@GetMapping("/list")
    public TableDataInfo list(ProjectDevice projectDevice) {
        startPage();
        List<ProjectDevice> list = projectDeviceService.selectProjectDeviceList(projectDevice);
        return getDataTable(list);
    }

    /**
     * 导出检测项目设备列表
     */
    @PreAuthorize("@ss.hasPermi('manage:projectdevice:export')")
    @Log(title = "检测项目设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectDevice projectDevice) {
        List<ProjectDevice> list = projectDeviceService.selectProjectDeviceList(projectDevice);
        ExcelUtil<ProjectDevice> util = new ExcelUtil<ProjectDevice>(ProjectDevice. class);
        util.exportExcel(response, list, "检测项目设备数据");
    }

    /**
     * 获取检测项目设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:projectdevice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(projectDeviceService.selectProjectDeviceById(id));
    }

    /**
     * 新增检测项目设备
     */
    @PreAuthorize("@ss.hasPermi('manage:projectdevice:add')")
    @Log(title = "检测项目设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectDevice projectDevice) {
        return toAjax(projectDeviceService.insertProjectDevice(projectDevice));
    }

    /**
     * 修改检测项目设备
     */
    @PreAuthorize("@ss.hasPermi('manage:projectdevice:edit')")
    @Log(title = "检测项目设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectDevice projectDevice) {
        return toAjax(projectDeviceService.updateProjectDevice(projectDevice));
    }

    /**
     * 删除检测项目设备
     */
    @PreAuthorize("@ss.hasPermi('manage:projectdevice:remove')")
    @Log(title = "检测项目设备", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(projectDeviceService.deleteProjectDeviceByIds(ids));
    }
}
