package com.ruoyi.szxc.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.szxc.domain.SzxcHkbgRecard;
import com.ruoyi.szxc.service.ISzxcHkbgRecardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 户口变更记录Controller
 * 
 * @author hs
 * @date 2024-03-15
 */
@RestController
@RequestMapping("/szxc/recard")
public class SzxcHkbgRecardController extends BaseController
{
    @Autowired
    private ISzxcHkbgRecardService szxcHkbgRecardService;

    /**
     * 查询户口变更记录列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:recard:list')")
    @GetMapping("/list")
    public TableDataInfo list(SzxcHkbgRecard szxcHkbgRecard)
    {
        startPage();
        List<SzxcHkbgRecard> list = szxcHkbgRecardService.selectSzxcHkbgRecardList(szxcHkbgRecard);
        return getDataTable(list);
    }

    /**
     * 导出户口变更记录列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:recard:export')")
    @Log(title = "户口变更记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SzxcHkbgRecard szxcHkbgRecard)
    {
        List<SzxcHkbgRecard> list = szxcHkbgRecardService.selectSzxcHkbgRecardList(szxcHkbgRecard);
        ExcelUtil<SzxcHkbgRecard> util = new ExcelUtil<SzxcHkbgRecard>(SzxcHkbgRecard.class);
        util.exportExcel(response, list, "户口变更记录数据");
    }

    /**
     * 获取户口变更记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:recard:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(szxcHkbgRecardService.selectSzxcHkbgRecardById(id));
    }

    /**
     * 新增户口变更记录
     */
    @PreAuthorize("@ss.hasPermi('szxc:recard:add')")
    @Log(title = "户口变更记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzxcHkbgRecard szxcHkbgRecard)
    {
        //根据前端传递过来的部门存储，如果没传则存储当前用户的部门
        if(szxcHkbgRecard.getDeptId()==null){
            szxcHkbgRecard.setDeptId(getDeptId());
        }
        szxcHkbgRecard.setUserId(getUserId());
        return toAjax(szxcHkbgRecardService.insertSzxcHkbgRecard(szxcHkbgRecard));
    }

    /**
     * 修改户口变更记录
     */
    @PreAuthorize("@ss.hasPermi('szxc:recard:edit')")
    @Log(title = "户口变更记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzxcHkbgRecard szxcHkbgRecard)
    {
        return toAjax(szxcHkbgRecardService.updateSzxcHkbgRecard(szxcHkbgRecard));
    }

    /**
     * 删除户口变更记录
     */
    @PreAuthorize("@ss.hasPermi('szxc:recard:remove')")
    @Log(title = "户口变更记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(szxcHkbgRecardService.deleteSzxcHkbgRecardByIds(ids));
    }
}
