package com.jeeplus.human.enrollment.enrollmentRegistration.controller;

import com.jeeplus.human.enrollment.enrollmentRegistration.domain.EnrollmentEduInfo;
import com.jeeplus.human.enrollment.enrollmentRegistration.domain.EnrollmentTrainingInfo;
import com.jeeplus.human.enrollment.enrollmentRegistration.domain.EnrollmentWorkInfo;
import com.jeeplus.human.enrollment.enrollmentRegistration.service.EnrollmentEduInfoService;
import com.jeeplus.human.enrollment.enrollmentRegistration.service.EnrollmentTrainingInfoService;
import com.jeeplus.logging.annotation.ApiLog;
import com.jeeplus.logging.constant.enums.LogTypeEnum;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author 王强
 * @version 1.0
 */
@Slf4j
@RestController
@Api("培训经历")
@RequestMapping(value = "/trainingInfo")
public class EnrollmentTrainingInfoController {

    @Resource
    private EnrollmentTrainingInfoService service;


    /**
     * 保存培训经历
     * @return
     */
    @ApiLog(value = "保存培训经历", type = LogTypeEnum.SAVE)
    @PostMapping("save")
    public ResponseEntity save(@Valid @RequestBody EnrollmentTrainingInfo info) throws Exception {
        service.saveOrUpdateInfo(info);
        return ResponseEntity.ok ("操作成功");
    }

    /**
     * 删除培训经历
     * @return
     */
    @ApiLog(value = "删除培训经历", type = LogTypeEnum.SAVE)
    @PostMapping("delete")
    public ResponseEntity<String> delete(@Valid @RequestBody EnrollmentTrainingInfo info) throws Exception {
        service.removeById(info.getId());
        return ResponseEntity.ok ("操作成功");
    }

    /**
     * 培训经历列表
     * @return
     */
    @ApiLog(value = "教育培训经历", type = LogTypeEnum.SAVE)
    @GetMapping("list")
    public ResponseEntity<List<EnrollmentTrainingInfo>> findList(EnrollmentTrainingInfo info) throws Exception {
        List<EnrollmentTrainingInfo> list = service.findByUserId(info.getUserId(),"5");
        return ResponseEntity.ok (list);
    }

    /**
     * 根据id查询培训经历信息
     * @return
     */
    @ApiLog(value = "根据id查询培训经历信息", type = LogTypeEnum.SAVE)
    @GetMapping("findById")
    public ResponseEntity<EnrollmentTrainingInfo> findById(EnrollmentTrainingInfo info) throws Exception {
        EnrollmentTrainingInfo res = service.findById(info.getId());
        return ResponseEntity.ok (res);
    }

    /**
     * 培训经历用户端列表
     * @return
     */
    @ApiLog(value = "培训经历用户端列表", type = LogTypeEnum.SAVE)
    @GetMapping("findAuditList")
    public ResponseEntity<List<EnrollmentTrainingInfo>> findAuditList(EnrollmentTrainingInfo info) throws Exception {
        List<EnrollmentTrainingInfo> list = service.findByUserId(info.getUserId(),"1");
        return ResponseEntity.ok (list);
    }
}
