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

/**
 * 工单信息Controller
 *
 * @author Yinq
 * @date 2023-09-27
 */
@RestController
@RequestMapping("/base/orderInfo")
public class BaseOrderInfoController extends BaseController {
    @Autowired
    private IBaseOrderInfoService baseOrderInfoService;

    /**
     * 查询工单信息列表
     */
    @PreAuthorize("@ss.hasPermi('base:orderInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseOrderInfo baseOrderInfo) {
        startPage();
        List<BaseOrderInfo> list = baseOrderInfoService.selectBaseOrderInfoList(baseOrderInfo);
        return getDataTable(list);
    }

    /**
     * 导出工单信息列表
     */
    @PreAuthorize("@ss.hasPermi('base:orderInfo:export')")
    @Log(title = "工单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseOrderInfo baseOrderInfo) {
        List<BaseOrderInfo> list = baseOrderInfoService.selectBaseOrderInfoList(baseOrderInfo);
        ExcelUtil<BaseOrderInfo> util = new ExcelUtil<BaseOrderInfo>(BaseOrderInfo.class);
        util.exportExcel(response, list, "工单信息数据");
    }

    /**
     * 获取工单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:orderInfo:query')")
    @GetMapping(value = "/{objId}")
    public AjaxResult getInfo(@PathVariable("objId") Long objId) {
        return success(baseOrderInfoService.selectBaseOrderInfoByObjId(objId));
    }

    /**
     * 新增工单信息
     */
    @PreAuthorize("@ss.hasPermi('base:orderInfo:add')")
    @Log(title = "工单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseOrderInfo baseOrderInfo) {
        baseOrderInfo.setCreatedBy(getUsername());
        return toAjax(baseOrderInfoService.insertBaseOrderInfo(baseOrderInfo));
    }

    /**
     * 修改工单信息
     */
    @PreAuthorize("@ss.hasPermi('base:orderInfo:edit')")
    @Log(title = "工单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseOrderInfo baseOrderInfo) {
        baseOrderInfo.setUpdatedBy(getUsername());
        return toAjax(baseOrderInfoService.updateBaseOrderInfo(baseOrderInfo));
    }

    /**
     * 删除工单信息
     */
    @PreAuthorize("@ss.hasPermi('base:orderInfo:remove')")
    @Log(title = "工单信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{objIds}")
    public AjaxResult remove(@PathVariable Long[] objIds) {
        return toAjax(baseOrderInfoService.deleteBaseOrderInfoByObjIds(objIds));
    }
}
