package com.srs.web.controller.comprehensive;

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

import com.srs.comprehensive.domain.CphFamilyMember;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;

import com.srs.comprehensive.domain.SrsEducationExperience;
import com.srs.comprehensive.service.ISrsEducationExperienceService;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.enums.BusinessType;
import com.srs.common.annotation.Log;
import com.srs.common.core.page.TableDataInfo;

/**
 * 教育经历
 * Controller
 *
 * @author srs
 * @date 2024-04-08
 */
@RestController
@RequestMapping("/comprehensive/experience")
@Api(value = "教育经历 管理", tags = "教育经历")
public class SrsEducationExperienceController extends BaseController {
    @Autowired
    private ISrsEducationExperienceService srsEducationExperienceService;

    @GetMapping("/getOwnExp")
    @ApiOperation("查询学生自己的教育经历列表")
    public AjaxResult getOwnExp(){
        List<SrsEducationExperience> list = srsEducationExperienceService.getStuExp(getUsername());
        return AjaxResult.success(list);
    }

    /**
     * 跟据学号查询学生教育经历列表
     * @return
     */
    @GetMapping("/getOwnExpByStuNo")
    @ApiOperation("跟据学号查询学生教育经历列表")
    public AjaxResult getOwnExp(@RequestParam String stuNo){
        List<SrsEducationExperience> list = srsEducationExperienceService.getStuExp(stuNo);
        return AjaxResult.success(list);
    }
    @PostMapping("/editOwnExp")
    @ApiOperation("修改学生自己的家庭成员")
    public AjaxResult editOwnExp(@RequestBody SrsEducationExperience param){
        param.setStuNo(getUsername());
        return srsEducationExperienceService.editOwnExp(param);
    }

    @PostMapping("/deleteOwnExp/{id}")
    @ApiOperation("删除学生自己的家庭成员")
    public AjaxResult deleteOwnExp(@PathVariable("id") Long id){
        SrsEducationExperience param = new SrsEducationExperience();
        param.setEduId(id);
        param.setStuNo(getUsername());
        return srsEducationExperienceService.deleteOwnExp(param);
    }


    @PostMapping("/addOwnExp")
    @ApiOperation("添加学生自己的家庭成员")
    public AjaxResult addOwnExp(@RequestBody SrsEducationExperience param){
        param.setStuNo(getUsername());
        return toAjax(srsEducationExperienceService.insertSrsEducationExperience(param));
    }



    /**
     * 查询教育经历
     * 列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:experience:list')")
    @GetMapping("/list")
    @ApiOperation("查询教育经历列表")
    public TableDataInfo list(SrsEducationExperience srsEducationExperience) {
        startPage();
        List<SrsEducationExperience> list = srsEducationExperienceService.selectSrsEducationExperienceList(srsEducationExperience);
        return getDataTable(list);
    }

    /**
     * 导出教育经历
     * 列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:experience:export')")
    @Log(title = "教育经历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出教育经历列表")
    public void export(HttpServletResponse response, SrsEducationExperience srsEducationExperience) {
        List<SrsEducationExperience> list = srsEducationExperienceService.selectSrsEducationExperienceList(srsEducationExperience);
        ExcelUtil<SrsEducationExperience> util = new ExcelUtil<SrsEducationExperience>(SrsEducationExperience.class);
        util.exportExcel(response, list, "教育经历数据");
    }

    /**
     * 获取教育经历
     * 详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:experience:query')")
    @GetMapping(value = "/{eduId}")
    @ApiOperation("获取教育经历详细信息")
    public AjaxResult getInfo(@PathVariable("eduId") Long eduId) {
        return success(srsEducationExperienceService.selectSrsEducationExperienceByEduId(eduId));
    }

    /**
     * 新增教育经历
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:experience:add')")
    @Log(title = "教育经历", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增教育经历")
    public AjaxResult add(@RequestBody SrsEducationExperience srsEducationExperience) {
        return toAjax(srsEducationExperienceService.insertSrsEducationExperience(srsEducationExperience));
    }

    /**
     * 修改教育经历
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:experience:edit')")
    @Log(title = "教育经历", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改教育经历")
    public AjaxResult edit(@RequestBody SrsEducationExperience srsEducationExperience) {
        return toAjax(srsEducationExperienceService.updateSrsEducationExperience(srsEducationExperience));
    }

    /**
     * 删除教育经历
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:experience:remove')")
    @Log(title = "教育经历", businessType = BusinessType.DELETE)
    @PostMapping("/{eduIds}")
    @ApiOperation("删除教育经历")
    public AjaxResult remove(@PathVariable Long[] eduIds) {
        return toAjax(srsEducationExperienceService.deleteSrsEducationExperienceByEduIds(eduIds));
    }
}
