package com.bonus.canteen.core.account.controller;

import com.bonus.canteen.core.account.domain.AccCardHis;
import com.bonus.canteen.core.account.service.IAccCardHisService;
import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 人员换卡历史记录Controller
 *
 * @author xsheng
 * @date 2025-04-23
 */
@Api(tags = "人员换卡历史记录接口")
@RestController
@RequestMapping("/acc_card_his")
public class AccCardHisController extends BaseController {
    @Autowired
    private IAccCardHisService accCardHisService;

    /**
     * 查询人员换卡历史记录列表
     */
    @ApiOperation(value = "查询人员换卡历史记录列表")
    //@RequiresPermissions("account:his:list")
    @GetMapping("/list")
    public TableDataInfo list(AccCardHis accCardHis) {
        startPage();
        List<AccCardHis> list = accCardHisService.selectAccCardHisList(accCardHis);
        return getDataTable(list);
    }

    /**
     * 导出人员换卡历史记录列表
     */
    @ApiOperation(value = "导出人员换卡历史记录列表")
    //@PreventRepeatSubmit
    //@RequiresPermissions("account:his:export")
    @SysLog(title = "人员换卡历史记录", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导出人员换卡历史记录")
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccCardHis accCardHis) {
        List<AccCardHis> list = accCardHisService.selectAccCardHisList(accCardHis);
        ExcelUtil<AccCardHis> util = new ExcelUtil<AccCardHis>(AccCardHis.class);
        util.exportExcel(response, list, "人员换卡历史记录数据");
    }

    /**
     * 获取人员换卡历史记录详细信息
     */
    @ApiOperation(value = "获取人员换卡历史记录详细信息")
    //@RequiresPermissions("account:his:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(accCardHisService.selectAccCardHisById(id));
    }

    /**
     * 新增人员换卡历史记录
     */
    @ApiOperation(value = "新增人员换卡历史记录")
    //@PreventRepeatSubmit
    //@RequiresPermissions("account:his:add")
    @SysLog(title = "人员换卡历史记录", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增人员换卡历史记录")
    @PostMapping
    public AjaxResult add(@RequestBody AccCardHis accCardHis) {
        try {
            return toAjax(accCardHisService.insertAccCardHis(accCardHis));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 修改人员换卡历史记录
     */
    @ApiOperation(value = "修改人员换卡历史记录")
    //@PreventRepeatSubmit
    //@RequiresPermissions("account:his:edit")
    @SysLog(title = "人员换卡历史记录", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->修改人员换卡历史记录")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody AccCardHis accCardHis) {
        try {
            return toAjax(accCardHisService.updateAccCardHis(accCardHis));
        } catch (Exception e) {
            return error("系统错误, " + e.getMessage());
        }
    }

    /**
     * 删除人员换卡历史记录
     */
    @ApiOperation(value = "删除人员换卡历史记录")
    //@PreventRepeatSubmit
    //@RequiresPermissions("account:his:remove")
    @SysLog(title = "人员换卡历史记录", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除人员换卡历史记录")
	@PostMapping("/del/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(accCardHisService.deleteAccCardHisByIds(ids));
    }
}
