/*
 *    Copyright (c) 2018-2025, hnqz All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: hnqz
 */
package com.qunzhixinxi.hnqz.daemon.quartz.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qunzhixinxi.hnqz.daemon.quartz.entity.WmTaskType;
import com.qunzhixinxi.hnqz.daemon.quartz.mapper.WmTaskTypeMapper;
import com.qunzhixinxi.hnqz.daemon.quartz.service.WmTaskTypeService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 任务类型打分表
 *
 * @author gaoyang
 * @date 2020-07-01 20:20:05
 */
@Service
public class WmTaskTypeServiceImpl extends ServiceImpl<WmTaskTypeMapper, WmTaskType> implements WmTaskTypeService {

	@Override
	public int getWmTaskTypeByEnt(WmTaskType wmTaskType) {
		wmTaskType.setDelFlag("0");
		wmTaskType.setEnableFlag("0");
		List<WmTaskType> list= super.list(Wrappers.query(wmTaskType));
		if(list.size()>0)
		{
			if(list.size()>0)
			{
				return list.get(0).getScore();
			}
		}else{
			return 0;
		}
		return 0;
	}

	@Override
	public int changeTaskTypeInfo() {
		WmTaskType wmTaskType=new WmTaskType();
		wmTaskType.setTaskTypeLevel("1");
		wmTaskType.setStatus("1");
		List<WmTaskType> wmTaskTypes=super.list(Wrappers.query(wmTaskType));

		for (WmTaskType wmT:wmTaskTypes) {
			WmTaskType wmTaskTypeBase=super.getById(wmT.getBaseId());
			WmTaskType wmTaskType1=new WmTaskType();
			wmTaskType1.setTaskTypeName(wmT.getTaskTypeName());
			wmTaskType1.setTaskTypeLevel("2");
			List<WmTaskType> wmTaskTypeList=super.list(Wrappers.query(wmTaskType1));

			for (WmTaskType wmTaskType2:wmTaskTypeList) {
				if(wmTaskType2.getScore()<wmT.getTaskScoreEnd()||wmTaskType2.getScore()>wmT.getTaskScoreStart())
				{
					wmTaskType2.setScore(wmT.getScore());
					wmTaskType2.setTaskScoreStart(wmT.getTaskScoreStart());
					wmTaskType2.setTaskScoreEnd(wmT.getTaskScoreEnd());
					this.updateById(wmTaskType2);
				}else{
					wmTaskType2.setTaskScoreStart(wmT.getTaskScoreStart());
					wmTaskType2.setTaskScoreEnd(wmT.getTaskScoreEnd());
					this.updateById(wmTaskType2);
				}
			}

			wmTaskTypeBase.setScore(wmT.getScore());
			wmTaskTypeBase.setTaskScoreEnd(wmT.getTaskScoreEnd());
			wmTaskTypeBase.setTaskScoreStart(wmT.getTaskScoreStart());
			this.updateById(wmTaskTypeBase);
		}


		this.remove(Wrappers.query(wmTaskType));





		return 0;
	}
}
