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

/**
 * 产线信息Controller
 *
 * @author Yinq
 * @date 2023-09-19
 */
@RestController
@RequestMapping("/base/productLine")
public class BaseProductLineController extends BaseController {
    @Autowired
    private IBaseProductLineService baseProductLineService;

    /**
     * 查询产线信息列表
     */
    @PreAuthorize("@ss.hasPermi('base:productLine:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseProductLine baseProductLine) {
        startPage();
        List<BaseProductLine> list = baseProductLineService.selectBaseProductLineList(baseProductLine);
        return getDataTable(list);
    }

    /**
     * 查询产线下拉框列表
     * @param baseProductLine
     * @return
     */
    @GetMapping("/findProductLineList")
    public AjaxResult findProductLineList(BaseProductLine baseProductLine) {
        List<BaseProductLine> list = baseProductLineService.selectBaseProductLineList(baseProductLine);
        return success(list);
    }

    /**
     * 导出产线信息列表
     */
    @PreAuthorize("@ss.hasPermi('base:productLine:export')")
    @Log(title = "产线信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseProductLine baseProductLine) {
        List<BaseProductLine> list = baseProductLineService.selectBaseProductLineList(baseProductLine);
        ExcelUtil<BaseProductLine> util = new ExcelUtil<BaseProductLine>(BaseProductLine.class);
        util.exportExcel(response, list, "产线信息数据");
    }

    /**
     * 获取产线信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:productLine:query')")
    @GetMapping(value = "/{objId}")
    public AjaxResult getInfo(@PathVariable("objId") Long objId) {
        return success(baseProductLineService.selectBaseProductLineByObjId(objId));
    }

    /**
     * 新增产线信息
     */
    @PreAuthorize("@ss.hasPermi('base:productLine:add')")
    @Log(title = "产线信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseProductLine baseProductLine) {
        baseProductLine.setCreatedBy(getUsername());
        baseProductLine.setCreatedTime(DateUtils.getNowDate());
        return toAjax(baseProductLineService.insertBaseProductLine(baseProductLine));
    }

    /**
     * 修改产线信息
     */
    @PreAuthorize("@ss.hasPermi('base:productLine:edit')")
    @Log(title = "产线信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseProductLine baseProductLine) {
        baseProductLine.setUpdatedBy(getUsername());
        baseProductLine.setUpdatedTime(DateUtils.getNowDate());
        return toAjax(baseProductLineService.updateBaseProductLine(baseProductLine));
    }

    /**
     * 删除产线信息
     */
    @PreAuthorize("@ss.hasPermi('base:productLine:remove')")
    @Log(title = "产线信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{objIds}")
    public AjaxResult remove(@PathVariable Long[] objIds) {
        return toAjax(baseProductLineService.deleteBaseProductLineByObjIds(objIds));
    }
}
