package com.aidex.web.controller.system;

import com.aidex.common.annotation.Log;
import com.aidex.common.core.controller.BaseController;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.page.PageDomain;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import com.aidex.framework.cache.DictUtils;
import com.aidex.system.domain.SysShip;
import com.aidex.system.service.SysShipService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * 船只管理Controller
 * @author ChenSir
 * @email 91476835
 * @date 2024-03-16
 */
@RestController
@RequestMapping("/system/sysShip")
public class SysShipController extends BaseController {

    @Autowired
    private SysShipService sysShipService;

    /**
     * 查询船只管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysShip:list')")
    @GetMapping("/list")
    public R<PageInfo> list(SysShip sysShip, HttpServletRequest request, HttpServletResponse response) {
        sysShip.setPage(new PageDomain(request, response));
        return R.data(sysShipService.findPage(sysShip));
    }

    @PreAuthorize("@ss.hasPermi('system:sysShip:list')")
    @GetMapping("/listAll")
    public R<List<SysShip>> listAll(SysShip sysShip) {
        return R.data(sysShipService.findList(sysShip));
    }

    /**
     * 获取船只管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sysShip:query')")
    @GetMapping(value = "/{id}")
    public R<SysShip> detail(@PathVariable("id") String id) {
        return R.data(sysShipService.get(id));
    }

    /**
     * 新增船只管理
     */
    @PreAuthorize("@ss.hasPermi('system:sysShip:add')")
    @Log(title = "船只管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  SysShip sysShip) {
        return R.status(sysShipService.save(sysShip));
    }

    /**
     * 修改船只管理
     */
    @PreAuthorize("@ss.hasPermi('system:sysShip:edit')")
    @Log(title = "船只管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated SysShip sysShip) {
        return R.status(sysShipService.save(sysShip));
    }

    /**
     * 删除船只管理
     */
    @PreAuthorize("@ss.hasPermi('system:sysShip:remove')")
    @Log(title = "船只管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(sysShipService.deleteSysShipByIds(ids));
    }


    /**
     * 导出船只管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysShip:export')")
    @Log(title = "船只管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(SysShip sysShip) {
        List<SysShip> list = sysShipService.findList(sysShip);
        ExcelUtil<SysShip> util = new ExcelUtil<SysShip>(SysShip.class);
        return util.exportExcel(list, "船只管理数据");
    }

    /**
     * 根据字典类型查询字典数据信息等其他自定义信息
     */
    @GetMapping(value = "/getInitData/{dictTypes}")
    public R getInitData(@PathVariable String dictTypes) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.putAll(DictUtils.getMultiDictList(dictTypes));
        return R.data(dataMap);
    }

}
