package com.zg.project.wisdom.controller;

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

import com.zg.framework.aspectj.lang.annotation.Log;
import com.zg.framework.aspectj.lang.enums.BusinessType;
import com.zg.common.utils.poi.ExcelUtil;
import com.zg.framework.web.controller.BaseController;
import com.zg.framework.web.domain.AjaxResult;
import com.zg.framework.web.page.TableDataInfo;

import com.zg.project.wisdom.domain.MoveRecord;
import com.zg.project.wisdom.domain.dto.MoveRequestDTO;
import com.zg.project.wisdom.service.IMoveRecordService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 移库记录Controller
 * 
 * @author zg
 * @date 2025-06-20
 */
@RestController
@RequestMapping("/inventory/move")
public class MoveRecordController extends BaseController
{
    @Autowired
    private IMoveRecordService moveRecordService;


    /**
     * 新增移库记录
     */
    @PreAuthorize("@ss.hasPermi('wisdom:stock:move')")
    @Log(title = "移库记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult processMove(@RequestBody MoveRequestDTO dto) {
        moveRecordService.processMove(dto);
        return AjaxResult.success("移库成功");
    }


    /**
     * 查询移库记录列表
     */
    @PreAuthorize("@ss.hasPermi('wisdom:move:list')")
    @GetMapping("/list")
    public TableDataInfo list(MoveRecord moveRecord)
    {
        startPage();
        List<MoveRecord> list = moveRecordService.selectMoveRecordList(moveRecord);
        return getDataTable(list);
    }

    /**
     * 导出移库记录列表
     */
    @PreAuthorize("@ss.hasPermi('inventory:move:export')")
    @Log(title = "移库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MoveRecord moveRecord)
    {
        List<MoveRecord> list = moveRecordService.selectMoveRecordList(moveRecord);
        ExcelUtil<MoveRecord> util = new ExcelUtil<>(MoveRecord.class);
        util.exportExcel(response, list, "移库记录数据");
    }

    /**
     * 获取移库记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('inventory:move:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(moveRecordService.selectMoveRecordById(id));
    }

    /**
     * 修改移库记录
     */
    @PreAuthorize("@ss.hasPermi('inventory:move:edit')")
    @Log(title = "移库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MoveRecord moveRecord)
    {
        return toAjax(moveRecordService.updateMoveRecord(moveRecord));
    }

    /**
     * 删除移库记录
     */
    @PreAuthorize("@ss.hasPermi('inventory:move:remove')")
    @Log(title = "移库记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(moveRecordService.deleteMoveRecordByIds(ids));
    }
}
