/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 大恒泰山系统
 * 创建日期:2022/8/23
 */
package org.springblade.modules.business.equipment.inspection.plan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.business.equipment.inspection.plan.entity.EquipmentInspectionPlanEntity;
import org.springblade.modules.business.equipment.inspection.plan.mapper.EquipmentInspectionPlanMapper;
import org.springblade.modules.business.equipment.inspection.plan.service.IEquipmentInspectionPlanService;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/***
 * Date:2022/8/23
 * Title:文件所属模块（必须填写）
 * Description：对本文件的详细描述，原则上不能少于30字
 * @author dylan
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
@Service
public class EquipmentInspectionPlanServiceImpl extends BaseServiceImpl<EquipmentInspectionPlanMapper, EquipmentInspectionPlanEntity> implements IEquipmentInspectionPlanService {


	@Override
	public EquipmentInspectionPlanEntity yearPlan() {
		LambdaQueryWrapper<EquipmentInspectionPlanEntity> wrapper = Wrappers.<EquipmentInspectionPlanEntity>query().lambda();
		wrapper.eq(EquipmentInspectionPlanEntity::getIsDeleted,0);
		wrapper.orderByDesc(EquipmentInspectionPlanEntity::getCreateTime);
		wrapper.last("limit 1");
		return baseMapper.selectOne(wrapper);
	}

	@Override
	public EquipmentInspectionPlanEntity getPlanInfo() {
		LambdaQueryWrapper<EquipmentInspectionPlanEntity> wrapper = Wrappers.<EquipmentInspectionPlanEntity>query().lambda();
		wrapper.eq(EquipmentInspectionPlanEntity::getIsDeleted,0);
		wrapper.orderByDesc(EquipmentInspectionPlanEntity::getCreateTime);
		List<EquipmentInspectionPlanEntity> list = this.list(wrapper);
		if (null != list && list.size()>0){
			return list.get(0);
		}else {
			EquipmentInspectionPlanEntity entity=new EquipmentInspectionPlanEntity();
			Calendar calendar= Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.set(Calendar.MONTH,4-1);
			calendar.set(Calendar.DAY_OF_MONTH,1);
			entity.setBeforeRainSeasonStartTime(calendar.getTime());
			calendar.set(Calendar.MONTH,6-1);
			calendar.set(Calendar.DAY_OF_MONTH,1);
			entity.setBeforeRainSeasonEndTime(calendar.getTime());
			calendar.set(Calendar.MONTH,6-1);
			calendar.set(Calendar.DAY_OF_MONTH,1);
			entity.setRainSeasonFirstStartTime(calendar.getTime());
			calendar.set(Calendar.MONTH,8-1);
			calendar.set(Calendar.DAY_OF_MONTH,15);
			entity.setRainSeasonFirstEndTime(calendar.getTime());
			calendar.set(Calendar.MONTH,8-1);
			calendar.set(Calendar.DAY_OF_MONTH,15);
			entity.setRainSeasonSecondStartTime(calendar.getTime());
			calendar.set(Calendar.MONTH,10-1);
			calendar.set(Calendar.DAY_OF_MONTH,1);
			entity.setRainSeasonSecondEndTime(calendar.getTime());
			return entity;
		}
	}
}
