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.entity.SysUser;
import com.djhk.common.core.page.TableDataInfo;
import com.djhk.common.enums.BusinessType;
import com.djhk.common.utils.DateUtils;
import com.djhk.common.utils.SecurityUtils;
import com.djhk.common.utils.poi.ExcelUtil;
import com.djhk.system.service.ISysUserService;
import com.djhk.uav.uav.model.UavRealInfo;
import com.djhk.uav.uav.service.IUavRealInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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


/**
 * 靶机库反制设备对应机型实测数据 controller
 * @author zhulongchuan
 * @date 2024-11-07
 */
@RestController
@RequestMapping("/realInfo")
public class UavRealInfoController extends BaseController {

    @Autowired
    private IUavRealInfoService UavRealInfoService;
//    @Autowired
//    private RemoteUserService remoteUserService;

    @Autowired
    private ISysUserService userService;


    /**
     * 查询列表
     */
    @GetMapping("/list")
    public TableDataInfo list(UavRealInfo uavRealInfo)
    {
        startPage();
        List<UavRealInfo> list = UavRealInfoService.selectUavRealInfoList(uavRealInfo);
        return getDataTable(list);
    }


    /**
     * 导出列表
     */
//    @RequiresPermissions("uav:info:export")
    @Log(title = "反制设备对应机型实测数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UavRealInfo uavRealInfo)
    {
        List<UavRealInfo> list =  UavRealInfoService.selectUavRealInfoList(uavRealInfo);
        ExcelUtil<UavRealInfo> util = new ExcelUtil<UavRealInfo>(UavRealInfo.class);
        util.exportExcel(response, list, "无人机信息数据");
    }

    /**
     * 获取详细信息
     */
//    @RequiresPermissions("uav:info:query")
    @GetMapping(value = "/{id}")
    public UavRealInfo getInfo(@PathVariable("id") Long id)
    {
        return UavRealInfoService.selectUavRealInfoByUavId(id);
    }

    /**
     * 新增靶机库反制设备对应机型实测数据
     */
//    @RequiresPermissions("uav:info:add")
    @Log(title = "靶机库反制设备对应机型实测数据", businessType = BusinessType.INSERT)
    @PostMapping
    public int add(@RequestBody UavRealInfo uavRealInfo)
    {
//        if(StringUtils.isEmpty(uavInfo.getUavNum())){
//            return R.fail("无人机编号不能为空");
//        }
//        if(StringUtils.isEmpty(uavInfo.getUavType())){
//            return R.fail("无人机机型不能为空");
//        }
//        if(StringUtils.isEmpty(uavInfo.getMachineNum())){
//            return R.fail("无人机机号不能为空");
//        }
//        SysUser sysUser = remoteUserService.getUserInfoByUserId(SecurityUtils.getUserId(), SecurityConstants.INNER).getData();
        SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
        Date nowDate = DateUtils.getNowDate();
        uavRealInfo.setCreateBy(sysUser.getUserName());
        uavRealInfo.setCreateTime(nowDate);
        return UavRealInfoService.insertUavRealInfo(uavRealInfo);
    }

    /**
     * 修改
     */
//    @RequiresPermissions("uav:info:edit")
    @Log(title = "靶机库反制设备对应机型实测数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public int edit(@RequestBody UavRealInfo uavRealInfo)
    {
//        if(StringUtils.isEmpty(uavInfo.getUavName())){
//            return R.fail("无人机名称不能为空");
//        }
//        if(StringUtils.isEmpty(uavInfo.getUavNum())){
//            return R.fail("无人机编号不能为空");
//        }
//        if(StringUtils.isEmpty(uavInfo.getUavType())){
//            return R.fail("无人机机型不能为空");
//        }
//        if(StringUtils.isEmpty(uavInfo.getMachineNum())){
//            return R.fail("无人机机号不能为空");
//        }
//        SysUser sysUser = remoteUserService.getUserInfoByUserId(SecurityUtils.getUserId(), SecurityConstants.INNER).getData();
        SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
        Date nowDate = DateUtils.getNowDate();
        uavRealInfo.setUpdateBy(sysUser.getUpdateBy());
        uavRealInfo.setUpdateTime(nowDate);
        return UavRealInfoService.updateUavRealInfo(uavRealInfo);
    }



    /**
     * 删除
     */
//    @RequiresPermissions("uav:info:remove")
    @Log(title = "靶机库反制设备对应机型实测数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public int remove(@PathVariable Long[] ids)
    {
        return UavRealInfoService.deleteUavRealInfoByUavIds(ids);
    }


}
