package com.ruoyi.szxc.controller;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.szxc.domain.SzxcJmTag;
import com.ruoyi.szxc.service.ISzxcJmTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 居民标签关联Controller
 *
 * @author hs
 * @date 2024-03-30
 */
@RestController
@RequestMapping("/szxc/jmtag")
public class SzxcJmTagController extends BaseController
{
    @Autowired
    private ISzxcJmTagService szxcJmTagService;

    /**
     * 查询居民标签关联列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:jmtag:list')")
    @GetMapping("/list")
    public TableDataInfo list(SzxcJmTag szxcJmTag)
    {
        startPage();
        List<SzxcJmTag> list = szxcJmTagService.selectSzxcJmTagList(szxcJmTag);
        return getDataTable(list);
    }

    /**
     * 导出居民标签关联列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:jmtag:export')")
    @Log(title = "居民标签关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SzxcJmTag szxcJmTag)
    {
        List<SzxcJmTag> list = szxcJmTagService.selectSzxcJmTagList(szxcJmTag);
        ExcelUtil<SzxcJmTag> util = new ExcelUtil<SzxcJmTag>(SzxcJmTag.class);
        util.exportExcel(response, list, "居民标签关联数据");
    }

    /**
     * 获取居民标签关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:jmtag:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(szxcJmTagService.selectSzxcJmTagById(id));
    }

    /**
     * 新增、修改、删除居民标签集合关联
     */
    @PreAuthorize("@ss.hasPermi('szxc:jmtag:add')")
    @Log(title = "居民标签关联", businessType = BusinessType.UPDATE)
    @PostMapping("/addAll")
    public AjaxResult addAll(@RequestBody JSONObject json)
    {
        List<SzxcJmTag> szxcJmTags = json.getJSONArray("szxcJmTags").toJavaList(SzxcJmTag.class);
        return toAjax(szxcJmTagService.insertSzxcJmTags(szxcJmTags));
    }

    /**
     * 新增居民标签关联
     */
    @PreAuthorize("@ss.hasPermi('szxc:jmtag:add')")
    @Log(title = "居民标签关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzxcJmTag szxcJmTag)
    {
        return toAjax(szxcJmTagService.insertSzxcJmTag(szxcJmTag));
    }

    /**
     * 修改居民标签关联
     */
    @PreAuthorize("@ss.hasPermi('szxc:jmtag:edit')")
    @Log(title = "居民标签关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzxcJmTag szxcJmTag)
    {
        return toAjax(szxcJmTagService.updateSzxcJmTag(szxcJmTag));
    }

    /**
     * 删除居民标签关联
     */
    @PreAuthorize("@ss.hasPermi('szxc:jmtag:remove')")
    @Log(title = "居民标签关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(szxcJmTagService.deleteSzxcJmTagByIds(ids));
    }
}
