package cn.timer.api.utils.router.business;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import cn.timer.api.bean.yggl.YgglMainEmp;
import cn.timer.api.controller.yggl.service.YgglService;
import cn.timer.api.dto.spmk.FromData;
import cn.timer.api.dto.yggl.YgzzDto;
import cn.timer.api.utils.DateFormatUtils;
import cn.timer.api.utils.DateUtil;
import lombok.Builder;

/**
 * 转正-业务
 * @author Tang
 *
 */
@Service
public class RegularizationBusiness extends SpmkAssoBusiness {

	@Autowired
	private YgglService ygglService;
	
	@Value("${config-8timer.environmental-science}")
	public String environmental_science;
	
	public void Logoutput(String science) {
		
		if(!("pro").equals(environmental_science)) {
			
			System.out.println(science);
		}else {
			System.out.println("");
		}
		
	}
	
	@Override
	public void handleApprove(JSONObject jsonObj) throws Exception {
		// TODO Auto-generated method stub
		// 发起人企业id
//		String orgCode = jsonObj.get("orgCode",FromData.class).getValue();
		
		// 申请人名称
		String applicant = ObjectUtil.isNull(jsonObj.get("__applicant",FromData.class)) ? null : jsonObj.get("__applicant",FromData.class).getValue();
		
		// 试用期内主要工作和成绩
//		String WorkAndAchievement = jsonObj.get("WorkAndAchievement",FromData.class).getValue();
		// 存在问题及改进意见
//		String problem = jsonObj.get("problem",FromData.class).getValue();
		// 上传文件
//		String file = jsonObj.get("file",FromData.class).getValue();
		
		
		
		// 发起人id
		Integer id = jsonObj.getInt("id");
		// 企业id
		Integer orgCode = ObjectUtil.isNull(jsonObj.get("orgCode")) ? null : Convert.toInt(jsonObj.get("orgCode"));
		// 计划转正时间
		String confirmationTime = ObjectUtil.isNull(jsonObj.get("confirmationTime",FromData.class)) ? null : jsonObj.get("confirmationTime",FromData.class).getValue();
		// 实际转正时间
		String newConfirmationTime = ObjectUtil.isNull(jsonObj.get("__newConfirmationTime",FromData.class)) ? null : jsonObj.get("__newConfirmationTime",FromData.class).getValue();
		// 备注
		String Remarks = ObjectUtil.isNull(jsonObj.get("Remarks",FromData.class)) ? null : jsonObj.get("Remarks",FromData.class).getValue();
		
		YgzzDto ygzzDto = YgzzDto.builder()
				.empNum(id)
				.orgCode(orgCode)
				.zzTime(DateUtil.getFormatDate(confirmationTime))
				.sjzzTime(DateUtil.getFormatDate(newConfirmationTime))
				.zzRemark(Remarks)
				.build();
		Logoutput("转正:"+ygzzDto);
		// 调 员工管理 业务
//		YgglMainEmp.builder()
//		.jobStatus(2)
//		.zzTime(ygzzDto.getZzTime())
//		.sjzzTime(new Date())
//		.zzRemark(ygzzDto.getZzRemark())
//		.build().update(new UpdateWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getEmpNum, ygzzDto.getEmpNum()));
		ygglService.applicationRegularization(ygzzDto);
	}

}