package com.djhk.uav.policeWarLawLibrary.controller;


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.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.uav.policeWarLawLibrary.domain.PoliceWarLawLibrary;
import com.djhk.uav.policeWarLawLibrary.domain.PoliceWarLawLibraryAddVO;
import com.djhk.uav.policeWarLawLibrary.domain.warNameVo;
import com.djhk.uav.policeWarLawLibrary.service.IPoliceWarLawLibraryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * 战法库Controller
 * 
 * @author ruoyi
 * @date 2024-11-21
 */
@RestController
@RequestMapping("/policeWarLawLibrary")
public class PoliceWarLawLibraryController extends BaseController
{
    @Autowired
    private IPoliceWarLawLibraryService policeWarLawLibraryService;

    /**
     * 查询战法库数据列表
     */
    @PostMapping("/list")
    public AjaxResult list(@RequestBody PoliceWarLawLibrary policeWarLawLibrary)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (null == loginUser) {
            throw new ServiceException("登录失效，请重新登录！", 500);
        }

        policeWarLawLibrary.setDeptId(SecurityUtils.getDeptId());
        HashMap<String, Object> map = policeWarLawLibraryService.selectPoliceWarLawLibraryList(policeWarLawLibrary);
        return AjaxResult.success(map);
    }
    /**
     * 查询战法库名称列表
     */
    @GetMapping("/warNameList")
    public TableDataInfo warNameList(PoliceWarLawLibrary policeWarLawLibrary)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (null == loginUser) {
            throw new ServiceException("登录失效，请重新登录！", 500);
        }

//        policeWarLawLibrary.setDeptId(loginUser.getSysUser().getDeptId());
        policeWarLawLibrary.setDeptId(SecurityUtils.getDeptId());
        List<warNameVo> list = policeWarLawLibraryService.warNameList(policeWarLawLibrary);
        return getDataTable(list);
    }

    /**
     * 导出战法库列表
     */
    @Log(title = "战法库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PoliceWarLawLibrary policeWarLawLibrary) throws Exception {
        policeWarLawLibraryService.exprotByTenplete(response,policeWarLawLibrary);
    }




    /**
     * 获取战法库详细信息
     */
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Long id)
//    {
//        return success(policeWarLawLibraryService.selectPoliceWarLawLibraryById(id));
//    }

    /**
     * 新增战法库
     */
    @Log(title = "战法库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PoliceWarLawLibraryAddVO policeWarLawLibraryAddVO)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (null == loginUser) {
            throw new ServiceException("登录失效，请重新登录！", 500);
        }

//        policeWarLawLibraryAddVO.setDeptId(loginUser.getSysUser().getDeptId());
        policeWarLawLibraryAddVO.setDeptId(SecurityUtils.getDeptId());
        Date date = new Date();
        String d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
        policeWarLawLibraryAddVO.setWarName(policeWarLawLibraryAddVO.getWarName() + d);
        return toAjax(policeWarLawLibraryService.insertPoliceWarLawLibrary(policeWarLawLibraryAddVO));
    }

    /**
     * 修改战法库
     */
    @Log(title = "战法库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PoliceWarLawLibrary policeWarLawLibrary)
    {
        return toAjax(policeWarLawLibraryService.updatePoliceWarLawLibrary(policeWarLawLibrary));
    }

    /**
     * 删除战法库
     */
    @Log(title = "战法库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(policeWarLawLibraryService.deletePoliceWarLawLibraryByIds(ids));
    }

    /**
     * 根据战法名称删除战法库
     */
    @Log(title = "根据战法名称删除战法库", businessType = BusinessType.DELETE)
    @PostMapping("/removeByWarName")
    public AjaxResult removeByWarName(@RequestParam String warName)
    {
        return toAjax(policeWarLawLibraryService.removeByWarName(warName));
    }
}
