package com.ym.mec.web.controller;

import com.ym.mec.biz.dal.dto.StudentVisitDto;
import com.ym.mec.biz.dal.entity.StudentVisit;
import com.ym.mec.biz.dal.page.StudentVisitQueryInfo;
import com.ym.mec.biz.service.OrganizationService;
import com.ym.mec.biz.service.StudentVisitService;
import com.ym.mec.biz.service.SysUserService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import com.ym.mec.common.page.PageInfo;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "回访服务")
@RequestMapping("visit")
@RestController
public class VisitController extends BaseController {

    @Autowired
    private StudentVisitService studentVisitService;
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private OrganizationService organizationService;

    @ApiOperation(value = "回访列表")
    @GetMapping("/queryPage")
    @PreAuthorize("@pcs.hasPermissions('visit/queryPage')")
    public HttpResponseResult<PageInfo<StudentVisitDto>> queryPage(StudentVisitQueryInfo queryInfo) {
        queryInfo.setOrganId(organizationService.getEmployeeOrgan(queryInfo.getOrganId()));
        return succeed(studentVisitService.getPageList(queryInfo));
    }

    @ApiOperation(value = "添加回访")
    @PostMapping(value = "/add")
    @PreAuthorize("@pcs.hasPermissions('visit/add')")
    public HttpResponseResult<StudentVisit> add(@RequestBody @Validated StudentVisit studentVisit) {
        studentVisit.setTeacherId(sysUserService.getUserId());
        studentVisit.setVisiterType(StudentVisit.VisiterTypeEnum.EDU_TEACHER);
        return succeed(studentVisitService.addVisit(studentVisit));
    }


    @ApiOperation(value = "回访详情")
    @GetMapping(value = "/getInfo")
    @PreAuthorize("@pcs.hasPermissions('visit/getInfo')")
    public HttpResponseResult<StudentVisitDto> getInfo(Integer id) {
        return succeed(studentVisitService.getInfo(id));
    }
}
