package com.willalp.web.controller.erms;

import com.willalp.common.annotation.Log;
import com.willalp.common.core.controller.BaseController;
import com.willalp.common.core.domain.AjaxResult;
import com.willalp.common.core.page.TableDataInfo;
import com.willalp.common.enums.BusinessType;
import com.willalp.common.utils.DateUtils;
import com.willalp.common.utils.SecurityUtils;
import com.willalp.common.utils.poi.ExcelUtil;
import com.willalp.erms.domain.HsGoodsStorageRecord;
import com.willalp.erms.service.IHsGoodsStorageRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 物资库存记录Controller
 *
 * @author willalp
 * @date 2023-03-08
 */
@RestController
@RequestMapping("/erms/goodsRecord")
public class HsGoodsStorageRecordController extends BaseController
{
    @Resource
    private IHsGoodsStorageRecordService hsGoodsStorageRecordService;

    /**
     * 查询物资库存记录列表
     */
    @PreAuthorize("@ss.hasPermi('erms:goodsRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsGoodsStorageRecord hsGoodsStorageRecord)
    {
        startPage();
        List<HsGoodsStorageRecord> list = hsGoodsStorageRecordService.selectHsGoodsStorageRecordList(hsGoodsStorageRecord);
        return getDataTable(list);
    }

    /**
     * 导出物资库存记录列表
     */
    @PreAuthorize("@ss.hasPermi('erms:goodsRecord:export')")
    @Log(title = "物资库存记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsGoodsStorageRecord hsGoodsStorageRecord)
    {
        List<HsGoodsStorageRecord> list = hsGoodsStorageRecordService.selectHsGoodsStorageRecordList(hsGoodsStorageRecord);
        ExcelUtil<HsGoodsStorageRecord> util = new ExcelUtil<HsGoodsStorageRecord>(HsGoodsStorageRecord.class);
        return util.exportExcel(list, "物资库存记录数据");
    }

    /**
     * 获取物资库存记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('erms:goodsRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(hsGoodsStorageRecordService.getById(id));
    }

    /**
     * 新增物资库存记录
     */
    @PreAuthorize("@ss.hasPermi('erms:goodsRecord:add')")
    @Log(title = "物资库存记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsGoodsStorageRecord hsGoodsStorageRecord)
    {
        hsGoodsStorageRecord.setCreateBy(SecurityUtils.getUsername());
        hsGoodsStorageRecord.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsGoodsStorageRecordService.save(hsGoodsStorageRecord));
    }

    /**
     * 修改物资库存记录
     */
    @PreAuthorize("@ss.hasPermi('erms:goodsRecord:edit')")
    @Log(title = "物资库存记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsGoodsStorageRecord hsGoodsStorageRecord)
    {
        hsGoodsStorageRecord.setUpdateBy(SecurityUtils.getUsername());
        hsGoodsStorageRecord.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsGoodsStorageRecordService.updateById(hsGoodsStorageRecord));
    }

    /**
     * 删除物资库存记录
     */
    @PreAuthorize("@ss.hasPermi('erms:goodsRecord:remove')")
    @Log(title = "物资库存记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(hsGoodsStorageRecordService.removeByIds(Arrays.asList(ids)));
    }
}
