package com.yanzhu.jh.bigscreen.web.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.yanzhu.jh.project.domain.SurProjectDeptWroks;
import com.yanzhu.jh.project.domain.SurProjectWorkAttendance;
import com.yanzhu.jh.project.service.ISurProjectDeptWroksService;
import com.yanzhu.jh.project.service.ISurProjectWorkAttendanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 在岗出勤Conller
 */
@RestController
@RequestMapping("/bgscreen/attendance")
public class ProjectAttendanceController extends BaseController {

    @Autowired
    ISurProjectWorkAttendanceService surProjectWorkAttendanceService;

    @Autowired
    ISurProjectDeptWroksService surProjectDeptWroksService;

    /**
     * 查询在岗人数
     * @param deptId
     * @param projectId
     * @return
     */
    @GetMapping("/getDeptWorksList")
    public TableDataInfo getDeptWorksList(String deptId,String projectId){
        SurProjectDeptWroks surProjectDeptWroks = new SurProjectDeptWroks();
        if(deptId!=null && !"0".equals(deptId)){
            surProjectDeptWroks.setDeptId(Convert.toLong(deptId));
        }
        if(projectId!=null && !"0".equals(projectId)){
            surProjectDeptWroks.setProjectId(Convert.toLong(projectId));
        }
        return getDataTable(surProjectDeptWroksService.selectBgscreenDeptWroksList(surProjectDeptWroks));
    }

    /**
     * 查询出勤列表
     * @param deptId
     * @param projectId
     * @param date
     * @return
     */
    @GetMapping("/getWorkAttendanceList")
    public TableDataInfo getWorkAttendanceList(String deptId,String projectId,String date){
        SurProjectWorkAttendance surProjectWorkAttendance = new SurProjectWorkAttendance();
        if(deptId!=null && !"0".equals(deptId)){
            surProjectWorkAttendance.setDeptId(Convert.toLong(deptId));
        }
        if(projectId!=null && !"0".equals(projectId)){
            surProjectWorkAttendance.setProjectId(Convert.toLong(projectId));
        }
        if(StringUtils.isNotBlank(date)){
            surProjectWorkAttendance.setWorkDate(DateUtils.parseDate(date));
        }else{
            surProjectWorkAttendance.setWorkDate(new Date());
        }
        return getDataTable(surProjectWorkAttendanceService.selectBgscreenWorkAttendanceList(surProjectWorkAttendance));
    }
}
