package com.hzya.frame.sysnew.integtationTaskLiving.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzya.frame.sysnew.integtationTask.IIntegrationTaskCacheableService;
import com.hzya.frame.sysnew.integtationTask.entity.IntegrationTaskEntity;
import com.hzya.frame.sysnew.integtationTaskLiving.entity.IntegrationTaskLivingEntity;
import com.hzya.frame.sysnew.integtationTaskLiving.dao.IIntegrationTaskLivingDao;
import com.hzya.frame.sysnew.integtationTaskLiving.service.IIntegrationTaskLivingService;
import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import com.hzya.frame.basedao.service.impl.BaseService;

import java.util.List;

/**
 * 集成任务-实例(IntegrationTaskLiving)表服务实现类
 *
 * @author makejava
 * @since 2024-05-06 15:37:09
 */
@Service(value = "integrationTaskLivingService")
public class IntegrationTaskLivingServiceImpl extends BaseService<IntegrationTaskLivingEntity, String> implements IIntegrationTaskLivingService {
     
    private IIntegrationTaskLivingDao integrationTaskLivingDao;

	@Resource
	private IIntegrationTaskCacheableService iIntegrationTaskCacheableService;
    @Autowired
	public void setIntegrationTaskLivingDao(IIntegrationTaskLivingDao dao) {
		this.integrationTaskLivingDao = dao;
		this.dao = dao;
	}

	/**
	 * @param jsonObject
	 * @return com.hzya.frame.web.entity.JsonResultEntity
	 * @Author lvleigang
	 * @Description 查询任务实例列表分页
	 * @Date 11:52 上午 2024/3/27
	 **/
	@Override
	public JsonResultEntity queryEntityPage(JSONObject jsonObject) {
		IntegrationTaskLivingEntity entity = getData("jsonStr", jsonObject, IntegrationTaskLivingEntity.class);
		//判断分页
		if (entity == null || entity.getPageNum() == null || entity.getPageSize() == null) {
			return BaseResult.getFailureMessageEntity("分页查询参数不存在");
		}
		PageHelper.startPage(entity.getPageNum(), entity.getPageSize());
		List<IntegrationTaskLivingEntity> list = integrationTaskLivingDao.queryByLike(entity);
		PageInfo pageInfo = new PageInfo(list);
		return BaseResult.getSuccessMessageEntity("查询数据成功", pageInfo);
	}

	/**
	 * @param jsonObject
	 * @return com.hzya.frame.web.entity.JsonResultEntity
	 * @Author lvleigang
	 * @Description 获取任务实例
	 * @Date 2:36 下午 2024/3/27
	 **/
	@Override
	public JsonResultEntity getEntity(JSONObject jsonObject) {
		IntegrationTaskLivingEntity entity = getData("jsonStr", jsonObject, IntegrationTaskLivingEntity.class);
		if (entity == null) {
			return BaseResult.getFailureMessageEntity("参数不允许为空");
		}
		if (entity.getId() == null || "".equals(entity.getId())) {
			return BaseResult.getFailureMessageEntity("系统错误");
		}
		entity = iIntegrationTaskCacheableService.getIntegrationTaskLivingEntity(entity.getId());
		if (entity == null) {
			return BaseResult.getFailureMessageEntity("获取任务实例失败");
		}
		return BaseResult.getSuccessMessageEntity("获取任务实例成功", entity);
	}
}
