package com.zhyc.module.produce.manage_sheep.controller;

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

import com.zhyc.module.produce.manage_sheep.domain.ScTransGroup;
import com.zhyc.module.produce.manage_sheep.service.IScTransGroupService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zhyc.common.annotation.Log;
import com.zhyc.common.core.controller.BaseController;
import com.zhyc.common.core.domain.AjaxResult;
import com.zhyc.common.enums.BusinessType;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.common.core.page.TableDataInfo;

/**
 * 转群记录Controller
 *
 * @author ruoyi
 * @date 2025-07-10
 */
@RestController
@RequestMapping("produce/manage_sheep/trans_group")
public class ScTransGroupController extends BaseController {
    @Autowired
    private IScTransGroupService scTransGroupService;

    /**
     * 查询转群记录列表
     */
    @PreAuthorize("@ss.hasPermi('produce:trans_group:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScTransGroup scTransGroup) {
        startPage();
        List<ScTransGroup> list = scTransGroupService.selectScTransGroupList(scTransGroup);
        return getDataTable(list);
    }

    /**
     * 导出转群记录列表
     */
    @PreAuthorize("@ss.hasPermi('produce:trans_group:export')")
    @Log(title = "转群记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScTransGroup scTransGroup) throws IOException {
        List<ScTransGroup> list = scTransGroupService.selectScTransGroupList(scTransGroup);
        ExcelUtil<ScTransGroup> util = new ExcelUtil<>(ScTransGroup.class);
        util.exportExcel(response, list, "转群记录数据");
    }

    /**
     * 获取转群记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('produce:trans_group:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(scTransGroupService.selectScTransGroupById(id));
    }

    /**
     * 新增转群记录
     */
    @PreAuthorize("@ss.hasPermi('produce:trans_group:add')")
    @Log(title = "转群记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScTransGroup scTransGroup) {
        scTransGroup.setUserId(getUserId());
        scTransGroup.setDeptId(getDeptId());
        return toAjax(scTransGroupService.insertScTransGroup(scTransGroup));
    }

    /**
     * 修改转群记录
     */
    @PreAuthorize("@ss.hasPermi('produce:trans_group:edit')")
    @Log(title = "转群记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScTransGroup scTransGroup) {
        return toAjax(scTransGroupService.updateScTransGroup(scTransGroup));
    }

    /**
     * 删除转群记录
     */
    @PreAuthorize("@ss.hasPermi('produce:trans_group:remove')")
    @Log(title = "转群记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(scTransGroupService.deleteScTransGroupByIds(ids));
    }

    @GetMapping("/search_ear_numbers")
    public AjaxResult searchEarNumbers(@RequestParam("query") String query){
        return success(scTransGroupService.searchEarNumbers(query.trim()));
    }
}
