package com.aucma.base.controller;

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

import com.aucma.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.aucma.common.annotation.Log;
import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.enums.BusinessType;
import com.aucma.base.domain.BaseMaterialInfo;
import com.aucma.base.service.IBaseMaterialInfoService;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.common.core.page.TableDataInfo;

/**
 * 物料信息Controller
 *
 * @author Yinq
 * @date 2023-09-19
 */
@RestController
@RequestMapping("/base/materialInfo" )
public class BaseMaterialInfoController extends BaseController {
    @Autowired
    private IBaseMaterialInfoService baseMaterialInfoService;

    /**
     * 查询物料信息列表
     */
    @PreAuthorize("@ss.hasPermi('base:materialInfo:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(BaseMaterialInfo baseMaterialInfo) {
        startPage();
        List<BaseMaterialInfo> list = baseMaterialInfoService.selectBaseMaterialInfoList(baseMaterialInfo);
        return getDataTable(list);
    }

    /**
     * 导出物料信息列表
     */
    @PreAuthorize("@ss.hasPermi('base:materialInfo:export')" )
    @Log(title = "物料信息" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, BaseMaterialInfo baseMaterialInfo) {
        List<BaseMaterialInfo> list = baseMaterialInfoService.selectBaseMaterialInfoList(baseMaterialInfo);
        ExcelUtil<BaseMaterialInfo> util = new ExcelUtil<BaseMaterialInfo>(BaseMaterialInfo. class);
        util.exportExcel(response, list, "物料信息数据" );
    }

    /**
     * 获取物料信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:materialInfo:query')" )
    @GetMapping(value = "/{objId}" )
    public AjaxResult getInfo(@PathVariable("objId" ) Long objId) {
        return success(baseMaterialInfoService.selectBaseMaterialInfoByObjId(objId));
    }

    /**
     * 新增物料信息
     */
    @PreAuthorize("@ss.hasPermi('base:materialInfo:add')" )
    @Log(title = "物料信息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseMaterialInfo baseMaterialInfo) {
        baseMaterialInfo.setCreatedBy(getUsername());
        return toAjax(baseMaterialInfoService.insertBaseMaterialInfo(baseMaterialInfo));
    }

    /**
     * 修改物料信息
     */
    @PreAuthorize("@ss.hasPermi('base:materialInfo:edit')" )
    @Log(title = "物料信息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseMaterialInfo baseMaterialInfo) {
        baseMaterialInfo.setUpdatedBy(getUsername());
        baseMaterialInfo.setUpdatedTime(DateUtils.getNowDate());
        return toAjax(baseMaterialInfoService.updateBaseMaterialInfo(baseMaterialInfo));
    }

    /**
     * 删除物料信息
     */
    @PreAuthorize("@ss.hasPermi('base:materialInfo:remove')" )
    @Log(title = "物料信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{objIds}" )
    public AjaxResult remove(@PathVariable Long[] objIds) {
        return toAjax(baseMaterialInfoService.deleteBaseMaterialInfoByObjIds(objIds));
    }
}
