package hw.tagApi.service.controller;

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

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 hw.tagApi.common.annotation.Log;
import hw.tagApi.common.core.controller.BaseController;
import hw.tagApi.common.core.domain.AjaxResult;
import hw.tagApi.common.enums.BusinessType;
import hw.tagApi.service.domain.HwTagRecord;
import hw.tagApi.service.service.IHwTagRecordService;
import hw.tagApi.common.utils.poi.ExcelUtil;
import hw.tagApi.common.core.page.TableDataInfo;

/**
 * 标签记录Controller
 *
 * @author Yinq
 * @date 2025-04-15
 */
@RestController
@RequestMapping("/service/tagRecord")
public class HwTagRecordController extends BaseController {
    @Autowired
    private IHwTagRecordService hwTagRecordService;

    /**
     * 查询标签记录列表
     */
    @PreAuthorize("@ss.hasPermi('service:tagRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(HwTagRecord hwTagRecord) {
        startPage();
        List<HwTagRecord> list = hwTagRecordService.selectHwTagRecordList(hwTagRecord);
        return getDataTable(list);
    }

    /**
     * 导出标签记录列表
     */
    @PreAuthorize("@ss.hasPermi('service:tagRecord:export')")
    @Log(title = "标签记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HwTagRecord hwTagRecord) {
        List<HwTagRecord> list = hwTagRecordService.selectHwTagRecordList(hwTagRecord);
        ExcelUtil<HwTagRecord> util = new ExcelUtil<HwTagRecord>(HwTagRecord.class);
        util.exportExcel(response, list, "标签记录数据");
    }

    /**
     * 获取标签记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:tagRecord:query')")
    @GetMapping(value = "/{rId}")
    public AjaxResult getInfo(@PathVariable("rId") Long rId) {
        return success(hwTagRecordService.selectHwTagRecordByRId(rId));
    }

    /**
     * 新增标签记录
     */
    @PreAuthorize("@ss.hasPermi('service:tagRecord:add')")
    @Log(title = "标签记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HwTagRecord hwTagRecord) {
        return toAjax(hwTagRecordService.insertHwTagRecord(hwTagRecord));
    }

    /**
     * 修改标签记录
     */
    @PreAuthorize("@ss.hasPermi('service:tagRecord:edit')")
    @Log(title = "标签记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HwTagRecord hwTagRecord) {
        return toAjax(hwTagRecordService.updateHwTagRecord(hwTagRecord));
    }

    /**
     * 删除标签记录
     */
    @PreAuthorize("@ss.hasPermi('service:tagRecord:remove')")
    @Log(title = "标签记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{rIds}")
    public AjaxResult remove(@PathVariable Long[] rIds) {
        return toAjax(hwTagRecordService.deleteHwTagRecordByRIds(rIds));
    }
}
