package com.persagy.calendar.pojo.dto;

import java.util.Date;
import java.util.Set;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.persagy.common.utils.StringUtil;

import cn.hutool.core.collection.CollectionUtil;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * @version 
 * @description 
 * @company persagy
 * @author zhangqiankun
 * @since 2021年3月2日:	下午4:57:22
 */
@Getter
@Setter
@ToString
@EqualsAndHashCode(callSuper = false)
@TableName("work_calendar_object")
public class WorkCalendarObject extends Model<WorkCalendarObject> {
	private static final long serialVersionUID = -3559409863078752929L;
	
	@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
	private String groupCode; // 集团编码
	
	@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
	private String calendarId; // 工作历ID

	@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
	private String projectId; // 工作历分类ID

	@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
	private String objectId; 	// 对象ID
	
	@TableField(exist = false)
	private String objectName; 	// 对象名称

	@TableField(fill = FieldFill.INSERT, updateStrategy = FieldStrategy.NOT_EMPTY)
	private String createTime; // 创建时间

	@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
	private String updateUser; // 最后操作者ID

	public static class Builder {

		private QueryWrapper<WorkCalendarObject> queryWrapper = null;

		private UpdateWrapper<WorkCalendarObject> updateWrapper = null;

		public Builder createQueryWrapper() {
			queryWrapper = new QueryWrapper<WorkCalendarObject>();
			return this;
		}

		public Builder createUpdateWrapper() {
			updateWrapper = new UpdateWrapper<WorkCalendarObject>();
			return this;
		}

		public Builder groupCodeEq(String groupCode) {
			if (StringUtil.isNotBlank(groupCode)) {
				if (updateWrapper != null) {
					updateWrapper.eq("GROUP_CODE", groupCode);
				} else {
					queryWrapper.eq("GROUP_CODE", groupCode);
				}
			}
			return this;
		}
		
		public Builder calendarIdEq(String calendarId) {
			if (StringUtil.isNotBlank(calendarId)) {
				if (updateWrapper != null) {
					updateWrapper.eq("CALENDAR_ID", calendarId);
				} else {
					queryWrapper.eq("CALENDAR_ID", calendarId);
				}
			}
			return this;
		}
		
		public Builder objectIdEq(String objectId) {
			if (StringUtil.isNotBlank(objectId)) {
				if (updateWrapper != null) {
					updateWrapper.eq("OBJECT_ID", objectId);
				} else {
					queryWrapper.eq("OBJECT_ID", objectId);
				}
			}
			return this;
		}
		
		public Builder objectIdIn(Set<String> objectIds) {
			if (CollectionUtil.isNotEmpty(objectIds)) {
				if (updateWrapper != null) {
					updateWrapper.in("OBJECT_ID", objectIds);
				} else {
					queryWrapper.in("OBJECT_ID", objectIds);
				}
			}
			return this;
		}

		public Builder projectIdEq(String projectId) {
			if (StringUtil.isNotBlank(projectId)) {
				if (updateWrapper != null) {
					updateWrapper.eq("PROJECT_ID", projectId);
				} else {
					queryWrapper.eq("PROJECT_ID", projectId);
				}
			}
			return this;
		}

		public Builder createTimeEq(Date createTime) {
			if (null != createTime) {
				if (updateWrapper != null) {
					updateWrapper.eq("CREATE_TIME", createTime);
				} else {
					queryWrapper.eq("CREATE_TIME", createTime);
				}
			}
			return this;
		}

		public Builder updateUserEq(String updateUser) {
			if (StringUtil.isNotBlank(updateUser)) {
				if (updateWrapper != null) {
					updateWrapper.eq("UPDATE_USER", updateUser);
				} else {
					queryWrapper.eq("UPDATE_USER", updateUser);
				}
			}
			return this;
		}

		public QueryWrapper<WorkCalendarObject> builderQueryWrapper() {
			return queryWrapper;
		}

		public UpdateWrapper<WorkCalendarObject> builderUpdateWrapper() {
			return updateWrapper;
		}
	}
}
