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

import java.util.List;
import java.util.Map;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
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.module.produce.breed.domain.ScEmbryoFlush;
import com.zhyc.module.produce.breed.service.IScEmbryoFlushService;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.common.core.page.TableDataInfo;

/**
 * 冲胚记录Controller
 *
 * @author ruoyi
 * @date 2025-11-28
 */
@RestController
@RequestMapping("/embryo/flush")
public class ScEmbryoFlushController extends BaseController
{
    @Autowired
    private IScEmbryoFlushService scEmbryoFlushService;

    /**
     * 查询冲胚记录列表
     */
    @PreAuthorize("@ss.hasPermi('embryo:flush:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScEmbryoFlush scEmbryoFlush)
    {
        startPage();
        List<ScEmbryoFlush> list = scEmbryoFlushService.selectScEmbryoFlushList(scEmbryoFlush);
        return getDataTable(list);
    }

    /**
     * 导出冲胚记录列表
     */
    @PreAuthorize("@ss.hasPermi('embryo:flush:export')")
    @Log(title = "冲胚记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScEmbryoFlush scEmbryoFlush)
    {
        List<ScEmbryoFlush> list = scEmbryoFlushService.selectScEmbryoFlushList(scEmbryoFlush);
        ExcelUtil<ScEmbryoFlush> util = new ExcelUtil<ScEmbryoFlush>(ScEmbryoFlush.class);
        util.exportExcel(response, list, "冲胚记录数据");
    }

    /**
     * 获取冲胚记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('embryo:flush:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scEmbryoFlushService.selectScEmbryoFlushById(id));
    }

    /**
     * 新增冲胚记录
     */
    @PreAuthorize("@ss.hasPermi('embryo:flush:add')")
    @Log(title = "冲胚记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScEmbryoFlush scEmbryoFlush)
    {
        return toAjax(scEmbryoFlushService.insertScEmbryoFlush(scEmbryoFlush));
    }

    /**
     * 修改冲胚记录
     */
    @PreAuthorize("@ss.hasPermi('embryo:flush:edit')")
    @Log(title = "冲胚记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScEmbryoFlush scEmbryoFlush)
    {
        return toAjax(scEmbryoFlushService.updateScEmbryoFlush(scEmbryoFlush));
    }

    /**
     * 删除冲胚记录
     */
    @PreAuthorize("@ss.hasPermi('embryo:flush:remove')")
    @Log(title = "冲胚记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scEmbryoFlushService.deleteScEmbryoFlushByIds(ids));
    }

    /**
     * 根据供体母羊耳号获取关联信息
     * 返回：母羊品种、父号、父号品种、胚胎品种、牧场信息、配种日期等
     */
    @PreAuthorize("@ss.hasPermi('embryo:flush:query')")
    @GetMapping("/getDonorInfo")
    public AjaxResult getDonorRelatedInfo(@RequestParam("donorFemaleNo") String donorFemaleNo)
    {
        Map<String, Object> info = scEmbryoFlushService.getDonorRelatedInfo(donorFemaleNo);
        return success(info);
    }

    /**
     * 获取供体母羊下拉列表
     */
    @PreAuthorize("@ss.hasPermi('embryo:flush:query')")
    @GetMapping("/donorFemaleList")
    public AjaxResult getDonorFemaleList()
    {
        List<Map<String, Object>> list = scEmbryoFlushService.selectDonorFemaleList();
        return success(list);
    }
}