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

/**
 * 质检项信息维护Controller
 *
 * @author Yinq
 * @date 2023-10-16
 */
@RestController
@RequestMapping("/base/qualityInspectionItem" )
public class BaseQualityInspectionItemController extends BaseController {
    @Autowired
    private IBaseQualityInspectionItemService baseQualityInspectionItemService;

    /**
     * 查询质检项信息维护列表
     */
    @PreAuthorize("@ss.hasPermi('base:qualityInspectionItem:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(BaseQualityInspectionItem baseQualityInspectionItem) {
        startPage();
        List<BaseQualityInspectionItem> list = baseQualityInspectionItemService.selectBaseQualityInspectionItemList(baseQualityInspectionItem);
        return getDataTable(list);
    }

    /**
     * 导出质检项信息维护列表
     */
    @PreAuthorize("@ss.hasPermi('base:qualityInspectionItem:export')" )
    @Log(title = "质检项信息维护" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, BaseQualityInspectionItem baseQualityInspectionItem) {
        List<BaseQualityInspectionItem> list = baseQualityInspectionItemService.selectBaseQualityInspectionItemList(baseQualityInspectionItem);
        ExcelUtil<BaseQualityInspectionItem> util = new ExcelUtil<BaseQualityInspectionItem>(BaseQualityInspectionItem. class);
        util.exportExcel(response, list, "质检项信息维护数据" );
    }

    /**
     * 获取质检项信息维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:qualityInspectionItem:query')" )
    @GetMapping(value = "/{objId}" )
    public AjaxResult getInfo(@PathVariable("objId" ) Long objId) {
        return success(baseQualityInspectionItemService.selectBaseQualityInspectionItemByObjId(objId));
    }

    /**
     * 查询所有父级以及名称
     * */
    @GetMapping("/getParent")
    public AjaxResult getParent(){
        return success(baseQualityInspectionItemService.selectBaseQualityInspectionItemParent());
    }

    /**
     * 新增质检项信息维护
     */
    @PreAuthorize("@ss.hasPermi('base:qualityInspectionItem:add')" )
    @Log(title = "质检项信息维护" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseQualityInspectionItem baseQualityInspectionItem) {
        baseQualityInspectionItem.setCreatedBy(getUsername());
        baseQualityInspectionItem.setCreatedTime(DateUtils.getNowDate());
        return toAjax(baseQualityInspectionItemService.insertBaseQualityInspectionItem(baseQualityInspectionItem));
    }

    /**
     * 修改质检项信息维护
     */
    @PreAuthorize("@ss.hasPermi('base:qualityInspectionItem:edit')" )
    @Log(title = "质检项信息维护" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseQualityInspectionItem baseQualityInspectionItem) {
        baseQualityInspectionItem.setUpdatedBy(getUsername());
        baseQualityInspectionItem.setUpdatedTime(DateUtils.getNowDate());
        return toAjax(baseQualityInspectionItemService.updateBaseQualityInspectionItem(baseQualityInspectionItem));
    }

    /**
     * 删除质检项信息维护
     */
    @PreAuthorize("@ss.hasPermi('base:qualityInspectionItem:remove')" )
    @Log(title = "质检项信息维护" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{objIds}" )
    public AjaxResult remove(@PathVariable Long[] objIds) {
        return toAjax(baseQualityInspectionItemService.deleteBaseQualityInspectionItemByObjIds(objIds));
    }
}
