package com.ruoyi.web.work.controller;

import java.util.Arrays;
import java.util.List;

import com.ruoyi.common.annotation.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.work.domain.Dg;
import com.ruoyi.web.work.service.IDgService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 诊断
 * @author lsw
 * @date 2024-07-19
 */
@Api(tags = "诊断管理")
@Anonymous
@RestController
@RequestMapping("/work/dg")
public class DgController extends BaseController {
    @Autowired
    private IDgService dgService;

    @ApiOperation(value = "获取诊断列表")
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:dg:list')")
    @GetMapping("/list")
    public TableDataInfo list(Dg dg){
        startPage();
        List<Dg> list = dgService.selectList(dg);
        return getDataTable(list);
    }

    @ApiOperation(value = "根据id查询")
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:dg:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id){
        return AjaxResult.success(dgService.getById(id));
    }

    @ApiOperation(value = "添加诊断信息")
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:dg:add')")
    @Log(title = "诊断", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Dg dg){
        return toAjax(dgService.save(dg));
    }

    @ApiOperation(value = "修改诊断信息")
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:dg:edit')")
    @Log(title = "诊断", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Dg dg){
        return toAjax(dgService.updateById(dg));
    }

    @ApiOperation(value = "删除诊断信息")
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:dg:remove')")
    @Log(title = "诊断", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(dgService.removeByIds(Arrays.asList(ids)));
    }
}
