package com.phm.manage.controller;

import com.phm.common.annotation.Log;
import com.phm.common.core.controller.BaseController;
import com.phm.common.core.domain.AjaxResult;
import com.phm.common.core.domain.entity.SysUser;
import com.phm.common.core.page.TableDataInfo;
import com.phm.common.enums.BusinessType;
import com.phm.common.utils.poi.ExcelUtil;
import com.phm.manage.domain.Sortie;
import com.phm.manage.service.ISortieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 架次信息Controller
 *
 * @author phm
 * @date 2023-08-22
 */
@RestController
@RequestMapping("/manage/sortie")
public class SortieController extends BaseController {
    @Autowired
    private ISortieService sortieService;

    /**
     * 查询架次信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:sortie:list')")
    @GetMapping("/list")
    public TableDataInfo list(Sortie sortie) {
        startPage();
        List<Sortie> list = sortieService.selectSortieList(sortie);
        return getDataTable(list);
    }

    /**
     * 导出架次信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:sortie:export')")
    @Log(title = "架次信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Sortie sortie) {
        List<Sortie> list = sortieService.selectSortieList(sortie);
        ExcelUtil<Sortie> util = new ExcelUtil<Sortie>(Sortie.class);
        util.exportExcel(response, list, "架次信息数据");
    }
    @Log(title = "架次信息", businessType = BusinessType.IMPORT)
//    @PreAuthorize("@ss.hasPermi('manage:sortie:import')")
    @PostMapping("/import")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<Sortie> util = new ExcelUtil<Sortie>(Sortie.class);
        List<Sortie> sortieList = util.importExcel(file.getInputStream());
        String message = sortieService.importSortie(sortieList, updateSupport);
        return success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<Sortie> util = new ExcelUtil<Sortie>(Sortie.class);
        util.importTemplateExcel(response, "架次数据");
    }

    /**
     * 获取架次信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:sortie:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sortieService.selectSortieById(id));
    }

    /**
     * 新增架次信息
     */
    @PreAuthorize("@ss.hasPermi('manage:sortie:add')")
    @Log(title = "架次信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Sortie sortie) {
        return toAjax(sortieService.insertSortie(sortie));
    }

    /**
     * 修改架次信息
     */
    @PreAuthorize("@ss.hasPermi('manage:sortie:edit')")
    @Log(title = "架次信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Sortie sortie) {
        return toAjax(sortieService.updateSortie(sortie));
    }

    /**
     * 删除架次信息
     */
    @PreAuthorize("@ss.hasPermi('manage:sortie:remove')")
    @Log(title = "架次信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sortieService.deleteSortieByIds(ids));
    }
}
