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.BaseSpaceDetail;
import com.aucma.base.service.IBaseSpaceDetailService;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.common.core.page.TableDataInfo;

/**
 * 货道明细Controller
 *
 * @author Yinq
 * @date 2023-10-30
 */
@RestController
@RequestMapping("/base/spaceDetail" )
public class BaseSpaceDetailController extends BaseController {
    @Autowired
    private IBaseSpaceDetailService baseSpaceDetailService;

    /**
     * 查询货道明细列表
     */
    @PreAuthorize("@ss.hasPermi('base:spaceDetail:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(BaseSpaceDetail baseSpaceDetail) {
        startPage();
        List<BaseSpaceDetail> list = baseSpaceDetailService.selectBaseSpaceDetailList(baseSpaceDetail);
        return getDataTable(list);
    }

    /**
     * 导出货道明细列表
     */
    @PreAuthorize("@ss.hasPermi('base:spaceDetail:export')" )
    @Log(title = "货道明细" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, BaseSpaceDetail baseSpaceDetail) {
        List<BaseSpaceDetail> list = baseSpaceDetailService.selectBaseSpaceDetailList(baseSpaceDetail);
        ExcelUtil<BaseSpaceDetail> util = new ExcelUtil<BaseSpaceDetail>(BaseSpaceDetail. class);
        util.exportExcel(response, list, "货道明细数据" );
    }

    /**
     * 获取货道明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:spaceDetail:query')" )
    @GetMapping(value = "/{objId}" )
    public AjaxResult getInfo(@PathVariable("objId" ) Long objId) {
        return success(baseSpaceDetailService.selectBaseSpaceDetailByObjId(objId));
    }

    /**
     * 新增货道明细
     */
    @PreAuthorize("@ss.hasPermi('base:spaceDetail:add')" )
    @Log(title = "货道明细" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseSpaceDetail baseSpaceDetail) {
        baseSpaceDetail.setCreatedBy(getUsername());
        baseSpaceDetail.setCreatedTime(DateUtils.getNowDate());
        return toAjax(baseSpaceDetailService.insertBaseSpaceDetail(baseSpaceDetail));
    }

    /**
     * 修改货道明细
     */
    @PreAuthorize("@ss.hasPermi('base:spaceDetail:edit')" )
    @Log(title = "货道明细" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseSpaceDetail baseSpaceDetail) {
        baseSpaceDetail.setUpdatedBy(getUsername());
        baseSpaceDetail.setUpdatedTime(DateUtils.getNowDate());
        return toAjax(baseSpaceDetailService.updateBaseSpaceDetail(baseSpaceDetail));
    }

    /**
     * 删除货道明细
     */
    @PreAuthorize("@ss.hasPermi('base:spaceDetail:remove')" )
    @Log(title = "货道明细" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{objIds}" )
    public AjaxResult remove(@PathVariable Long[] objIds) {
        return toAjax(baseSpaceDetailService.deleteBaseSpaceDetailByObjIds(objIds));
    }
}
