package com.cyl.h5.controller.staff;

import com.cyl.h5.pojo.request.StaffListRequest;
import com.cyl.h5.pojo.request.StaffServiceRecordRequest;
import com.cyl.h5.pojo.vo.StaffServiceRecordVO;
import com.cyl.manager.staff.domain.vo.StaffVO;
import com.cyl.manager.staff.domain.Staff;
import com.cyl.manager.staff.service.IStaffService;
import com.cyl.manager.staff.service.IStaffServiceRecordService;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.config.LocalDataUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

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

/**
 * 人员信息Controller
 *
 * @author daixiande
 * @date 2023-12-25
 */
//@Api("服务人员信息")
@RestController
@RequestMapping("/h5/staff")
public class H5StaffController extends BaseController {
    @Autowired
    private IStaffService staffService;
    @Autowired
    private IStaffServiceRecordService staffServiceRecordService;

    /**
     * 查询人员信息列表
     */
//    @ApiOperation("查询人员信息列表")
    @GetMapping("/list")
    public TableDataInfo listForGet(StaffListRequest request) {
        startPage();
        List<StaffVO> list = staffService.selectStaffListForFont(request);
        return getDataTable(list);
    }

    /**
     * 查询人员信息列表
     */
//    @ApiOperation("查询人员信息列表")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody StaffListRequest request) {
        startPage();
        List<StaffVO> list = staffService.selectStaffListByCondition(request);
        return getDataTable(list);
    }

    /**
     * 获取人员信息详细信息
     */
//    @ApiOperation("获取人员信息详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.successData(staffService.selectStaffByIdForFront(id));
    }

    /**
     * 服务记录新增和修改接口
     */
//    @ApiOperation("服务记录 新增 和 修改")
    @PostMapping(value = "/saveOrUpdateServiceRecord")
    public ResponseEntity<Boolean> saveOrUpdateServiceRecord(@RequestBody @Valid StaffServiceRecordRequest request) {
        Staff staff = (Staff) LocalDataUtil.getVar(Constants.STAFF_INFO);
        Long staffId = staff.getId();
        request.setStaffId(staffId);
        return ResponseEntity.ok(staffServiceRecordService.saveOrUpdateServiceRecord(request));
    }

    /**
     * 获取当前员工服务记录接口
     */
//    @ApiOperation("获取某员工服务记录接口")
    @GetMapping(value = "/getServiceRecords/{staffId}")
    public ResponseEntity<List<StaffServiceRecordVO>> getServiceRecords(@PathVariable("staffId") Long staffId) {
        List<StaffServiceRecordVO> serviceRecords = staffServiceRecordService.getServiceRecords(staffId);
        return ResponseEntity.ok(serviceRecords);
    }


}
