package org.dromara.ems.info.controller;

import org.dromara.common.log.annotation.Log;
import org.dromara.ems.common.web.EmsBaseController;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.ems.info.domain.SparePartsInventoryCheck;
import org.dromara.ems.info.service.ISparePartsInventoryCheckService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * 备件盘点记录明细Controller
 * 
 * @author Yinq
 * @date 2024-12-13
 */
@RestController
@RequiredArgsConstructor

@RequestMapping("/ems/info/sparePartsInventoryCheck")
public class SparePartsInventoryCheckController extends EmsBaseController
{

    private final ISparePartsInventoryCheckService sparePartsInventoryCheckService;

    /**
     * 查询备件盘点记录明细列表
     */
    @SaCheckPermission("ems/info:sparePartsInventoryCheck:list")
    @GetMapping("/list")
    public TableDataInfo list(SparePartsInventoryCheck sparePartsInventoryCheck)
    {
        startPage();
        List<SparePartsInventoryCheck> list = sparePartsInventoryCheckService.selectSparePartsInventoryCheckList(sparePartsInventoryCheck);
        return getDataTable(list);
    }

    /**
     * 导出备件盘点记录明细列表
     */
    @SaCheckPermission("ems/info:sparePartsInventoryCheck:export")
    @Log(title = "备件盘点记录明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SparePartsInventoryCheck sparePartsInventoryCheck)
    {
        List<SparePartsInventoryCheck> list = sparePartsInventoryCheckService.selectSparePartsInventoryCheckList(sparePartsInventoryCheck);
        ExcelUtil.exportExcel(list, "备件盘点记录明细数据", SparePartsInventoryCheck.class, response);
    }

    /**
     * 获取备件盘点记录明细详细信息
     */
    @SaCheckPermission("ems/info:sparePartsInventoryCheck:query")
    @GetMapping(value = "/{id}")
    public R<?> getInfo(@PathVariable("id") Long id)
    {
        return success(sparePartsInventoryCheckService.selectSparePartsInventoryCheckById(id));
    }

    /**
     * 新增备件盘点记录明细
     */
    @SaCheckPermission("ems/info:sparePartsInventoryCheck:add")
    @Log(title = "备件盘点记录明细", businessType = BusinessType.INSERT)
    @PostMapping
    public R<?> add(@RequestBody SparePartsInventoryCheck sparePartsInventoryCheck)
    {
        return toAjax(sparePartsInventoryCheckService.insertSparePartsInventoryCheck(sparePartsInventoryCheck));
    }

    /**
     * 修改备件盘点记录明细
     */
    @SaCheckPermission("ems/info:sparePartsInventoryCheck:edit")
    @Log(title = "备件盘点记录明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<?> edit(@RequestBody SparePartsInventoryCheck sparePartsInventoryCheck)
    {
        return toAjax(sparePartsInventoryCheckService.updateSparePartsInventoryCheck(sparePartsInventoryCheck));
    }

    /**
     * 删除备件盘点记录明细
     */
    @SaCheckPermission("ems/info:sparePartsInventoryCheck:remove")
    @Log(title = "备件盘点记录明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R<?> remove(@PathVariable Long[] ids)
    {
        return toAjax(sparePartsInventoryCheckService.deleteSparePartsInventoryCheckByIds(ids));
    }

    /**
     * 导入备件盘点记录明细数据
     */
    @SaCheckPermission("ems/info:sparePartsInventoryCheck:add")
    @Log(title = "备件盘点记录明细", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public R<?> importData(MultipartFile file, @RequestParam(value = "updateSupport", defaultValue = "false") boolean updateSupport) throws Exception
    {
        List<SparePartsInventoryCheck> dataList = ExcelUtil.importExcel(file.getInputStream(), SparePartsInventoryCheck.class);
        String message = sparePartsInventoryCheckService.importSparePartsInventoryCheck(dataList, updateSupport, getUsername());
        return R.ok(message);
    }

    /**
     * 获取备件盘点记录明细导入模板
     */
    @SaCheckPermission("ems/info:sparePartsInventoryCheck:add")
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil.exportExcel(new ArrayList<>(), "备件盘点记录明细数据", SparePartsInventoryCheck.class, response);
    }
}
