package com.djhk.uav.uav.controller;



import com.djhk.common.core.controller.BaseController;
import com.djhk.common.utils.DateUtils;
import com.djhk.system.service.ISysUserService;
import com.djhk.uav.uav.model.UavInformation;
import com.djhk.uav.uav.service.IUavInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.djhk.common.annotation.Log;
import com.djhk.common.core.controller.BaseController;
import com.djhk.common.core.domain.AjaxResult;
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.SecurityUtils;
import com.djhk.common.utils.ServletUtils;
import com.djhk.common.utils.poi.ExcelUtil;
import com.djhk.system.service.ISysUserService;
import com.djhk.uav.uav.domain.ThreedModelInfo;
import com.djhk.uav.uav.domain.ThreedModelInfoVo;
import com.djhk.uav.uav.service.IThreedModelInfoService;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;


/**
 * 靶机库反制设备 controller
 * @author zhulongchuan
 * @date 2024-11-07
 */
@RestController
@RequestMapping("/information")
public class UavInformationController extends BaseController {

    @Autowired
    private IUavInformationService uavInformationService;
//    @Autowired
//    private RemoteUserService remoteUserService;

    @Autowired
    private ISysUserService remoteUserService;




    /**
     * 查询列表
     */
    @GetMapping("/list")
    public TableDataInfo list(UavInformation uavInformation)
    {
        startPage();
        List<UavInformation> list = uavInformationService.selectUavInformationList(uavInformation);
        return getDataTable(list);
    }


    /**
     * 导出列表
     */
//    @RequiresPermissions("uav:info:export")
    @Log(title = "无人机信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UavInformation uavInformation)
    {
        List<UavInformation> list =  uavInformationService.selectUavInformationList(uavInformation);
        ExcelUtil<UavInformation> util = new ExcelUtil<UavInformation>(UavInformation.class);
        util.exportExcel(response, list, "无人机信息数据");
    }

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

    /**
     * 新增靶机库反制设备
     */
//    @RequiresPermissions("uav:info:add")
    @Log(title = "靶机库反制设备", businessType = BusinessType.INSERT)
    @PostMapping
    public int add(@RequestBody UavInformation uavInformation)
    {
//        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 =  remoteUserService.selectUserById(SecurityUtils.getUserId());
        Date nowDate = DateUtils.getNowDate();
        uavInformation.setCreateBy(sysUser.getUserName());
        uavInformation.setCreateTime(nowDate);
        return uavInformationService.insertUavInformation(uavInformation);
    }

    /**
     * 修改
     */
//    @RequiresPermissions("uav:info:edit")
    @Log(title = "靶机库反制设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public int edit(@RequestBody UavInformation uavInformation)
    {
//        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 =  remoteUserService.selectUserById(SecurityUtils.getUserId());
        Date nowDate = DateUtils.getNowDate();
        uavInformation.setUpdateBy(sysUser.getUpdateBy());
        uavInformation.setUpdateTime(nowDate);
        return uavInformationService.updateUavInformation(uavInformation);
    }



    /**
     * 删除
     */
//    @RequiresPermissions("uav:info:remove")
    @Log(title = "靶机库反制设备", businessType = BusinessType.DELETE)
//    @DeleteMapping("/delete/{uavIds}")
//    public int remove(@PathVariable Long[] uavIds)
//    {
//        return uavInformationService.deleteUavInformationByUavIds(uavIds);
//    }

    @DeleteMapping(value = "/{uavIds}")
    public int remove(@PathVariable Long[] uavIds)
    {
        return uavInformationService.deleteUavInformationByUavIds(uavIds);
    }



}
