package com.uavps.web.controller.system;

import com.uavps.common.annotation.Log;
import com.uavps.common.core.controller.BaseController;
import com.uavps.common.core.domain.AjaxResult;
import com.uavps.common.core.page.TableDataInfo;
import com.uavps.common.enums.BusinessType;
import com.uavps.common.utils.poi.ExcelUtil;
import com.uavps.system.domain.UavpsMultiTargetFormation;
import com.uavps.system.service.IUavpsMultiTargetFormationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

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

/**
 * 多目标集群信息Controller
 *
 * @author ruoyi
 * @date 2025-02-07
 */
@RestController
@RequestMapping("/uavps/formation")
public class UavpsMultiTargetFormationController extends BaseController {
    @Autowired
    private IUavpsMultiTargetFormationService uavpsMultiTargetFormationService;

    /**
     * 查询多目标集群信息列表
     */
    @PreAuthorize("@ss.hasPermi('uavps:formation:list')")
    @GetMapping("/list")
    public TableDataInfo list(UavpsMultiTargetFormation uavpsMultiTargetFormation) {
        startPage();
        List<UavpsMultiTargetFormation> list = uavpsMultiTargetFormationService.selectUavpsMultiTargetFormationList(uavpsMultiTargetFormation);
        return getDataTable(list);
    }

    /**
     * 导入多目标集群信息列表
     */
    @Log(title = "多目标集群信息", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('uavps:formation:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<UavpsMultiTargetFormation> util = new ExcelUtil<UavpsMultiTargetFormation>(UavpsMultiTargetFormation.class);
        List<UavpsMultiTargetFormation> formationList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = uavpsMultiTargetFormationService.importUavpsMultiTargetFormation(formationList, updateSupport, operName);
        return success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<UavpsMultiTargetFormation> util = new ExcelUtil<UavpsMultiTargetFormation>(UavpsMultiTargetFormation.class);
        util.importTemplateExcel(response, "多目标集群信息");
    }

    /**
     * 导出多目标集群信息列表
     */
    @PreAuthorize("@ss.hasPermi('uavps:formation:export')")
    @Log(title = "多目标集群信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UavpsMultiTargetFormation uavpsMultiTargetFormation) {
        List<UavpsMultiTargetFormation> list = uavpsMultiTargetFormationService.selectUavpsMultiTargetFormationList(uavpsMultiTargetFormation);
        ExcelUtil<UavpsMultiTargetFormation> util = new ExcelUtil<UavpsMultiTargetFormation>(UavpsMultiTargetFormation.class);
        util.exportExcel(response, list, "多目标集群信息数据");
    }

    /**
     * 获取多目标集群信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('uavps:formation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(uavpsMultiTargetFormationService.selectUavpsMultiTargetFormationById(id));
    }

    /**
     * 新增多目标集群信息
     */
    @PreAuthorize("@ss.hasPermi('uavps:formation:add')")
    @Log(title = "多目标集群信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UavpsMultiTargetFormation uavpsMultiTargetFormation) {
        uavpsMultiTargetFormation.setCreateBy(getUsername());
        return toAjax(uavpsMultiTargetFormationService.insertUavpsMultiTargetFormation(uavpsMultiTargetFormation));
    }

    /**
     * 修改多目标集群信息
     */
    @PreAuthorize("@ss.hasPermi('uavps:formation:edit')")
    @Log(title = "多目标集群信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UavpsMultiTargetFormation uavpsMultiTargetFormation) {
        uavpsMultiTargetFormation.setUpdateBy(getUsername());
        return toAjax(uavpsMultiTargetFormationService.updateUavpsMultiTargetFormation(uavpsMultiTargetFormation));
    }

    /**
     * 删除多目标集群信息
     */
    @PreAuthorize("@ss.hasPermi('uavps:formation:remove')")
    @Log(title = "多目标集群信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(uavpsMultiTargetFormationService.deleteUavpsMultiTargetFormationByIds(ids));
    }
}
