package com.ym.mec.web.controller;

import com.ym.mec.biz.dal.entity.TeacherDefaultPracticeGroupSalary;
import com.ym.mec.biz.service.TeacherDefaultPracticeGroupSalaryService;
import com.ym.mec.common.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Api(tags = "老师默认陪练课薪酬")
@RequestMapping("teacherDefaultPracticeGroupSalary")
@RestController
public class TeacherDefaultPracticeGroupSalaryController extends BaseController {

	@Autowired
	private TeacherDefaultPracticeGroupSalaryService teacherDefaultPracticeGroupSalaryService;

	@ApiOperation(value = "获取教师的陪练课课酬列表")
	@GetMapping("/queryPageByTeacherId")
	@PreAuthorize("@pcs.hasPermissions('teacherDefaultPracticeGroupSalary/queryPageByTeacherId')")
	public Object queryByTeacherId(Integer teacherId) {
		return succeed(teacherDefaultPracticeGroupSalaryService.queryByUserId(teacherId));
	}

	@ApiOperation(value = "批量新增、修改教师陪练课课酬")
	@PostMapping("/update")
	@PreAuthorize("@pcs.hasPermissions('teacherDefaultPracticeGroupSalary/update')")
	public Object update(@RequestBody TeacherDefaultPracticeGroupSalaryTemp teacherDefaultPracticeGroupSalaryTemp) {
		return teacherDefaultPracticeGroupSalaryService.update(teacherDefaultPracticeGroupSalaryTemp.getTeacherDefaultPracticeGroupSalaries(),
				teacherDefaultPracticeGroupSalaryTemp.getStartDate()) ? succeed() : failed();
	}

	static class TeacherDefaultPracticeGroupSalaryTemp {

		private List<TeacherDefaultPracticeGroupSalary> teacherDefaultPracticeGroupSalaries;

		private Date startDate;

		public List<TeacherDefaultPracticeGroupSalary> getTeacherDefaultPracticeGroupSalaries() {
			return teacherDefaultPracticeGroupSalaries;
		}

		public void setTeacherDefaultPracticeGroupSalaries(List<TeacherDefaultPracticeGroupSalary> teacherDefaultPracticeGroupSalaries) {
			this.teacherDefaultPracticeGroupSalaries = teacherDefaultPracticeGroupSalaries;
		}

		public Date getStartDate() {
			return startDate;
		}

		public void setStartDate(Date startDate) {
			this.startDate = startDate;
		}
	}
}
