package com.fastbee.data.controller.userRecharge;

import java.util.List;
import javax.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.fastbee.common.annotation.Log;
import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.enums.BusinessType;
import com.fastbee.rechargecard.domain.UserIrrigationRecord;
import com.fastbee.rechargecard.service.IUserIrrigationRecordService;
import com.fastbee.common.utils.poi.ExcelUtil;
import com.fastbee.common.core.page.TableDataInfo;

/**
 * 灌溉记录Controller
 *
 * @author kerwincui
 * @date 2024-12-18
 */
@RestController
@RequestMapping("/rechargecard/record")
@Api(tags = "灌溉记录")
public class UserIrrigationRecordController extends BaseController
{
    @Autowired
    private IUserIrrigationRecordService userIrrigationRecordService;

    /**
     * 查询灌溉记录列表
     */
    @PreAuthorize("@ss.hasPermi('rechargecard:record:list')")
    @GetMapping("/list")
    @ApiOperation("查询灌溉记录列表")
    public TableDataInfo list(UserIrrigationRecord userIrrigationRecord)
    {
        startPage();
        List<UserIrrigationRecord> list = userIrrigationRecordService.selectUserIrrigationRecordList(userIrrigationRecord);
        return getDataTable(list);
    }

    /**
     * 获取用户灌溉记录详细信息列表
     */
    @PreAuthorize("@ss.hasPermi('rechargecard:record:query')")
    @GetMapping(value = "/list/{cardNumber}")
    @ApiOperation("获取灌溉记录详细信息")
    public AjaxResult getInfo(@PathVariable("cardNumber") String cardNumber)
    {
        return success(userIrrigationRecordService.selectUserIrrigationRecordListBycardNumber(cardNumber));
    }

    /**
     * 获取用户灌溉记录展示详细信息列表
     */
    @PreAuthorize("@ss.hasPermi('rechargecard:record:query')")
    @GetMapping(value = "/list/show/{cardNumber}")
    @ApiOperation("获取灌溉记录详细信息")
    public AjaxResult getShowInfo(@PathVariable("cardNumber") String cardNumber)
    {
        return success(userIrrigationRecordService.selectUserIrrigationRecordListShowBycardNumber(cardNumber));
    }

    /**
     * 导出灌溉记录列表
     */
    @ApiOperation("导出灌溉记录列表")
    @PreAuthorize("@ss.hasPermi('rechargecard:record:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserIrrigationRecord userIrrigationRecord)
    {
        List<UserIrrigationRecord> list = userIrrigationRecordService.selectUserIrrigationRecordList(userIrrigationRecord);
        ExcelUtil<UserIrrigationRecord> util = new ExcelUtil<UserIrrigationRecord>(UserIrrigationRecord.class);
        util.exportExcel(response, list, "灌溉记录数据");
    }

    /**
     * 获取灌溉记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('rechargecard:record:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取灌溉记录详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userIrrigationRecordService.selectUserIrrigationRecordById(id));
    }

    /**
     * 新增灌溉记录
     */
    @PreAuthorize("@ss.hasPermi('rechargecard:record:add')")
    @PostMapping
    @ApiOperation("新增灌溉记录")
    public AjaxResult add(@RequestBody UserIrrigationRecord userIrrigationRecord)
    {
        return toAjax(userIrrigationRecordService.insertUserIrrigationRecord(userIrrigationRecord));
    }

    /**
     * 修改灌溉记录
     */
    @PreAuthorize("@ss.hasPermi('rechargecard:record:edit')")
    @PutMapping
    @ApiOperation("修改灌溉记录")
    public AjaxResult edit(@RequestBody UserIrrigationRecord userIrrigationRecord)
    {
        return toAjax(userIrrigationRecordService.updateUserIrrigationRecord(userIrrigationRecord));
    }

    /**
     * 删除灌溉记录
     */
    @PreAuthorize("@ss.hasPermi('rechargecard:record:remove')")
    @DeleteMapping("/{ids}")
    @ApiOperation("删除灌溉记录")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userIrrigationRecordService.deleteUserIrrigationRecordByIds(ids));
    }
}
