package com.djhk.uav.uav.controller;

import com.djhk.common.annotation.Log;
import com.djhk.common.core.controller.BaseController;
import com.djhk.common.core.domain.R;
import com.djhk.common.core.page.TableDataInfo;
import com.djhk.common.enums.BusinessType;
import com.djhk.common.utils.poi.ExcelUtil;
import com.djhk.uav.uav.model.UavOrganization;
import com.djhk.uav.uav.service.IUavOrganizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 无人机编队Controller
 *
 * @author jiachengshuai
 * @date 2023-02-28
 */
@RestController
@RequestMapping("/organization")
public class UavOrganizationController extends BaseController
{
    @Autowired
    private IUavOrganizationService uavOrganizationService;

    /**
     * 查询无人机编队列表
     */
//    @RequiresPermissions("uav:organization:list")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam Map<String, Object> param)
    {
        return uavOrganizationService.selectOrganizationTableData(param);
    }

    /**
     * 导出无人机编队列表
     */
//    @RequiresPermissions("uav:organization:export")
    @Log(title = "无人机编队", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody Map<String, Object> param)
    {
        R<List<UavOrganization>> r = uavOrganizationService.selectUavOrganizationList(param);
        if(r.getCode() == 200){
            List<UavOrganization> list = r.getData();
            ExcelUtil<UavOrganization> util = new ExcelUtil<UavOrganization>(UavOrganization.class);
            util.exportExcel(response, list, "无人机编队数据");
        }else{
            response.setStatus(r.getCode());
        }

    }

    /**
     * 获取无人机编队详细信息
     */
//    @RequiresPermissions("uav:organization:query")
    @GetMapping(value = "/{id}")
    public R<UavOrganization> getInfo(@PathVariable("id") Long id)
    {
        return uavOrganizationService.selectUavOrganizationById(id);
    }

    /**
     * 新增无人机编队
     */
//    @RequiresPermissions("uav:organization:add")
    @Log(title = "无人机编队", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody UavOrganization uavOrganization)
    {
        return uavOrganizationService.insertUavOrganization(uavOrganization);
    }

    /**
     * 修改无人机编队
     */
//    @RequiresPermissions("uav:organization:edit")
    @Log(title = "无人机编队", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody UavOrganization uavOrganization)
    {
        return uavOrganizationService.updateUavOrganization(uavOrganization);
    }

    /**
     * 删除无人机编队
     */
//    @RequiresPermissions("uav:organization:remove")
    @Log(title = "无人机编队", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R remove(@PathVariable Long[] ids)
    {
        return uavOrganizationService.deleteUavOrganizationByIds(ids);
    }
}
