package com.xinelu.manage.controller.normdepartmentcompare;

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.normdepartmentcompare.NormDepartmentCompare;
import com.xinelu.manage.service.normdepartmentcompare.INormDepartmentCompareService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 标准科室对照信息Controller
 *
 * @author xinelu
 * @date 2024-02-28
 */
@RestController
@RequestMapping("/system/compare")
public class NormDepartmentCompareController extends BaseController {
    @Resource
    private INormDepartmentCompareService normDepartmentCompareService;

    /**
     * 查询标准科室对照信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:compare:list')")
    @GetMapping("/list")
    public TableDataInfo list(NormDepartmentCompare normDepartmentCompare) {
        startPage();
        List<NormDepartmentCompare> list = normDepartmentCompareService.selectNormDepartmentCompareList(normDepartmentCompare);
        return getDataTable(list);
    }

    /**
     * 导出标准科室对照信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:compare:export')")
    @Log(title = "标准科室对照信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NormDepartmentCompare normDepartmentCompare) {
        List<NormDepartmentCompare> list = normDepartmentCompareService.selectNormDepartmentCompareList(normDepartmentCompare);
        ExcelUtil<NormDepartmentCompare> util = new ExcelUtil<NormDepartmentCompare>(NormDepartmentCompare.class);
        util.exportExcel(response, list, "标准科室对照信息数据");
    }

    /**
     * 获取标准科室对照信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:compare:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(normDepartmentCompareService.selectNormDepartmentCompareById(id));
    }

    /**
     * 新增标准科室对照信息
     */
    @PreAuthorize("@ss.hasPermi('system:compare:add')")
    @Log(title = "标准科室对照信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NormDepartmentCompare normDepartmentCompare) {
        return toAjax(normDepartmentCompareService.insertNormDepartmentCompare(normDepartmentCompare));
    }

    /**
     * 修改标准科室对照信息
     */
    @PreAuthorize("@ss.hasPermi('system:compare:edit')")
    @Log(title = "标准科室对照信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NormDepartmentCompare normDepartmentCompare) {
        return toAjax(normDepartmentCompareService.updateNormDepartmentCompare(normDepartmentCompare));
    }

    /**
     * 删除标准科室对照信息
     */
    @PreAuthorize("@ss.hasPermi('system:compare:remove')")
    @Log(title = "标准科室对照信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(normDepartmentCompareService.deleteNormDepartmentCompareByIds(ids));
    }
}
