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

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zhgd.annotation.OperLog;
import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.xmgl.modules.basicdata.entity.WorkerAttendance;
import com.zhgd.xmgl.modules.basicdata.entity.WorkerInfo;
import com.zhgd.xmgl.modules.basicdata.service.IWorkerAttendanceService;
import com.zhgd.xmgl.modules.basicdata.service.IWorkerInfoService;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


 /**
 * @Title: Controller
 * @Description: 人员考勤
 * @author： pengj
 * @date：   2023-03-14
 * @version： V1.0
 */
@RestController
@RequestMapping("/project/workerAttendance")
@Slf4j
@Api(tags = "人员考勤管理")
public class WorkerAttendanceController {
	@Autowired
	private IWorkerAttendanceService workerAttendanceService;

    @Autowired
    private IWorkerInfoService workerInfoService;

	/**
	  *   添加
	 * @param workerAttendance
	 * @return
	 */
	@OperLog(operModul = "人员考勤管理", operType = "新增", operDesc = "添加人员考勤信息")
	@ApiOperation(value = " 添加人员考勤信息", notes = "添加人员考勤信息" , httpMethod="POST")
	@PostMapping(value = "/add")
	public Result<WorkerAttendance> add(@RequestBody WorkerAttendance workerAttendance) {
		Result<WorkerAttendance> result = new Result<WorkerAttendance>();
        WorkerInfo workerInfo = workerInfoService.getOne(Wrappers.<WorkerInfo>lambdaQuery().eq(WorkerInfo::getId, workerAttendance.getId()));
        if(workerInfo == null) {
            result.error500("未找到对应人员信息");
        } else {
            workerAttendance.setEngineeringSn(workerInfo.getEngineeringSn());
            workerAttendance.setProjectSn(workerInfo.getProjectSn());
            workerAttendanceService.save(workerAttendance);
            result.ok("操作成功");
        }
        return result;
	}
}
