package com.xinelu.manage.controller.nursestationdepartment;

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.custominterface.Insert;
import com.xinelu.common.custominterface.Update;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.nursestationdepartment.NurseStationDepartment;
import com.xinelu.manage.dto.nursestationdepartment.NurseStationDepartmentDTO;
import com.xinelu.manage.service.nursestationdepartment.INurseStationDepartmentService;
import com.xinelu.manage.vo.nursestationdepartment.NurseStationDepartmentVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * 护理站部门信息Controller
 *
 * @author zh
 * @date 2022-09-13
 */
@RestController
@RequestMapping("/system/StationDepartment")
public class StationDepartmentController extends BaseController {

    @Resource
    private INurseStationDepartmentService nurseStationDepartmentService;

    /**
     * 查询护理站部门信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:StationDepartment:list')")
    @GetMapping("/list")
    public TableDataInfo list(NurseStationDepartmentVO nurseStationDepartment) {
        startPage();
        List<NurseStationDepartmentVO> list = nurseStationDepartmentService.selectNurseStationDepartmentList(nurseStationDepartment);
        return getDataTable(list);
    }

    /**
     * 导出护理站部门信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:StationDepartment:export')")
    @Log(title = "护理站部门信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NurseStationDepartmentVO nurseStationDepartment) {
        List<NurseStationDepartmentVO> list = nurseStationDepartmentService.selectNurseStationDepartmentList(nurseStationDepartment);
        ExcelUtil<NurseStationDepartmentVO> util = new ExcelUtil<>(NurseStationDepartmentVO.class);
        util.exportExcel(response, list, "护理站部门信息数据");
    }

    /**
     * 获取护理站部门信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:StationDepartment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(nurseStationDepartmentService.selectNurseStationDepartmentById(id));
    }

    /**
     * 新增护理站部门信息
     */
    @PreAuthorize("@ss.hasPermi('system:StationDepartment:add')")
    @Log(title = "护理站部门信息", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@Validated(Insert.class) @RequestBody NurseStationDepartmentDTO nurseStationDepartment) {
        return nurseStationDepartmentService.insertStationDepartmentList(nurseStationDepartment.getNurseStationDepartmentList());
    }

    /**
     * 修改护理站部门信息
     */
    @PreAuthorize("@ss.hasPermi('system:StationDepartment:edit')")
    @Log(title = "护理站部门信息", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public AjaxResult edit(@Validated(Update.class) @RequestBody NurseStationDepartment nurseStationDepartment) {
        return nurseStationDepartmentService.updateNurseStationDepartment(nurseStationDepartment);
    }

    /**
     * 删除护理站部门信息
     */
    @PreAuthorize("@ss.hasPermi('system:StationDepartment:remove')")
    @Log(title = "护理站部门信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(nurseStationDepartmentService.deleteNurseStationDepartmentByIds(ids));
    }
}