package com.zhgd.xmgl.modules.basicdata.controller.government;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhgd.annotation.OperLog;
import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.xmgl.modules.basicdata.dto.WorkerInfoDto;
import com.zhgd.xmgl.modules.basicdata.entity.WorkerInfo;
import com.zhgd.xmgl.modules.basicdata.service.IWorkerInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * @Title: Controller
 * @Description: 人员
 * @author： pengj
 * @date： 2023-03-13
 * @version： V1.0
 */
@RestController
@RequestMapping("/gov/workerInfo")
@Slf4j
@Api(tags = "人员管理")
public class GovWorkerInfoController {
    @Autowired
    private IWorkerInfoService workerInfoService;

    /**
     * 分页列表查询
     *
     * @return
     */
    @OperLog(operModul = "人员管理", operType = "分页查询", operDesc = "分页列表查询人员信息")
    @ApiOperation(value = " 分页列表查询人员信息", notes = "分页列表查询人员信息", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "personType", value = "人员类别(1:管理;2:工人)", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "personName", value = "姓名", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "companySn", value = "单位SN", paramType = "query", dataType = "String")
    })
    @PostMapping(value = "/page")
    public Result<IPage<WorkerInfoDto>> queryPageList(Page page, @RequestBody WorkerInfo workerInfo) {
        QueryWrapper<WorkerInfo> wrapper = Wrappers.<WorkerInfo>query();
        if (workerInfo.getPersonType() != null) {
            wrapper.eq("w.person_type", workerInfo.getPersonType());
        }
        if (StringUtils.isNotBlank(workerInfo.getPersonName())) {
            wrapper.like("w.person_name", workerInfo.getPersonName());
        }
        if (StringUtils.isNotBlank(workerInfo.getCompanySn())) {
            wrapper.eq("w.company_sn", workerInfo.getCompanySn());
        }
        IPage<WorkerInfoDto> pageList = workerInfoService.getDetailPageList(page, wrapper);
        return Result.success(pageList);
    }


    @OperLog(operModul = "人员管理", operType = "分页查询", operDesc = "按人员类型统计数据")
    @ApiOperation(value = " 按人员类型统计数据", notes = "按人员类型统计数据", httpMethod = "GET")
    @GetMapping(value = "/getByType")
    public Result<Map<String, Object>> getByType() {
        return Result.success(workerInfoService.getByType());
    }

    /**
     * 考勤统计
     * @return
     */
    @OperLog(operModul = "人员管理", operType = "统计", operDesc = "考勤统计")
    @ApiOperation(value = "考勤统计", notes = "考勤统计", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "engineeringSn", value = "工程SN", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "personType", value = "角色类型", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "month", value = "月份", paramType = "query", required = true, dataType = "String")
    })
    @PostMapping(value = "/attendStat")
    public Result<Page<Map<String, Object>>> attendStat(Page page, @RequestBody Map<String, Object> map) {
        return Result.success(workerInfoService.attendanceStat(page, map));
    }
}
