package com.zfire.jiasm.syncdata.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.zfire.jiasm.syncdata.dao.mapper.*;
import com.zfire.jiasm.syncdata.data.DetailDownloadData;
import com.zfire.jiasm.syncdata.parameter.OrderPar;
import com.zfire.jiasm.syncdata.plus.entity.*;
import com.zfire.jiasm.syncdata.plus.service.*;
import com.zfire.jiasm.syncdata.response.WebsitFWS;
import com.zfire.jiasm.syncdata.response.WebsitSH;
import com.zfire.jiasm.syncdata.response.WorderInfo;
import com.zfire.jiasm.syncdata.service.DetailDownloadService;
import com.zfire.jiasm.syncdata.service.PublicService;
import com.zfire.jiasm.syncdata.utils.MyBeanUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class DetailDownloadServiceImpl implements DetailDownloadService {
	@Autowired
	private JdbcTemplate jdbcTemplate;
	@Resource
	ItfTblAzAssignXzydDownloadService itfTblAzAssignXzydDownloadService;
	@Resource
	InstallXzydDownloadMapper installXzydDownloadMapper;
	@Resource
	InstallDownloadTaskListMapper installDownloadTaskListMapper;
	@Resource
	OrderInformationService orderInformationService;
	@Resource
	PublicService publicService;
	@Resource
	OrderBaseService orderBaseService;
	@Resource
	ItfTblYjhxJddDownloadService itfTblYjhxJddDownloadService;
	@Resource
	YjhxAppraiseService yjhxAppraiseService;
	@Resource
	ItfTblTradeNewForOldDownloadService itfTblTradeNewForOldDownloadService;
	@Resource
	OldForNewProductService oldForNewProductService;
	@Resource
	TradeNewForOldDownloadMapper tradeNewForOldDownloadMapper;
	@Resource
	YjhxJddDownloadMapper yjhxJddDownloadMapper;
	@Resource
	ItfTblAzWgmxJyktDownloadService itfTblAzWgmxJyktDownloadService;
	@Resource
	ItfTblAzWgmxSyktDownloadService itfTblAzWgmxSyktDownloadService;
	@Resource
	ItfTblAzWgmxQitaDownloadService itfTblAzWgmxQitaDownloadService;
	@Resource
	OrderInstallDetailService orderInstallDetailService;
	@Resource
	AzWgmxJyktDownloadMapper azWgmxJyktDownloadMapper;
	@Resource
	AzWgmxSyktDownloadMapper azWgmxSyktDownloadMapper;
	@Resource
	AzWgmxQitaDownloadMapper azWgmxQityaDownloadMapper;
	@Resource
	ItfGreeToFaDownloadTaskListService itfGreeToFaDownloadTaskListService;
	@Resource
	ItfTblAzWgmxJyktFjDownloadService itfTblAzWgmxJyktFjDownloadService;
	@Resource
	ItfTblAzWgmxSyktFjDownloadService itfTblAzWgmxSyktFjDownloadService;
	@Resource
	ItfTblAzWgmxQitaFjDownloadService itfTblAzWgmxQitaFjDownloadService;
	@Resource
	ItfTblAzWgmxSyktTmmxLsDownloadService itfTblAzWgmxSyktTmmxLsDownloadService;
	@Resource
	OrderDetailFileService orderDetailFileService;
	@Resource
	OrderInstallDetailCodeService orderInstallDetailCodeService;

	

	@Override
	public List<Map<String, Object>> getTaskTypeInstall() {
		List<Map<String, Object>> result = jdbcTemplate.queryForList("SELECT * from "
				+" itf_gree_to_fa_download_task_type  "
				+ " where download_task_type not in (92,31) "
				);
		return result;
	}

	@Override
	public List<Map<String, Object>> getTaskTypeRepair() {
		List<Map<String, Object>> result = jdbcTemplate.queryForList("SELECT * from "
				+" itf_gree_to_fa_download_task_type  "
				+ " where download_task_type in (92,31) "
				);
		return result;
	}
	
	@Override
	public List<Map<String, Object>> getTaskDataInstall(int downloadTaskType) {
		List<Map<String, Object>> result = jdbcTemplate.queryForList("SELECT a.*, "
				+ " c.download_task_type_name "
				+ " FROM itf_gree_to_fa_download_task_list a,itf_gree_to_fa_download_task_type c "
				+ " where a.download_task_type=c.download_task_type " 
				+ " and c.download_task_type not in (92,31) and c.download_task_type=? "
				+ " and a.download_status=0 and (download_times is null or download_times<=5) order by a.id limit 1000 ",new Object[] {downloadTaskType});
		return result;
	}
	
	@Override
	public List<Map<String, Object>> getTaskDataRepair(int downloadTaskType) {
		List<Map<String, Object>> result = jdbcTemplate.queryForList("SELECT a.*, "
				+ " c.download_task_type_name "
				+ " FROM itf_gree_to_fa_download_task_list a,itf_gree_to_fa_download_task_type c "
				+ " where a.download_task_type=c.download_task_type " 
				+ " and c.download_task_type in (92,31) and c.download_task_type=? "
				+ " and a.download_status=0 and (download_times is null or download_times<=5) order by a.id limit 1000 ",new Object[] {downloadTaskType});
		return result;
	}

	public void insertAData(String downloadTaskNo, String destTabName, String destTabColList,
			Object[] arySrcTabColValue) throws Exception {

		StringBuffer mark = new StringBuffer();
		for (int i = 0; i < arySrcTabColValue.length; i++) {
			if (mark.length() > 0) {
				mark.append(",");
			}
			mark.append("?");
		}

		String sql = "insert into " + destTabName + " (download_task_no," + destTabColList + ") values (?," + mark
				+ ") ";

		Object[] insertValue = new Object[arySrcTabColValue.length + 1];
		insertValue[0] = downloadTaskNo;
		System.arraycopy(arySrcTabColValue, 0, insertValue, 1, arySrcTabColValue.length);

		jdbcTemplate.update(sql, insertValue);

	}

	@Override
	public List<Map<String, Object>> getTaskTables(int downloadTaskType) {
		List<Map<String, Object>> result = jdbcTemplate.queryForList(
				"SELECT * from itf_gree_to_fa_download_task_rule where download_task_type=? ",
				new Object[] { downloadTaskType });
		return result;
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void insertData(String downloadTaskNo, List<DetailDownloadData> detailDownloadDatas,
						   int downloadTaskType, String pgguid,Map<String, List<SysDict>> sysDictRefDLMap)
			throws Exception {

		// 写入下载表
		for (DetailDownloadData detailDownloadData : detailDownloadDatas) {
			insertAData(downloadTaskNo, detailDownloadData.getDestTabName(), detailDownloadData.getDestTabColList(),
					detailDownloadData.getArySrcTabColValue());
		}

		// 写入本地表
		process(downloadTaskNo, downloadTaskType, pgguid, sysDictRefDLMap);
	}


	public void process(String downloadTaskNo, int downloadTaskType, String pgguid, Map<String, List<SysDict>> sysDictRefDLMap) {
		if (downloadTaskType == 2201){
			// 安装工单采集数据下载(家用空调)	TL_SynDataFrom_tbl_az_wgmx_jykt
			processOrderInstallDetailJ(downloadTaskNo, pgguid);
		} else if (downloadTaskType == 220101){
			// 安装工单采集附件表数据下载(家用空调)	TL_SynDataFrom_tbl_az_wgmx_jykt_child
			processJyktFj(downloadTaskNo, pgguid);
		} else if (downloadTaskType == 2202){
			// 安装工单采集数据下载(商用空调)	TL_SynDataFrom_tbl_az_wgmx_sykt
			processOrderInstallDetailS(downloadTaskNo, pgguid);
		} else if (downloadTaskType == 220201){
			//  安装工单采集附件表数据下载(商用空调) TL_SynDataFrom_tbl_az_wgmx_sykt_child
			processSyktFjAndTM(downloadTaskNo, pgguid);
		} else if (downloadTaskType == 2203){
			// 安装工单采集数据下载(其他)	TL_SynDataFrom_tbl_az_wgmx_qita
			processOrderInstallDetailO(downloadTaskNo, pgguid);
		} else if (downloadTaskType == 220301){
			// 安装工单采集附件表数据下载(其他) 	TL_SynDataFrom_tbl_az_wgmx_qita_child
			processOktFj(downloadTaskNo, pgguid);
		} else if (downloadTaskType == 2204){
			// 以旧换新鉴定单 itf_tbl_yjhx_jdd_download  TL_SynDataFrom_tbl_yjhx_jdd
			processYjhxJdd(downloadTaskNo, pgguid);
		} else if (downloadTaskType == 2205){
			// 以旧换新旧机信息 itf_tbl_trade_new_for_old_download  TL_SynDataFrom_tbl_trade_new_for_old
			processOldForNewProduct(downloadTaskNo, pgguid);
		} else if (downloadTaskType == 2206){
			// 安装工单子表数据阅读信息 itf_tbl_az_assign_xzyd_download  TL_SynDataFrom_tbl_az_assign_xzyd
			processInformatino(downloadTaskNo, pgguid, sysDictRefDLMap);
		}
	}

	public void processOldForNewProduct(String downloadTaskNo, String pgguid){
        // 提取数据
		List<ItfTblTradeNewForOldDownload> yjhxps = itfTblTradeNewForOldDownloadService.lambdaQuery()
				.eq(ItfTblTradeNewForOldDownload::getDownloadTaskNo, downloadTaskNo)
				.eq(ItfTblTradeNewForOldDownload::getSynStatus,0).list();
		if (!CollectionUtils.isEmpty(yjhxps)){
			// 提取工单数据
			OrderBase orderBase = orderBaseService.lambdaQuery()
					.eq(OrderBase::getPgguid,pgguid).one();
			for (ItfTblTradeNewForOldDownload item:yjhxps){
				if (orderBase !=null){
					YjhxAppraise up = new YjhxAppraise();
					up.setStat("3");
					QueryWrapper upWrapper = new QueryWrapper<YjhxAppraise>()
							.eq("order_base_id", orderBase.getId());
					yjhxAppraiseService.update(up,upWrapper);

					// 删除原下载的数据
					QueryWrapper delWrapper = new QueryWrapper<OldForNewProduct>()
							.eq("order_base_id", orderBase.getId());
					oldForNewProductService.remove(delWrapper);
				}
				OldForNewProduct add = new OldForNewProduct();
				MyBeanUtils.copyProperties(item,add);
				add.setCreateBy(item.getCreatedBy());
				add.setCreateTime(item.getCreatedDate());
				add.setUpdateBy(item.getLastModifiedBy());
				add.setUpdateTime(item.getLastModifiedDate());
				add.setMainId(String.valueOf(item.getSpid()));
				add.insert();
			}
		}

		// 修改同步状态
		upSynStatusProduct(downloadTaskNo);
	}


	public void processOrderInstallDetailJ(String downloadTaskNo, String pgguid) {
		List<OrderInstallDetail> oids = new ArrayList<>();
		List<ItfGreeToFaDownloadTaskList> its = new ArrayList<>();
		int count = 1;

		// 提取数据
		List<ItfTblAzWgmxJyktDownload> jykts = itfTblAzWgmxJyktDownloadService.lambdaQuery()
				.eq(ItfTblAzWgmxJyktDownload::getDownloadTaskNo, downloadTaskNo)
				.eq(ItfTblAzWgmxJyktDownload::getSynStatus,0).list();


		if (!CollectionUtils.isEmpty(jykts)){
			// 提取工单数据
			OrderBase order = orderBaseService.lambdaQuery()
					.eq(OrderBase::getPgguid,pgguid).one();

			for (ItfTblAzWgmxJyktDownload item :jykts){
				// 生成采集明细数据
				count = getOrderInstallDetail(oids, count, order, item);

				// 增加处理三级从表的下载任务
				getItfGreeToFaDownloadTaskList(its, item);
			}
			orderInstallDetailService.saveBatch(oids);
			oids.clear();
			itfGreeToFaDownloadTaskListService.saveBatch(its);
			its.clear();
		}

		// 修改同步状态
		upSynStatusAzJykt(downloadTaskNo);
	}

	public void processJyktFj(String downloadTaskNo, String pgguid) {
		List<OrderDetailFile> odfs = new ArrayList<>();
		List<OrderInstallDetail> oids = new ArrayList<>();
		Map<String,List<OrderInstallDetail>> oidsMap = new HashMap<>();
		List<String> fsFjguid = new ArrayList<>();

		// 提取附件数据
		List<ItfTblAzWgmxJyktFjDownload> jykts = itfTblAzWgmxJyktFjDownloadService.lambdaQuery()
				.eq(ItfTblAzWgmxJyktFjDownload::getDownloadTaskNo, downloadTaskNo)
				.eq(ItfTblAzWgmxJyktFjDownload::getSynStatus,0).list();

		// 提取采集数据
		oids = orderInstallDetailService.lambdaQuery()
				.select(OrderInstallDetail::getPgwcmxid,OrderInstallDetail::getId)
				.eq(OrderInstallDetail::getPgguid,pgguid).list();
		oidsMap = oids.stream().collect(Collectors.groupingBy(OrderInstallDetail::getPgwcmxid));

		if (!CollectionUtils.isEmpty(jykts)){
			// 提取工单数据
			OrderBase order = orderBaseService.lambdaQuery()
					.eq(OrderBase::getPgguid,pgguid).one();
			if (order!=null){
				// 提取现有的采集附件数据
				List<OrderDetailFile> fs = orderDetailFileService.lambdaQuery()
						.select(OrderDetailFile::getFjguid,OrderDetailFile::getFileType)
						.eq(OrderDetailFile::getOrderBaseId,order.getId()).list();
				if (CollectionUtils.isEmpty(fs)){
					fs.stream().forEach(event->{
						fsFjguid.add(event.getFjguid());
					});
				}

				for (ItfTblAzWgmxJyktFjDownload item :jykts){
					// 采集明细表未同步不处理
					if (!oidsMap.containsKey(item.getPgwcmxid())){
						odfs.clear();
						break;
					}
					// 生成采集附件明细数据 暂时忽略更新，无新增
					if (!fsFjguid.contains(item.getFjguid())){
						getItfTblAzWgmxJyktFj(odfs,oidsMap.get(item.getPgwcmxid()).get(0), order, item);
					}
				}
				if (odfs.size()>0) {
					orderDetailFileService.saveBatch(odfs);
					odfs.clear();
				}
			}
		}
		// 修改同步状态
		upSynStatusAzJyktFJ(downloadTaskNo);
	}

	public void processSyktFjAndTM(String downloadTaskNo, String pgguid) {
		// 附件
		processSyktFj(downloadTaskNo, pgguid);
		// 条码
		processSyktTM(downloadTaskNo, pgguid);
		// 修改同步状态
		upSynStatusAzFJTM(downloadTaskNo);
	}

	public void processSyktFj(String downloadTaskNo, String pgguid) {
		List<OrderDetailFile> odfs = new ArrayList<>();
		List<OrderInstallDetail> oids = new ArrayList<>();
		Map<String,List<OrderInstallDetail>> oidsMap = new HashMap<>();
		List<String> fsFjguid = new ArrayList<>();

		// 提取附件数据
		List<ItfTblAzWgmxSyktFjDownload> fjs = itfTblAzWgmxSyktFjDownloadService.lambdaQuery()
				.eq(ItfTblAzWgmxSyktFjDownload::getDownloadTaskNo, downloadTaskNo)
				.eq(ItfTblAzWgmxSyktFjDownload::getSynStatus,0).list();

		// 提取采集数据
		oids = orderInstallDetailService.lambdaQuery()
				.select(OrderInstallDetail::getPgwcmxid,OrderInstallDetail::getId)
				.eq(OrderInstallDetail::getPgguid,pgguid).list();
		oidsMap = oids.stream().collect(Collectors.groupingBy(OrderInstallDetail::getPgwcmxid));

		if (!CollectionUtils.isEmpty(fjs)){
			// 提取工单数据
			OrderBase order = orderBaseService.lambdaQuery()
					.eq(OrderBase::getPgguid,pgguid).one();
			if (order!=null){
				// 提取现有的采集附件数据
				List<OrderDetailFile> fs = orderDetailFileService.lambdaQuery()
						.select(OrderDetailFile::getFjguid,OrderDetailFile::getFileType)
						.eq(OrderDetailFile::getOrderBaseId,order.getId()).list();
				if (CollectionUtils.isEmpty(fs)){
					fs.stream().forEach(event->{
						fsFjguid.add(event.getFjguid());
					});
				}

				for (ItfTblAzWgmxSyktFjDownload item :fjs){
					// 采集明细表未同步不处理
					if (!oidsMap.containsKey(item.getPgwcmxid())){
						odfs.clear();
						break;
					}
					// 生成采集附件明细数据 暂时忽略更新，无新增
					if (!fsFjguid.contains(item.getFjguid())){
						getItfTblAzWgmxSyktFj(odfs,oidsMap.get(item.getPgwcmxid()).get(0), order, item);
					}
				}
				if (odfs.size()>0) {
					orderDetailFileService.saveBatch(odfs);
					odfs.clear();
				}

				// 修改同步状态
				upSynStatusAzSyktFJ(downloadTaskNo);
			}
		}
	}

	public void processSyktTM(String downloadTaskNo, String pgguid) {
		List<OrderInstallDetailCode> addCodes = new ArrayList<>();
		List<OrderInstallDetail> oids = new ArrayList<>();
		Map<String,List<OrderInstallDetail>> oidsMap = new HashMap<>();
		List<String> tmguidS = new ArrayList<>();

		// 提取条码数据
		List<ItfTblAzWgmxSyktTmmxLsDownload> tms = itfTblAzWgmxSyktTmmxLsDownloadService.lambdaQuery()
				.eq(ItfTblAzWgmxSyktTmmxLsDownload::getDownloadTaskNo, downloadTaskNo)
				.eq(ItfTblAzWgmxSyktTmmxLsDownload::getSynStatus,0).list();

		// 提取采集数据
		oids = orderInstallDetailService.lambdaQuery()
				.select(OrderInstallDetail::getPgwcmxid,OrderInstallDetail::getId)
				.eq(OrderInstallDetail::getPgguid,pgguid).list();
		oidsMap = oids.stream().collect(Collectors.groupingBy(OrderInstallDetail::getPgwcmxid));

		if (!CollectionUtils.isEmpty(tms)){
			// 提取工单数据
			OrderBase order = orderBaseService.lambdaQuery()
					.eq(OrderBase::getPgguid,pgguid).one();
			if (order!=null){
				// 提取现有的条码数据
				List<OrderInstallDetailCode> codes = orderInstallDetailCodeService.lambdaQuery()
						.select(OrderInstallDetailCode::getTmguid,OrderInstallDetailCode::getStatus)
						.eq(OrderInstallDetailCode::getOrderBaseId,order.getId()).list();
				if (CollectionUtils.isEmpty(codes)){
					codes.stream().forEach(event->{
						tmguidS.add(event.getTmguid());
					});
				}

				for (ItfTblAzWgmxSyktTmmxLsDownload item :tms){
					// 采集明细表未同步不处理
					if (!oidsMap.containsKey(item.getPgwcmxid())){
						addCodes.clear();
						break;
					}
					// 生成采集附件明细数据 暂时忽略更新，无新增
					if (!tmguidS.contains(item.getTmguid())){
						getItfTblAzWgmxSyktTM(addCodes,oidsMap.get(item.getPgwcmxid()).get(0), order, item);
					}
				}
				if (addCodes.size()>0) {
					orderInstallDetailCodeService.saveBatch(addCodes);
					addCodes.clear();
				}
				// 修改同步状态
				upSynStatusAzSyktTM(downloadTaskNo);
			}
		}
	}

	public void processOktFj(String downloadTaskNo, String pgguid) {
		List<OrderDetailFile> odfs = new ArrayList<>();
		List<OrderInstallDetail> oids = new ArrayList<>();
		Map<String,List<OrderInstallDetail>> oidsMap = new HashMap<>();
		List<String> fsFjguid = new ArrayList<>();

		// 提取附件数据
		List<ItfTblAzWgmxQitaFjDownload> kts = itfTblAzWgmxQitaFjDownloadService.lambdaQuery()
				.eq(ItfTblAzWgmxQitaFjDownload::getDownloadTaskNo, downloadTaskNo)
				.eq(ItfTblAzWgmxQitaFjDownload::getSynStatus,0).list();

		// 提取采集数据
		oids = orderInstallDetailService.lambdaQuery()
				.select(OrderInstallDetail::getPgwcmxid,OrderInstallDetail::getId)
				.eq(OrderInstallDetail::getPgguid,pgguid).list();
		oidsMap = oids.stream().collect(Collectors.groupingBy(OrderInstallDetail::getPgwcmxid));

		if (!CollectionUtils.isEmpty(kts)){
			// 提取工单数据
			OrderBase order = orderBaseService.lambdaQuery()
					.eq(OrderBase::getPgguid,pgguid).one();
			if (order!=null){
				// 提取现有的采集附件数据
				List<OrderDetailFile> fs = orderDetailFileService.lambdaQuery()
						.select(OrderDetailFile::getFjguid,OrderDetailFile::getFileType)
						.eq(OrderDetailFile::getOrderBaseId,order.getId()).list();
				if (CollectionUtils.isEmpty(fs)){
					fs.stream().forEach(event->{
						fsFjguid.add(event.getFjguid());
					});
				}

				for (ItfTblAzWgmxQitaFjDownload item :kts){
					// 采集明细表未同步不处理
					if (!oidsMap.containsKey(item.getPgwcmxid())){
						odfs.clear();
						break;
					}
					// 生成采集附件明细数据 暂时忽略更新，无新增
					if (!fsFjguid.contains(item.getFjguid())){
						getItfTblAzWgmxOFj(odfs,oidsMap.get(item.getPgwcmxid()).get(0), order, item);
					}
				}
				if (odfs.size()>0) {
					orderDetailFileService.saveBatch(odfs);
					odfs.clear();
				}
			}
		}
		// 修改同步状态
		upSynStatusAzOFJ(downloadTaskNo);
	}

	private void getItfGreeToFaDownloadTaskList(List<ItfGreeToFaDownloadTaskList> its, ItfTblAzWgmxJyktDownload item) {
		ItfGreeToFaDownloadTaskList tl = new ItfGreeToFaDownloadTaskList();
		tl.setDownloadTaskNo(IdWorker.getIdStr());
		tl.setDownloadKeyValue(item.getPgwcmxid());
		tl.setDownloadTaskType(220101);
		tl.setDownloadStatus(0);
		its.add(tl);
	}

	private void getItfGreeToFaDownloadTaskListS(List<ItfGreeToFaDownloadTaskList> its, ItfTblAzWgmxSyktDownload item) {
		ItfGreeToFaDownloadTaskList tl = new ItfGreeToFaDownloadTaskList();
		tl.setDownloadTaskNo(IdWorker.getIdStr());
		tl.setDownloadKeyValue(item.getPgwcmxid());
		tl.setDownloadTaskType(220201);
		tl.setDownloadStatus(0);
		its.add(tl);
	}

	private void getItfGreeToFaDownloadTaskListO(List<ItfGreeToFaDownloadTaskList> its, ItfTblAzWgmxQitaDownload item) {
		ItfGreeToFaDownloadTaskList tl = new ItfGreeToFaDownloadTaskList();
		tl.setDownloadTaskNo(IdWorker.getIdStr());
		tl.setDownloadKeyValue(item.getPgwcmxid());
		tl.setDownloadTaskType(220301);
		tl.setDownloadStatus(0);
		its.add(tl);
	}

	private int getOrderInstallDetail(List<OrderInstallDetail> oids, int count, OrderBase order, ItfTblAzWgmxJyktDownload item) {
		WebsitSH websitSH;
		OrderInstallDetail a = new OrderInstallDetail();
		OrderPar req = new OrderPar();
		req.setSynReqId(item.getSynReqId());
		a= azWgmxJyktDownloadMapper.getAzjyktInfo(req);
		a.setId(IdWorker.getIdStr());

		WorderInfo worderInfo = publicService.getWorkerInfo(order.getWorkerId(), item.getCzwd(), order.getGroupCompanyId());
		a.setWxgid(worderInfo.getBrandWorkerNumber());
		if (item.getWcsj() !=null){
			a.setFirstTime(item.getWcsj());
		} else {
			if (item.getCzsj()!=null){
				a.setFirstTime(item.getCzsj());
			}
		}
		if (item.getCreatedDate()!=null){
			a.setCreateTime(item.getCreatedDate());
		}
		if (item.getLastModifiedDate()!=null){
			a.setUpdateTime(item.getLastModifiedDate());
		}
		// 结算网点 settle_websit_id 名称
		websitSH =  publicService.ptshwdToshshwd(a.getSettleWebsitId(),a.getMainId());
		a.setSettleWebsitId(websitSH.getWdId());
		a.setSettleWebsitName(websitSH.getWdmc());
		// 序号从1开始自加
		a.setCodeIndex(count++);
		websitSH =  publicService.ptshwdToshshwd(a.getOperatorWebsitId(),a.getMainId());
		a.setOperatorWebsitId(websitSH.getWdId());
		a.setOperatorWebsitName(websitSH.getWdmc());
		oids.add(a);
		return count;
	}

	private void getItfTblAzWgmxJyktFj(List<OrderDetailFile> odfs,OrderInstallDetail oid,
									   OrderBase order, ItfTblAzWgmxJyktFjDownload item) {
		OrderDetailFile a = new OrderDetailFile();
		a.setId(IdWorker.getIdStr());
		a.setFjguid(item.getFjguid());
		a.setOrderBaseId(order.getId());
		a.setOrderDetailId(oid.getId());
		setType(item.getType(),item.getFjname(), a);
		// 附件地址
		// a.setFilePath();
		a.setFileRemark(item.getFjremark());
		// 品牌方的附件index
		a.setBrandFileIndex(String.valueOf(item.getFjindex()));
		a.setPgwcmxid(item.getPgwcmxid());
		// 服务器存储图片路径
		a.setBrandFilePath(item.getFjserverpath());
		a.setFileType(item.getType());
		a.setSortNum(item.getFjsequence());
		a.setCreateTime(item.getCreatedDate());
		a.setCreateBy(item.getCreatedBy());
		a.setUpdateTime(item.getLastModifiedDate());
		a.setUpdateBy(item.getLastModifiedBy());
		odfs.add(a);
	}

	private void getItfTblAzWgmxOFj(List<OrderDetailFile> odfs,OrderInstallDetail oid,
									   OrderBase order, ItfTblAzWgmxQitaFjDownload item) {
		OrderDetailFile a = new OrderDetailFile();
		a.setId(IdWorker.getIdStr());
		a.setFjguid(item.getFjguid());
		a.setOrderBaseId(order.getId());
		a.setOrderDetailId(oid.getId());
		setType(item.getType(),item.getFjname(), a);
		// 附件地址
		// a.setFilePath();
		a.setFileRemark(item.getFjremark());
		// 品牌方的附件index
		a.setBrandFileIndex(String.valueOf(item.getFjindex()));
		a.setPgwcmxid(item.getPgwcmxid());
		// 服务器存储图片路径
		a.setBrandFilePath(item.getFjserverpath());
		a.setFileType(item.getType());
		a.setSortNum(item.getFjsequence());
		a.setCreateTime(item.getCreatedDate());
		a.setCreateBy(item.getCreatedBy());
		a.setUpdateTime(item.getLastModifiedDate());
		a.setUpdateBy(item.getLastModifiedBy());
		odfs.add(a);
	}

	private void getItfTblAzWgmxSyktFj(List<OrderDetailFile> odfs,OrderInstallDetail oid,
									   OrderBase order, ItfTblAzWgmxSyktFjDownload item) {
		OrderDetailFile a = new OrderDetailFile();
		a.setId(IdWorker.getIdStr());
		a.setFjguid(item.getFjguid());
		a.setOrderBaseId(order.getId());
		a.setOrderDetailId(oid.getId());
		setType(item.getType(),item.getFjname(), a);
		// 附件地址
		// a.setFilePath();
		a.setFileRemark(item.getFjremark());
		// 品牌方的附件index
		a.setBrandFileIndex(String.valueOf(item.getFjindex()));
		a.setPgwcmxid(item.getPgwcmxid());
		// 服务器存储图片路径
		a.setBrandFilePath(item.getFjserverpath());
		a.setFileType(item.getType());
		a.setSortNum(item.getFjsequence());
		a.setCreateTime(item.getCreatedDate());
		a.setCreateBy(item.getCreatedBy());
		a.setUpdateTime(item.getLastModifiedDate());
		a.setUpdateBy(item.getLastModifiedBy());
		odfs.add(a);
	}

	private void setType(Integer type,String fjname,OrderDetailFile a) {
		if (StringUtils.isEmpty(fjname)){
			if (type == 0) {
				a.setFileName("内机条码");
			} else if (type == 1) {
				a.setFileName("外机条码");
			} else if (type == 2) {
				a.setFileName("商用信息采集（必填）");
			} else if (type == 3) {
				a.setFileName("商用信息采集（选填）");
			} else if (type == 4) {
				a.setFileName("内机其他图片");
			} else if (type == 5) {
				a.setFileName("外机图片");
			} else if (type == 7) {
				a.setFileName("上墙图");
			} else if (type == 8) {
				a.setFileName("特殊安装确认图");
			} else {
				a.setFileName("其他");
			}
		} else {
			a.setFileName(fjname);
		}
	}

	private void getItfTblAzWgmxSyktTM(List<OrderInstallDetailCode> odfs,OrderInstallDetail oid,
									   OrderBase order, ItfTblAzWgmxSyktTmmxLsDownload item) {
		OrderInstallDetailCode a = new OrderInstallDetailCode();
		a.setId(IdWorker.getIdStr());
		// 结算网点 settle_websit_id 名称
		WebsitSH websitSH =  publicService.ptshwdToshshwd(order.getWebsitId(),order.getMainId());
		// 网点编号
		a.setWebsitId(websitSH.getWdId());
		a.setOrderBaseId(order.getId());
		a.setOrderDetailId(oid.getId());
		a.setCode(item.getJqtm());
		a.setType("2");
		if (item.getTmlx()==2){
			a.setType("1");
		}
		a.setPassword(item.getKjmm());
		a.setPassword2(item.getKjmm2());
		a.setCreateTime(item.getCreatedDate());
		a.setUpdateTime(item.getLastModifiedDate());
		a.setPgguid(order.getPgguid());
		a.setGreeImageId(item.getScwj());
		a.setPgwcmxid(item.getPgwcmxid());
		a.setTmguid(item.getTmguid());
		odfs.add(a);
	}

	private int getOrderInstallDetailS(List<OrderInstallDetail> oids, int count, OrderBase order, ItfTblAzWgmxSyktDownload item) {
		WebsitSH websitSH;
		OrderInstallDetail a = new OrderInstallDetail();
		OrderPar req = new OrderPar();
		req.setSynReqId(item.getSynReqId());
		a= azWgmxSyktDownloadMapper.getAzsyktInfo(req);
		a.setId(IdWorker.getIdStr());

		WorderInfo worderInfo = publicService.getWorkerInfo(order.getWorkerId(), item.getCzwd(), order.getGroupCompanyId());
		a.setWxgid(worderInfo.getBrandWorkerNumber());
		if (item.getWcsj() !=null){
			a.setFirstTime(item.getWcsj());
		} else {
			if (item.getCzsj()!=null){
				a.setFirstTime(item.getCzsj());
			}
		}
		if (item.getCreatedDate()!=null){
			a.setCreateTime(item.getCreatedDate());
		}
		if (item.getLastModifiedDate()!=null){
			a.setUpdateTime(item.getLastModifiedDate());
		}
		// 结算网点 settle_websit_id 名称
		websitSH =  publicService.ptshwdToshshwd(a.getSettleWebsitId(),a.getMainId());
		a.setSettleWebsitId(websitSH.getWdId());
		a.setSettleWebsitName(websitSH.getWdmc());
		// 序号从1开始自加
		a.setCodeIndex(count++);
		websitSH =  publicService.ptshwdToshshwd(a.getOperatorWebsitId(),a.getMainId());
		a.setOperatorWebsitId(websitSH.getWdId());
		a.setOperatorWebsitName(websitSH.getWdmc());
		oids.add(a);
		return count;
	}

	private int getOrderInstallDetailO(List<OrderInstallDetail> oids, int count, OrderBase order, ItfTblAzWgmxQitaDownload item) {
		WebsitSH websitSH;
		OrderInstallDetail a = new OrderInstallDetail();
		OrderPar req = new OrderPar();
		req.setSynReqId(item.getSynReqId());
		a= azWgmxQityaDownloadMapper.getAzQitaInfo(req);
		a.setId(IdWorker.getIdStr());

		WorderInfo worderInfo = publicService.getWorkerInfo(order.getWorkerId(), item.getCzwd(), order.getGroupCompanyId());
		a.setWxgid(worderInfo.getBrandWorkerNumber());
		if (item.getWcsj() !=null){
			a.setFirstTime(item.getWcsj());
		} else {
			if (item.getCzsj()!=null){
				a.setFirstTime(item.getCzsj());
			}
		}
		if (item.getCreatedDate()!=null){
			a.setCreateTime(item.getCreatedDate());
		}
		if (item.getLastModifiedDate()!=null){
			a.setUpdateTime(item.getLastModifiedDate());
		}
		// 结算网点 settle_websit_id 名称
		websitSH =  publicService.ptshwdToshshwd(a.getSettleWebsitId(),a.getMainId());
		a.setSettleWebsitId(websitSH.getWdId());
		a.setSettleWebsitName(websitSH.getWdmc());
		// 序号从1开始自加
		a.setCodeIndex(count++);
		websitSH =  publicService.ptshwdToshshwd(a.getOperatorWebsitId(),a.getMainId());
		a.setOperatorWebsitId(websitSH.getWdId());
		a.setOperatorWebsitName(websitSH.getWdmc());
		oids.add(a);
		return count;
	}

	public void processOrderInstallDetailS(String downloadTaskNo, String pgguid) {
		List<OrderInstallDetail> oids = new ArrayList<>();
		List<ItfGreeToFaDownloadTaskList> its = new ArrayList<>();
		int count = 1;

		// 提取数据
		List<ItfTblAzWgmxSyktDownload> sykts = itfTblAzWgmxSyktDownloadService.lambdaQuery()
				.eq(ItfTblAzWgmxSyktDownload::getDownloadTaskNo, downloadTaskNo)
				.eq(ItfTblAzWgmxSyktDownload::getSynStatus,0).list();


		if (!CollectionUtils.isEmpty(sykts)){
			// 提取工单数据
			OrderBase order = orderBaseService.lambdaQuery()
					.eq(OrderBase::getPgguid,pgguid).one();

			for (ItfTblAzWgmxSyktDownload item :sykts){
				// 生成采集明细数据
				count = getOrderInstallDetailS(oids, count, order, item);

				// 增加处理三级从表的下载任务
				getItfGreeToFaDownloadTaskListS(its, item);
			}
			orderInstallDetailService.saveBatch(oids);
			oids.clear();
			itfGreeToFaDownloadTaskListService.saveBatch(its);
			its.clear();
		}

		// 修改同步状态
		upSynStatusAzSykt(downloadTaskNo);
	}

	public void processOrderInstallDetailO(String downloadTaskNo, String pgguid) {
		List<OrderInstallDetail> oids = new ArrayList<>();
		List<ItfGreeToFaDownloadTaskList> its = new ArrayList<>();
		int count = 1;

		// 提取数据
		List<ItfTblAzWgmxQitaDownload> qts = itfTblAzWgmxQitaDownloadService.lambdaQuery()
				.eq(ItfTblAzWgmxQitaDownload::getDownloadTaskNo, downloadTaskNo)
				.eq(ItfTblAzWgmxQitaDownload::getSynStatus,0).list();

		if (!CollectionUtils.isEmpty(qts)){
			// 提取工单数据
			OrderBase order = orderBaseService.lambdaQuery()
					.eq(OrderBase::getPgguid,pgguid).one();

			for (ItfTblAzWgmxQitaDownload item :qts){
				// 生成采集明细数据
				count = getOrderInstallDetailO(oids, count, order, item);

				// 增加处理三级从表的下载任务
				getItfGreeToFaDownloadTaskListO(its, item);
			}
			orderInstallDetailService.saveBatch(oids);
			oids.clear();
			itfGreeToFaDownloadTaskListService.saveBatch(its);
			its.clear();
		}

		// 修改同步状态
		upSynStatusAzQita(downloadTaskNo);
	}

	// 存在进行修改，不存在则插入
	public void processYjhxJdd(String downloadTaskNo, String pgguid) {
        // 提取数据
		List<ItfTblYjhxJddDownload> jdds = itfTblYjhxJddDownloadService.lambdaQuery()
				.eq(ItfTblYjhxJddDownload::getDownloadTaskNo, downloadTaskNo)
				.eq(ItfTblYjhxJddDownload::getSynStatus,0).list();

		if (!CollectionUtils.isEmpty(jdds)){
			for (ItfTblYjhxJddDownload item :jdds){
				YjhxAppraise jdd = yjhxAppraiseService.lambdaQuery()
						.eq(YjhxAppraise::getHxjddid,item.getHxjddid()).one();
				// 存在更新，不存在插入
				addOrUp(pgguid, item, jdd);
			}
		}
		// 修改同步状态
		upSynStatusJdd(downloadTaskNo);
	}

	private void addOrUp(String pgguid, ItfTblYjhxJddDownload item, YjhxAppraise jdd) {
		if (jdd !=null){
			jdd.setOldMachineBrand(item.getOldMachineBrand());
			jdd.setOldMachineType(item.getOldMachineType());
			jdd.setBrandFlag(item.getBrandFlag() ? 1:0);
			jdd.setRealBrand(item.getRealBrand());
			jdd.setRealType(item.getRealType());
			jdd.setMachineIntegrity(item.getMachineIntegrity());
			jdd.setTempBarcode(item.getTempBarcode());
			jdd.setTempBarcodeImg(item.getTempBarcodeImg());
			jdd.setIdentifyResult(item.getIdentifyResult());
			jdd.setXsdh(item.getXsdh());
			jdd.setCpps(item.getCpps());
			jdd.setStat(item.getStat());
			jdd.setNjtm(item.getNjtm());
			jdd.setWjtm(item.getWjtm());
			jdd.setUploadNotifyFlag(1);
			jdd.updateById();
		} else {
			YjhxAppraise add = new YjhxAppraise();
			// 工单ID
			OrderBase orderBase = orderBaseService.lambdaQuery()
					.eq(OrderBase::getPgguid, pgguid).one();
			MyBeanUtils.copyProperties(item,add);
			add.setOrderBaseId(orderBase.getId());
			add.setWebsitId(orderBase.getWebsitId());
			add.setWorkerId(orderBase.getWorkerId());
			add.setWorkerName(orderBase.getWorkerName());
			add.setPgid(orderBase.getPgid());
			add.insert();
		}
	}

	public void processInformatino(String downloadTaskNo, String pgguid, Map<String, List<SysDict>> sysDictRefDLMap) {
		// 提取数据
		List<ItfTblAzAssignXzydDownload> zdmx = itfTblAzAssignXzydDownloadService.lambdaQuery()
				.eq(ItfTblAzAssignXzydDownload::getDownloadTaskNo, downloadTaskNo)
				.eq(ItfTblAzAssignXzydDownload::getSynStatus,0).list();

		if (!CollectionUtils.isEmpty(zdmx)){
			// 取最大的syn_req_id 用于判断是否为最后一条记录
			OrderPar req = new OrderPar();
			req.setOrderNo(downloadTaskNo);
			ItfTblAzAssignXzydDownload maxzd = installXzydDownloadMapper.getSynReqId(req);
			WebsitFWS sh = new WebsitFWS();
			for (ItfTblAzAssignXzydDownload item:zdmx){
				// 存在更新，不存在插入 order_information syncId三方平台主键
				OrderInformation info = orderInformationService.lambdaQuery()
						.eq(OrderInformation::getSyncId,item.getId()).one();

				// 工单ID
				OrderBase orderBase = orderBaseService.lambdaQuery()
						.eq(OrderBase::getPgguid, pgguid).one();

				if (info !=null){
					// 次数，与是否已读不相同时修改，其他不修改 这里只能做是否已读的处理
					if (!info.getReadStatus().equals(item.getYdbz())){
						upInformation(sysDictRefDLMap, info, item,orderBase);
					}
				} else {
					addInformation(sysDictRefDLMap, item, orderBase);
				}

				// 最后一条记录时更新主表的子信息字段
				if (maxzd.getSynReqId().equals(item.getSynReqId()) && !orderBase.getIsChildInfo().equals("YES")){
					orderBase.setIsChildInfo("YES");
					orderBase.updateById();
				}
			}
		}
		// 修改同步状态
		upSynStatus(downloadTaskNo);
	}

	public void upInformation(@NotNull Map<String, List<SysDict>> sysDictRefDLMap, OrderInformation info,
							  ItfTblAzAssignXzydDownload item, OrderBase orderBase) {
		WebsitFWS websitFWS = new WebsitFWS();

		info.setAskCategoryId(item.getXzyqlb());
		info.setAskCategoryName("");
		if (sysDictRefDLMap.containsKey(item.getXzyqlb())){
			info.setAskCategoryName(sysDictRefDLMap.get(item.getXzyqlb()).get(0).getDictValue());
		}

		info.setRemark(item.getXzyq());
		if (item.getYdbz().equals(1)){
			info.setReadStatus(item.getYdbz());
		} else {
			info.setReadStatus(0);
		}
		info.setReadName(item.getYdrmc());
		info.setReadTime(item.getYdsj());
		// 网点信息单独处理
		if (item.getYdbz().equals(1)){
			// 先查售后网点
			websitFWS = publicService.shshwdToptshwd(item.getYdwd(),orderBase);
			if (StringUtils.isEmpty(websitFWS.getWebsitId())){
				websitFWS = publicService.shxswdToptxswd(item.getYdwd(),orderBase);
			}
		} else {
			// 先查售后网点
			websitFWS = publicService.shshwdToptshwd(item.getWdno(),orderBase);
			if (StringUtils.isEmpty(websitFWS.getWebsitId())){
				websitFWS = publicService.shxswdToptxswd(item.getWdno(),orderBase);
			}
		}

		info.setWebsitId(websitFWS.getWebsitId());
		info.setWebsitName(websitFWS.getWdmc());
		info.updateById();
	}

	public void addInformation(Map<String, List<SysDict>> sysDictRefDLMap,
								ItfTblAzAssignXzydDownload item, OrderBase orderBase) {
		WebsitFWS websitFWS = new WebsitFWS();
		OrderInformation info = new OrderInformation();
		info.setSyncId(item.getId());
		info.setAskCategoryId(item.getXzyqlb());
		info.setAskCategoryName("");
		if (sysDictRefDLMap.containsKey(item.getXzyqlb())){
			info.setAskCategoryName(sysDictRefDLMap.get(item.getXzyqlb()).get(0).getDictValue());
		}
		info.setOrderBaseId(orderBase.getId());
		info.setRemark(item.getXzyq());
		info.setCreateBy(item.getCreatedBy());
		info.setCreateTime(item.getCreatedDate());
		info.setUpdateBy(item.getLastModifiedBy());
		info.setUpdateTime(item.getLastModifiedDate());
		// 网点信息单独处理
		if (item.getYdbz().equals(1)){
			// 先查售后网点
			websitFWS = publicService.shshwdToptshwd(item.getYdwd(),orderBase);
			if (StringUtils.isEmpty(websitFWS.getWebsitId())){
				websitFWS = publicService.shxswdToptxswd(item.getYdwd(),orderBase);
			}
		} else {
			// 先查售后网点
			websitFWS = publicService.shshwdToptshwd(item.getWdno(),orderBase);
			if (StringUtils.isEmpty(websitFWS.getWebsitId())){
				websitFWS = publicService.shxswdToptxswd(item.getWdno(),orderBase);
			}
		}

		info.setWebsitId(websitFWS.getWebsitId());
		info.setWebsitName(websitFWS.getWdmc());
		if (item.getYdbz().equals(1)){
			info.setReadStatus(item.getYdbz());
		} else {
			info.setReadStatus(0);
		}
		info.setWebsitName(websitFWS.getWdmc());
		info.setReadTime(item.getYdsj());
		info.insert();
	}

	public void upSynStatusProduct(String downloadTaskNo) {
		OrderPar req = new OrderPar();
		req.setOrderNo(downloadTaskNo);
		tradeNewForOldDownloadMapper.updateSynStatus(req);
		installDownloadTaskListMapper.updateSynStatus(req);
	}

	public void upSynStatusAzJykt(String downloadTaskNo) {
		OrderPar req = new OrderPar();
		req.setOrderNo(downloadTaskNo);

		ItfTblAzWgmxJyktDownload up = new ItfTblAzWgmxJyktDownload();
		up.setSynStatus(1);
		QueryWrapper upWrapper = new QueryWrapper<ItfTblAzWgmxJyktDownload>()
				.eq("download_task_no", downloadTaskNo)
				.eq("syn_status",0);
		itfTblAzWgmxJyktDownloadService.update(up,upWrapper);
		installDownloadTaskListMapper.updateSynStatus(req);
	}

	public void upSynStatusAzJyktFJ(String downloadTaskNo) {
		OrderPar req = new OrderPar();
		req.setOrderNo(downloadTaskNo);

		ItfTblAzWgmxJyktFjDownload up = new ItfTblAzWgmxJyktFjDownload();
		up.setSynStatus(1);
		QueryWrapper upWrapper = new QueryWrapper<ItfTblAzWgmxJyktFjDownload>()
				.eq("download_task_no", downloadTaskNo)
				.eq("syn_status",0);
		itfTblAzWgmxJyktFjDownloadService.update(up,upWrapper);
		installDownloadTaskListMapper.updateSynStatus(req);
	}

	public void upSynStatusAzSyktFJ(String downloadTaskNo) {
		ItfTblAzWgmxSyktFjDownload up = new ItfTblAzWgmxSyktFjDownload();
		up.setSynStatus(1);
		QueryWrapper upWrapper = new QueryWrapper<ItfTblAzWgmxSyktFjDownload>()
				.eq("download_task_no", downloadTaskNo)
				.eq("syn_status",0);
		itfTblAzWgmxSyktFjDownloadService.update(up,upWrapper);
	}

	public void upSynStatusAzOFJ(String downloadTaskNo) {
		OrderPar req = new OrderPar();
		req.setOrderNo(downloadTaskNo);

		ItfTblAzWgmxQitaFjDownload up = new ItfTblAzWgmxQitaFjDownload();
		up.setSynStatus(1);
		QueryWrapper upWrapper = new QueryWrapper<ItfTblAzWgmxQitaFjDownload>()
				.eq("download_task_no", downloadTaskNo)
				.eq("syn_status",0);
		itfTblAzWgmxQitaFjDownloadService.update(up,upWrapper);
		installDownloadTaskListMapper.updateSynStatus(req);
	}

	public void upSynStatusAzSyktTM(String downloadTaskNo) {
		ItfTblAzWgmxSyktTmmxLsDownload up = new ItfTblAzWgmxSyktTmmxLsDownload();
		up.setSynStatus(1);
		QueryWrapper upWrapper = new QueryWrapper<ItfTblAzWgmxSyktTmmxLsDownload>()
				.eq("download_task_no", downloadTaskNo)
				.eq("syn_status",0);
		itfTblAzWgmxSyktTmmxLsDownloadService.update(up,upWrapper);
	}

	public void upSynStatusAzSykt(String downloadTaskNo) {
		OrderPar req = new OrderPar();
		req.setOrderNo(downloadTaskNo);

		ItfTblAzWgmxSyktDownload up = new ItfTblAzWgmxSyktDownload();
		up.setSynStatus(1);
		QueryWrapper upWrapper = new QueryWrapper<ItfTblAzWgmxSyktDownload>()
				.eq("download_task_no", downloadTaskNo)
				.eq("syn_status",0);
		itfTblAzWgmxSyktDownloadService.update(up,upWrapper);
		installDownloadTaskListMapper.updateSynStatus(req);
	}

	public void upSynStatusAzFJTM(String downloadTaskNo) {
		OrderPar req = new OrderPar();
		req.setOrderNo(downloadTaskNo);
		installDownloadTaskListMapper.updateSynStatus(req);
	}

	public void upSynStatusAzQita(String downloadTaskNo) {
		OrderPar req = new OrderPar();
		req.setOrderNo(downloadTaskNo);

		ItfTblAzWgmxQitaDownload up = new ItfTblAzWgmxQitaDownload();
		up.setSynStatus(1);
		QueryWrapper upWrapper = new QueryWrapper<ItfTblAzWgmxQitaDownload>()
				.eq("download_task_no", downloadTaskNo)
				.eq("syn_status",0);
		itfTblAzWgmxQitaDownloadService.update(up,upWrapper);
		installDownloadTaskListMapper.updateSynStatus(req);
	}

	public void upSynStatusJdd(String downloadTaskNo) {
		OrderPar req = new OrderPar();
		req.setOrderNo(downloadTaskNo);
		yjhxJddDownloadMapper.updateSynStatus(req);
		installDownloadTaskListMapper.updateSynStatus(req);
	}

	public void upSynStatus(String downloadTaskNo) {
		OrderPar req = new OrderPar();
		req.setOrderNo(downloadTaskNo);
		installXzydDownloadMapper.updateSynStatus(req);
		installDownloadTaskListMapper.updateSynStatus(req);
	}

	@Override
	public void updateError(String downloadTaskNo, Integer downloadTimes, String errMessage) {
		if (downloadTimes == null) {
			downloadTimes = 1;
		} else {
			downloadTimes++;
		}
		jdbcTemplate.update(
				"UPDATE itf_gree_to_fa_download_task_list set download_err_msg=?,download_times=? where download_task_no=?",
				new Object[] { errMessage, downloadTimes, downloadTaskNo });
	}

}
