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

/**
 * 质检工位/缺陷维护Controller
 *
 * @author Yinq
 * @date 2023-11-27
 */
@RestController
@RequestMapping("/base/stationDefectRelation" )
public class StationDefectRelationController extends BaseController {
    @Autowired
    private IStationDefectRelationService stationDefectRelationService;

    /**
     * 查询质检工位/缺陷维护列表
     */
    @PreAuthorize("@ss.hasPermi('base:stationDefectRelation:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(StationDefectRelation stationDefectRelation) {
        startPage();
        List<StationDefectRelation> list = stationDefectRelationService.selectStationDefectRelationList(stationDefectRelation);
        return getDataTable(list);
    }

    /**
     * 导出质检工位/缺陷维护列表
     */
    @PreAuthorize("@ss.hasPermi('base:stationDefectRelation:export')" )
    @Log(title = "质检工位/缺陷维护" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, StationDefectRelation stationDefectRelation) {
        List<StationDefectRelation> list = stationDefectRelationService.selectStationDefectRelationList(stationDefectRelation);
        ExcelUtil<StationDefectRelation> util = new ExcelUtil<StationDefectRelation>(StationDefectRelation. class);
        util.exportExcel(response, list, "质检工位/缺陷维护数据" );
    }

    /**
     * 获取质检工位/缺陷维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:stationDefectRelation:query')" )
    @GetMapping(value = "/{objId}" )
    public AjaxResult getInfo(@PathVariable("objId" ) Long objId) {
        return success(stationDefectRelationService.selectStationDefectRelationByObjId(objId));
    }

    /**
     * 新增质检工位/缺陷维护
     */
    @PreAuthorize("@ss.hasPermi('base:stationDefectRelation:add')" )
    @Log(title = "质检工位/缺陷维护" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StationDefectRelation stationDefectRelation) {
        stationDefectRelation.setCreatedBy(getUsername());
        stationDefectRelation.setCreatedTime(DateUtils.getNowDate());
        return toAjax(stationDefectRelationService.insertStationDefectRelation(stationDefectRelation));
    }

    /**
     * 修改质检工位/缺陷维护
     */
    @PreAuthorize("@ss.hasPermi('base:stationDefectRelation:edit')" )
    @Log(title = "质检工位/缺陷维护" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StationDefectRelation stationDefectRelation) {
        stationDefectRelation.setUpdatedBy(getUsername());
        stationDefectRelation.setUpdatedTime(DateUtils.getNowDate());
        return toAjax(stationDefectRelationService.updateStationDefectRelation(stationDefectRelation));
    }

    /**
     * 删除质检工位/缺陷维护
     */
    @PreAuthorize("@ss.hasPermi('base:stationDefectRelation:remove')" )
    @Log(title = "质检工位/缺陷维护" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{objIds}" )
    public AjaxResult remove(@PathVariable Long[] objIds) {
        return toAjax(stationDefectRelationService.deleteStationDefectRelationByObjIds(objIds));
    }
}
