/*
 *    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.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qunzhixinxi.hnqz.daemon.quartz.config.QuartzAppConfig;
import com.qunzhixinxi.hnqz.daemon.quartz.entity.WmTask;
import com.qunzhixinxi.hnqz.daemon.quartz.mapper.WmTaskMapper;
import com.qunzhixinxi.hnqz.daemon.quartz.service.WmTaskService;
import com.qunzhixinxi.hnqz.daemon.quartz.service.WmWkArticleService;
import com.qunzhixinxi.hnqz.daemon.quartz.util.HttpPostUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

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

/**
 * 任务表
 *
 * @author pigx code generator
 * @date 2020-09-27 18:11:25
 */
@Service
@Slf4j
@AllArgsConstructor
public class WmTaskServiceImpl extends ServiceImpl<WmTaskMapper, WmTask> implements WmTaskService {

	private final QuartzAppConfig quartzAppConfig;

	private final List<Integer> taskTypeIdList = new ArrayList<>();

	{
		// 医院信息收集
		taskTypeIdList.add(15);
		// 商业公司信息收集
		taskTypeIdList.add(16);
		// 药店信息收集
		taskTypeIdList.add(18);
		// 医院信息修改
		taskTypeIdList.add(30);
	}

	@Override
	public boolean buildTaskImg(String param) {
//		 String API_URL="https://beijingapi.yaoyi.net";
		LambdaQueryWrapper<WmTask> wmTaskLambdaQueryWrapper = Wrappers.lambdaQuery();
		wmTaskLambdaQueryWrapper.isNull(WmTask::getTaskInfoImg);
		List<WmTask> wmTaskList = this.list(wmTaskLambdaQueryWrapper);
		if (wmTaskList.size() > 0) {
			for (WmTask wmTask : wmTaskList) {
				// 医院信息收集，商业公司信息收集，药店信息收集，医院信息修改，只导出审核通过的图片
				log.warn("当前任务：{}，类型是：{}，当前任务审核状态是：{}",wmTask.getId(),wmTask.getTaskTypeId(),wmTask.getPlatAuditStatus());
				if (taskTypeIdList.contains(Integer.parseInt(wmTask.getTaskTypeId())) && !"1".equals(wmTask.getPlatAuditStatus())) {
					log.warn("过滤的任务类型id：【{}】", taskTypeIdList.toString());
					continue;
				}
				try {
					String url = quartzAppConfig.getApiUrl() + "/admin/api/getH5To";
					System.out.println(url + "taskId=" + wmTask.getId());
					HttpPostUtil.sendGet(url, "taskId=" + wmTask.getId(), null);
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		}

		return true;
	}
}
