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.BaseEntity;
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.SysWharf;
import com.aidex.system.service.SysWharfService;
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 914769835
 * @date 2024-03-16
 */
@RestController
@RequestMapping("/system/sysWharf")
public class SysWharfController extends BaseController {

    @Autowired
    private SysWharfService sysWharfService;

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

    /**
     * 查询码头管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysWharf:list')")
    @GetMapping("/getAll")
    public R<List<SysWharf>> getAll() {
        SysWharf sysWharf = new SysWharf();
        sysWharf.setStatus(BaseEntity.STATUS_NORMAL);
        return R.data(sysWharfService.findList(sysWharf));
    }

    /**
     * 获取码头管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sysWharf:query')")
    @GetMapping(value = "/{id}")
    public R<SysWharf> detail(@PathVariable("id") String id) {
        return R.data(sysWharfService.get(id));
    }

    /**
     * 新增码头管理
     */
    @PreAuthorize("@ss.hasPermi('system:sysWharf:add')")
    @Log(title = "码头管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  SysWharf sysWharf) {
        return R.status(sysWharfService.save(sysWharf));
    }

    /**
     * 修改码头管理
     */
    @PreAuthorize("@ss.hasPermi('system:sysWharf:edit')")
    @Log(title = "码头管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated SysWharf sysWharf) {
        return R.status(sysWharfService.save(sysWharf));
    }

    /**
     * 修改码头状态
     */
    @PreAuthorize("@ss.hasPermi('system:sysWharf:edit')")
    @Log(title = "码头管理", businessType = BusinessType.UPDATE)
    @PutMapping("/updateStatus")
    public R updateStatus(@RequestBody @Validated SysWharf sysWharf) {
        return R.status(sysWharfService.updateStatus(sysWharf));
    }

    /**
     * 删除码头管理
     */
    @PreAuthorize("@ss.hasPermi('system:sysWharf:remove')")
    @Log(title = "码头管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(sysWharfService.deleteSysWharfByIds(ids));
    }


    /**
     * 导出码头管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysWharf:export')")
    @Log(title = "码头管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(SysWharf sysWharf) {
        List<SysWharf> list = sysWharfService.findList(sysWharf);
        ExcelUtil<SysWharf> util = new ExcelUtil<SysWharf>(SysWharf.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);
    }

}
