package com.djhk.uav.sysPolice.controller;



import com.djhk.common.annotation.Log;
import com.djhk.common.api.domain.SysPoliceFly;
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.domain.model.LoginUser;
import com.djhk.common.core.page.TableDataInfo;
import com.djhk.common.enums.BusinessType;
import com.djhk.common.exception.ServiceException;
import com.djhk.common.utils.SecurityUtils;

import com.djhk.system.service.ISysUserService;
import com.djhk.uav.sysPolice.service.ISysPoliceFlyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 警员信息
 */
@RestController
@RequestMapping("/sysPolice")
public class SysPoliceFlyController {

    @Resource
    private ISysPoliceFlyService iSysPoliceFlyService;
    private ISysUserService userService;

    /**
     * 获取警员列表
     */
    @GetMapping("/list")
    public AjaxResult list(SysPoliceFly sysPoliceFly)
    {
        List<SysPoliceFly> sysPolices = iSysPoliceFlyService.selectDeptList(sysPoliceFly);
        return AjaxResult.success(sysPolices);
    }

    /**
     * 新增警员信息
     */
    @PostMapping
    public AjaxResult add(@RequestBody SysPoliceFly sysPoliceFly)
    {
//        SysUser sysUser = userService.getUserInfoByUserId(SecurityUtils.getUserId(), SecurityConstants.INNER).getData();
//        sysPoliceFly.setCreateBy(sysUser.getUserName());
        SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
        return AjaxResult.success( iSysPoliceFlyService.insertDept(sysPoliceFly));
    }



    /**
     * 修改警员信息
     */
    @PutMapping
    public AjaxResult update(@RequestBody SysPoliceFly sysPoliceFly)
    {
//        SysUser sysUser = userService.getUserInfoByUserId(SecurityUtils.getUserId(), SecurityConstants.INNER).getData();
//        sysPoliceFly.setCreateBy(sysUser.getUserName());
        SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
        return AjaxResult.success( iSysPoliceFlyService.updateDept(sysPoliceFly));
    }


    /**
     * 删除警员信息
     */
    @DeleteMapping
    public AjaxResult delete(@PathVariable Long id)
    {
        return AjaxResult.success( iSysPoliceFlyService.deleteDeptById(id));
    }

}
