package com.ssm.controller;

import com.github.pagehelper.PageInfo;
import com.ssm.core.bean.GenericResponse;
import com.ssm.core.bean.PageResponse;
import com.ssm.core.utils.BigDecimalUtils;
import com.ssm.manage.entity.BaseProject;
import com.ssm.manage.entity.SmsException;
import com.ssm.manage.entity.StaffAttendanceRecord;
import com.ssm.manage.query.ProjectRequest;
import com.ssm.manage.query.StaffAttendanceRecordRequest;
import com.ssm.manage.response.ResponseCode;
import com.ssm.manage.service.SsmStaffAttendanceRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(value = "员工出勤记录controller", tags = {"员工出勤记录"})
@RestController
@RequestMapping("/demay/ssm/attendance")
@Slf4j
public class SsmStaffAttendanceRecordController {
    @Autowired
    private SsmStaffAttendanceRecordService ssmStaffAttendanceRecordService;

    @ApiOperation(value = "分页查询员工出勤记录 美发小程序-查询员工出勤记录", httpMethod = "POST", response = PageResponse.class)
    @RequestMapping("/record")
    public GenericResponse record(@RequestBody StaffAttendanceRecordRequest staffAttendanceRecordRequest) {
        GenericResponse genericResponse = new GenericResponse<>();
        List<StaffAttendanceRecord> list = new ArrayList<>();
        try {
            list = ssmStaffAttendanceRecordService.selectPage(staffAttendanceRecordRequest);
        } catch (Exception e) {
            log.error("SsmStaffAttendanceRecordController.page", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setRows(list);
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }

    @ApiOperation(value = "出勤记录添加  美发小程序-员工出勤记录添加", httpMethod = "POST", response = GenericResponse.class)
    @RequestMapping("/add")
    public GenericResponse add(@RequestBody StaffAttendanceRecordRequest staffAttendanceRecordRequest) {
        GenericResponse<StaffAttendanceRecord> genericResponse = new GenericResponse<>();
        int i = 0;
        try {
            i = ssmStaffAttendanceRecordService.addRecord(staffAttendanceRecordRequest);
        } catch (Exception e) {
            log.error("SsmStaffAttendanceRecordController.add", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }

//    @ApiOperation(value = "员工工时查询  美发小程序-员工工时查询", httpMethod = "POST", response = GenericResponse.class)
//    @RequestMapping("/staffWorkTime")
//    public GenericResponse staffWorkTime(@RequestBody StaffAttendanceRecordRequest staffAttendanceRecordRequest) {
//        GenericResponse genericResponse = new GenericResponse<>();
//        BigDecimal workTime = BigDecimalUtils.bigDecimal("0");
//        try {
//            workTime = ssmStaffAttendanceRecordService.staffWorkTime(staffAttendanceRecordRequest);
//        } catch (Exception e) {
//            log.error("SsmStaffAttendanceRecordController.staffWorkTime", e);
//            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
//            return genericResponse;
//        }
//
//        genericResponse.setCodeAndMsg(ResponseCode.OK);
//        genericResponse.setData(workTime);
//        return genericResponse;
//    }
}
