package com.ruoyi.app.user;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UserFootprint;
import com.ruoyi.system.service.IUserFootprintService;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * footprintController
 *
 * @author ruoyi
 * @date 2023-06-16
 */
@Api(value = "UserFootprintController", description = "足迹管理")
@RestController
@RequestMapping("/system/footprint")
public class UserFootprintController extends BaseController
{
    @Autowired
    private IUserFootprintService userFootprintService;

    /**
     * 查询footprint列表
     */
    @ApiOperation("查询footprint列表")
    @PreAuthorize("@ss.hasPermi('system:footprint:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserFootprint userFootprint)
    {
        startPage();
        List<UserFootprint> list = userFootprintService.selectUserFootprintList(userFootprint);
        return getDataTable(list);
    }

    /**
     * 导出footprint列表
     */
    @ApiOperation( "导出footprint列表")
    @PreAuthorize("@ss.hasPermi('system:footprint:export')")
    @Log(title = "footprint", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserFootprint userFootprint)
    {
        List<UserFootprint> list = userFootprintService.selectUserFootprintList(userFootprint);
        ExcelUtil<UserFootprint> util = new ExcelUtil<UserFootprint>(UserFootprint.class);
        util.exportExcel(response, list, MessageUtils.message("no.export.excel.footprint"));
    }

    /**
     * 获取footprint详细信息
     */
    @ApiOperation(value =  "获取footprint详细信息")
    @PreAuthorize("@ss.hasPermi('system:footprint:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userFootprintService.selectUserFootprintById(id));
    }

    /**
     * 新增footprint
     */
    @ApiOperation(value ="新增footprint")
    @PreAuthorize("@ss.hasPermi('system:footprint:add')")
    @Log(title = "footprint", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserFootprint userFootprint)
    {
        return toAjax(userFootprintService.insertUserFootprint(userFootprint));
    }

    /**
     * 修改footprint
     */
    @ApiOperation(value ="修改footprint")
    @PreAuthorize("@ss.hasPermi('system:footprint:edit')")
    @Log(title = "footprint", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserFootprint userFootprint)
    {
        return toAjax(userFootprintService.updateUserFootprint(userFootprint));
    }

    /**
     * 删除footprint
     */
    @ApiOperation(value = "删除footprint")
    @PreAuthorize("@ss.hasPermi('system:footprint:remove')")
    @Log(title = "footprint", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userFootprintService.deleteUserFootprintByIds(ids));
    }
}
