package com.zhyc.module.produce.bodyManage.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.*;
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.bodyManage.domain.ScBodyScore;
import com.zhyc.module.produce.bodyManage.service.IScBodyScoreService;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.common.core.page.TableDataInfo;

/**
 * 体况评分Controller
 * 
 * @author ruoyi
 * @date 2025-07-27
 */
@RestController
@RequestMapping("/body_score/body_score")
public class ScBodyScoreController extends BaseController
{
    @Autowired
    private IScBodyScoreService scBodyScoreService;

    /**
     * 查询体况评分列表
     */
    @PreAuthorize("@ss.hasPermi('body_score:body_score:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScBodyScore scBodyScore)
    {
        startPage();
        List<ScBodyScore> list = scBodyScoreService.selectScBodyScoreList(scBodyScore);
        return getDataTable(list);
    }

    /**
     * 导出体况评分列表
     */
    @PreAuthorize("@ss.hasPermi('body_score:body_score:export')")
    @Log(title = "体况评分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScBodyScore scBodyScore)
    {
        List<ScBodyScore> list = scBodyScoreService.selectScBodyScoreList(scBodyScore);
        ExcelUtil<ScBodyScore> util = new ExcelUtil<ScBodyScore>(ScBodyScore.class);
        util.exportExcel(response, list, "体况评分数据");
    }

    /**
     * 获取体况评分详细信息
     */
    @PreAuthorize("@ss.hasPermi('body_score:body_score:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scBodyScoreService.selectScBodyScoreById(id));
    }

    /**
     * 新增体况评分
     */
    @PreAuthorize("@ss.hasPermi('body_score:body_score:add')")
    @Log(title = "体况评分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScBodyScore scBodyScore)
    {
        scBodyScore.setUserId(getUserId());
        scBodyScore.setDeptId(getDeptId());
        return toAjax(scBodyScoreService.insertScBodyScore(scBodyScore));
    }

    /**
     * 修改体况评分
     */
    @PreAuthorize("@ss.hasPermi('body_score:body_score:edit')")
    @Log(title = "体况评分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScBodyScore scBodyScore)
    {
        return toAjax(scBodyScoreService.updateScBodyScore(scBodyScore));
    }

    /**
     * 删除体况评分
     */
    @PreAuthorize("@ss.hasPermi('body_score:body_score:remove')")
    @Log(title = "体况评分", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scBodyScoreService.deleteScBodyScoreByIds(ids));
    }

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