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.HsGoodsStorage;
import com.willalp.erms.service.IHsGoodsStorageService;
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/storage")
public class HsGoodsStorageController extends BaseController
{
    @Resource
    private IHsGoodsStorageService hsGoodsStorageService;

    /**
     * 查询物资库列表
     */
    @PreAuthorize("@ss.hasPermi('erms:storage:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsGoodsStorage hsGoodsStorage)
    {
        startPage();
        List<HsGoodsStorage> list = hsGoodsStorageService.selectHsGoodsStorageList(hsGoodsStorage);
        return getDataTable(list);
    }

    /**
     * 导出物资库列表
     */
    @PreAuthorize("@ss.hasPermi('erms:storage:export')")
    @Log(title = "物资库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsGoodsStorage hsGoodsStorage)
    {
        List<HsGoodsStorage> list = hsGoodsStorageService.selectHsGoodsStorageList(hsGoodsStorage);
        ExcelUtil<HsGoodsStorage> util = new ExcelUtil<HsGoodsStorage>(HsGoodsStorage.class);
        return util.exportExcel(list, "物资库数据");
    }

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

    /**
     * 新增物资库
     */
    @PreAuthorize("@ss.hasPermi('erms:storage:add')")
    @Log(title = "物资库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsGoodsStorage hsGoodsStorage)
    {
        hsGoodsStorage.setCreateBy(SecurityUtils.getUsername());
        hsGoodsStorage.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsGoodsStorageService.save(hsGoodsStorage));
    }

    /**
     * 修改物资库
     */
    @PreAuthorize("@ss.hasPermi('erms:storage:edit')")
    @Log(title = "物资库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsGoodsStorage hsGoodsStorage)
    {
        hsGoodsStorage.setUpdateBy(SecurityUtils.getUsername());
        hsGoodsStorage.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsGoodsStorageService.updateById(hsGoodsStorage));
    }

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