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

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
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 javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@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;
	@Resource
	ItfTblWxjsJyktDownloadService itfTblWxjsJyktDownloadService;
	@Resource
	OrderRepairDetailService orderRepairDetailService;
	@Resource
	OrderProductService orderProductService;
	@Resource
	ItfTblWxjsXxyyJyktDownloadService itfTblWxjsXxyyJyktDownloadService;
	@Resource
	OrderRepairDetailReasonService orderRepairDetailReasonService;
	@Resource
	RepairBugAppService repairBugAppService;
	@Resource
	OrderRepairDetailItemService orderRepairDetailItemService;
	@Resource
	ItfTblWxjsWxxmJyktDownloadService itfTblWxjsWxxmJyktDownloadService;
	@Resource
	ItfTblWxjsPjmxJyktDownloadService itfTblWxjsPjmxJyktDownloadService;
	@Resource
	ItfTblWxjsFjJyktDownloadService itfTblWxjsFjJyktDownloadService;
	@Autowired
	private DetailDownloadService detailDownloadService;



	

	@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>> getTaskDataInstallTest(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 a.download_key_value='B205E9EFB725E4E10268BB80DACF38E5' ");
		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
	public void insertData(String downloadTaskNo, List<DetailDownloadData> detailDownloadDatas,
						   int downloadTaskType, String pgguid,Map<String, List<SysDict>> sysDictRefDLMap,Long id)
			throws Exception {

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

		if (detailDownloadDatas.size()<=0){
			// 修改同步表状态信息
			updateSyncTable(id,"获取的数据为空无需同步");
			return;
		}

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

	public void updateSyncTable(Long synReqId, String msg) {
		jdbcTemplate.update("update itf_gree_to_fa_download_task_list set download_status = 1,download_time=?,download_err_msg=? where id=?",
				new Object[] { new Date(System.currentTimeMillis()), msg, synReqId });
	}


	@Override
	@Transactional(rollbackFor = Exception.class)
	public void insertDataRepair(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());
		}

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


	@Transactional(rollbackFor = Exception.class)
	public void process(String downloadTaskNo, int downloadTaskType, String pgguid, Map<String, List<SysDict>> sysDictRefDLMap) throws Exception {
		try{
			if (downloadTaskType == 2201){
				// 安装工单采集数据下载(家用空调)	TL_SynDataFrom_tbl_az_wgmx_jykt
				// 安装工单主表的order_base pgguid OK
				// itf_tbl_az_wgmx_jykt_download.pgguid=order_base.pgguid
				processOrderInstallDetailJ(downloadTaskNo, pgguid);
			} else if (downloadTaskType == 220101){
				// 安装工单采集附件表数据下载(家用空调)	TL_SynDataFrom_tbl_az_wgmx_jykt_child
				// pgguid = 家用空调完工明细(itf_tbl_az_wgmx_jykt_download)的pgwcmxid　ok
				// itf_tbl_az_wgmx_jykt_download.pgwcmxid = itf_tbl_az_wgmx_jykt_fj_download.pgwcmxid
				processJyktFj(downloadTaskNo, pgguid);
			} else if (downloadTaskType == 2202){
				// 安装工单采集数据下载(商用空调)	TL_SynDataFrom_tbl_az_wgmx_sykt
				// 安装工单主表的order_base pgguid OK
				processOrderInstallDetailS(downloadTaskNo, pgguid);
			} else if (downloadTaskType == 220201){
				//  安装工单采集附件表数据下载(商用空调) TL_SynDataFrom_tbl_az_wgmx_sykt_child
				// pgguid = 商用空调完工明细itf_tbl_az_wgmx_sykt_download的pgwcmxid　ok
				processSyktFjAndTM(downloadTaskNo, pgguid);
			} else if (downloadTaskType == 2203){
				// 安装工单采集数据下载(其他)	TL_SynDataFrom_tbl_az_wgmx_qita
				// 安装工单主表的order_base pgguid OK
				processOrderInstallDetailO(downloadTaskNo, pgguid);
			} else if (downloadTaskType == 220301){
				// 安装工单采集附件表数据下载(其他) 	TL_SynDataFrom_tbl_az_wgmx_qita_child
				// pgguid = 其他完工明细itf_tbl_az_wgmx_qita_download.pgwcmxid ok
				processOktFj(downloadTaskNo, pgguid);
			} else if (downloadTaskType == 2204){
				// 以旧换新鉴定单 itf_tbl_yjhx_jdd_download  TL_SynDataFrom_tbl_yjhx_jdd
				// pgguid 为安装工单下载主表的itf_tbl_az_assign_lc_ls_download pgguid OK
				processYjhxJdd(downloadTaskNo, pgguid);
			} else if (downloadTaskType == 2205){
				// 以旧换新旧机信息 itf_tbl_trade_new_for_old_download  TL_SynDataFrom_tbl_trade_new_for_old
				// pgguid 为安装工单下载主表的itf_tbl_az_assign_lc_ls_download pgguid OK
				processOldForNewProduct(downloadTaskNo, pgguid);
			} else if (downloadTaskType == 2206){
				// 安装工单子表数据阅读信息 itf_tbl_az_assign_xzyd_download  TL_SynDataFrom_tbl_az_assign_xzyd
				// pgguid 为安装工单下载主表的itf_tbl_az_assign_lc_ls_download pgguid OK
				processInformatino(downloadTaskNo, pgguid, sysDictRefDLMap);
			} else if (downloadTaskType == 6601){
				// 维修工单二子表下载	TL_SynDataFrom_tbl_wxjs_jykt OK
				processWxjsJykt(downloadTaskNo, pgguid);
			} else if (downloadTaskType == 660101){
				// 维修工单三子表下载  TL_SynDataFrom_tbl_wxjs_jykt_child OK
				// pgguid=itf_tbl_wxjs_jykt_download.wxjsguid
				processSix(downloadTaskNo, pgguid);
			}
			// 差指定安维工单下差功能


		}catch (Exception ex) {
			ex.printStackTrace();
			// 抛异常目的是把前期的数据操作回滚
			throw new Exception(ex);
		}
	}

	public void processRepair(String downloadTaskNo, int downloadTaskType, String pgguid, Map<String, List<SysDict>> sysDictRefDLMap) throws Exception {
		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)
					.last("limit 1").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 processOrderInstallDetailJBak(String downloadTaskNo, String pgguid) {
		List<OrderInstallDetail> oids = new ArrayList<>();
		List<OrderInstallDetailCode> oidcs = new ArrayList<>();
		List<ItfGreeToFaDownloadTaskList> its = new ArrayList<>();
		int count = 1;
		int outid=0;

		// 提取数据 pgwcmxid 主键
		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)
					.last("limit 1").one();
			for (ItfTblAzWgmxJyktDownload item :jykts){
				// 生成采集明细数据
				count = getOrderInstallDetail(oids, count, order, item,downloadTaskNo,pgguid);

				// 增加处理三级从表的下载任务
				getItfGreeToFaDownloadTaskList(its, item);
			}

			// 生成采集条码数据
			getOrderInstallDetailCode(oids, oidcs, outid, order);


			if (oids.size()>0){
				orderInstallDetailService.saveBatch(oids);
				oids.clear();
			}

			if (oidcs.size()>0){
				orderInstallDetailCodeService.saveBatch(oidcs);
				oidcs.clear();
			}

			itfGreeToFaDownloadTaskListService.saveBatch(its);
			its.clear();
		}

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


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

		// 提取数据 pgwcmxid 主键
		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)
					.last("limit 1").one();

			// outCjDownloadFlag = 1 代表需要从总部下载
			if ((order !=null && order.getOutCjDownloadFlag().equals(1)) || (order ==null)) {
				List<OrderInstallDetail> orderDetailRec = orderInstallDetailService.lambdaQuery()
						.eq(OrderInstallDetail::getOrderBaseId, order.getId())
						.eq(OrderInstallDetail::getStatus, 1).list();
				if (CollectionUtils.isNotEmpty(orderDetailRec)){
					// 存在已采集的数据忽略下载
				} else {
					// 清除本地的待采集数据
					List<OrderInstallDetail> delorderDetailRec = orderInstallDetailService.lambdaQuery()
							.eq(OrderInstallDetail::getOrderBaseId, order.getId())
							.eq(OrderInstallDetail::getStatus,0).list();
					if (CollectionUtils.isNotEmpty(delorderDetailRec)){
						delorderDetailRec.stream().forEach(ddr -> {
							ids.add(ddr.getId());
						});
						orderInstallDetailService.removeByIds(ids);
					}

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

						// 增加处理三级从表的下载任务
						getItfGreeToFaDownloadTaskList(its, item);
					}

					// 生成采集条码数据
					getOrderInstallDetailCode(oids, oidcs, outid, order);


					if (oids.size()>0){
						orderInstallDetailService.saveBatch(oids);
						oids.clear();
					}

					if (oidcs.size()>0){
						orderInstallDetailCodeService.saveBatch(oidcs);
						oidcs.clear();
					}

					itfGreeToFaDownloadTaskListService.saveBatch(its);
					its.clear();
				}
			}
		}

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

	private void getOrderInstallDetailCode(List<OrderInstallDetail> oids, List<OrderInstallDetailCode> oidcs, int outid, OrderBase order) {
		if (oids.size()>0){
			for (OrderInstallDetail a : oids){
				// log.info("生成采集条码表a {}",JSONObject.toJSONString(a));

				// 把条码信息放在采集条码表中使用
				if (StringUtils.isNotEmpty(a.getInsideCode())){
					outid = getInOutid(oidcs, outid, order, a, a.getInsideCode(), "1");
				}
				if (StringUtils.isNotEmpty(a.getOutCode())){
					outid = getInOutid(oidcs, outid, order, a, a.getOutCode(), "2");
				}
			}
		}
	}

	private void getOrderInstallDetailOtherCode(List<OrderInstallDetail> oids, List<OrderInstallDetailCode> oidcs,
												OrderBase order) {
		int outid=0;
		if (oids.size()>0){
			for (OrderInstallDetail a : oids){
				// log.info("生成采集条码表a {}",JSONObject.toJSONString(a));

				// 把条码信息放在采集条码表中使用
				if (StringUtils.isNotEmpty(a.getInsideCode())){
					outid = getInOutid(oidcs, outid, order, a, a.getInsideCode(), "1");
				}
				if (StringUtils.isNotEmpty(a.getOutCode())){
					outid = getInOutid(oidcs, outid, order, a, a.getOutCode(), "2");
				}
			}
		}
	}

	private int getInOutid(List<OrderInstallDetailCode> oidcs, int outid, OrderBase order, OrderInstallDetail a, String insideCode, String s) {
		OrderInstallDetailCode odf = new OrderInstallDetailCode();
		odf.setId(IdWorker.getIdStr());
		// 结算网点
		odf.setWebsitId(a.getSettleWebsitId());
		odf.setOrderBaseId(order.getId());
		odf.setOrderDetailId(a.getId());
		odf.setCode(insideCode);
		odf.setType(s);
		// 图放在附件中提取
		odf.setPassword(a.getInsidePassword());

		if (a.getCreateTime() != null) {
			odf.setCreateTime(a.getCreateTime());
		}
		if (a.getUpdateTime() != null) {
			odf.setUpdateTime(a.getUpdateTime());
		}
		odf.setPgguid(order.getPgguid());
		odf.setPgwcmxid(a.getPgwcmxid());
		odf.setStatus(1);
		if (a.getStatus() == 2) {
			odf.setStatus(0);
		}
		odf.setOutId(outid);
		odf.setSortNum(outid);
		outid = outid + 1;
		oidcs.add(odf);
		return outid;
	}

	// pgguid = order_install_detail.pgwcmxid
	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()
				.eq(OrderInstallDetail::getPgwcmxid,pgguid).list();
		oidsMap = oids.stream().collect(Collectors.groupingBy(OrderInstallDetail::getPgwcmxid));



		if (!CollectionUtils.isEmpty(jykts)){
			// 提取工单数据
			OrderBase order = orderBaseService.lambdaQuery()
					.eq(OrderBase::getId,oids.get(0).getOrderBaseId())
					.last("limit 1").one();

			if (order!=null){
				// 提取现有的采集附件数据
				List<OrderDetailFile> fs = orderDetailFileService.lambdaQuery()
						.select(OrderDetailFile::getFjguid,OrderDetailFile::getFileType)
						.eq(OrderDetailFile::getOrderBaseId,order.getId()).list();
				if (CollectionUtils.isNotEmpty(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())){
						OrderDetailFile a = new OrderDetailFile();
						getItfTblAzWgmxJyktFj(odfs,oidsMap.get(item.getPgwcmxid()).get(0), order, item, a);
					}
				}

				if (odfs.size()>0) {
					orderDetailFileService.saveBatch(odfs);
					odfs.clear();
				}
			}
		}
		// 修改同步状态
		upSynStatusAzJyktFJ(downloadTaskNo);
	}

	// pgguid = order_repair_detail.brand_wxjsguid
	// TL_SynDataFrom_tbl_wxjs_jykt_child
	// 四个方法放在一起处理 有一个处理完就要修改对应的task_list
	public void processSix(String downloadTaskNo, String pgguid) {
        // 维修现象下载同步   无数据时不处理同时修改同步状态
		// TL_SynDataFrom_tbl_wxjs_xxyy_jykt
		// itf_tbl_wxjs_xxyy_jykt_download   ->OrderRepairDetailReason
		if (processWxJsXxyyJykt(downloadTaskNo,pgguid)) {
			return;
		}
		// 维修项目现象 无数据时不处理同时修改同步状态  与维修现象合到一个表中
		// TL_SynDataFrom_tbl_wxjs_wxxm_jykt
		// itf_tbl_wxjs_wxxm_jykt_download  ->order_repair_detail_item
		/*if (processWxJsWxxmJykt(downloadTaskNo,pgguid)) {
			return;
		}*/

		// 配件表 无数据时不处理同时修改同步状态
		// TL_SynDataFrom_tbl_wxjs_pjmx_jykt
		// itf_tbl_wxjs_pjmx_jykt_download
		processWxjsPjmxJykt(downloadTaskNo);

		// 维修项目现象 无数据时不处理同时修改同步状态
		// TL_SynDataFrom_tbl_wxjs_fj_jykt
		// itf_tbl_wxjs_fj_jykt_download  ->order_detail_file
		if (processWxJsFjJykt(downloadTaskNo,pgguid)) {
			return;
		}



		// 修改同步状态
		OrderPar req = new OrderPar();
		req.setOrderNo(downloadTaskNo);
		installDownloadTaskListMapper.updateSynStatus(req);
	}


	// pgguid = order_repair_detail.brand_wxjsguid
	// TL_SynDataFrom_tbl_wxjs_jykt_child
	// 四个方法放在一起处理 有一个处理完就要修改对应的task_list
	public Boolean processWxJsXxyyJykt(String downloadTaskNo, String pgguid) {
		List<OrderRepairDetailReason> ordrs = new ArrayList<>();
		List<OrderRepairDetail> irds = new ArrayList<>();
		Map<String,List<OrderRepairDetail>> irdsMap = new HashMap<>();
		List<OrderRepairDetailReason> ordrsOld = new ArrayList<>();
		List<String> xxyyguid = new ArrayList<>();
		List<ItfTblWxjsWxxmJyktDownload> wxxms = new ArrayList<>();

				// 维修现象下载同步   无数据时不处理同时修改同步状态
		// TL_SynDataFrom_tbl_wxjs_xxyy_jykt
		// itf_tbl_wxjs_xxyy_jykt_download   ->OrderRepairDetailReason
		List<ItfTblWxjsXxyyJyktDownload> wxxxs = itfTblWxjsXxyyJyktDownloadService.lambdaQuery()
				.eq(ItfTblWxjsXxyyJyktDownload::getDownloadTaskNo,downloadTaskNo).list();

		if (CollectionUtils.isNotEmpty(wxxxs)){
			irds = orderRepairDetailService.lambdaQuery()
					.eq(OrderRepairDetail::getBrandWxjsguid,pgguid).list();
			// 无数据不处理
			if (CollectionUtils.isEmpty(irds)) {
				return Boolean.TRUE;
			}

			irdsMap = irds.stream().collect(Collectors.groupingBy(OrderRepairDetail::getBrandWxjsguid));

			ordrsOld = orderRepairDetailReasonService.lambdaQuery()
					.eq(OrderRepairDetailReason::getOrderBaseId,irds.get(0).getOrderBaseId()).list();

			if (CollectionUtils.isNotEmpty(ordrsOld)){
				ordrsOld.stream().forEach(event->{
					xxyyguid.add(event.getXxyyguid());
				});
			}

			// 生成故障现象数据 暂时忽略更新，无新增
			for (ItfTblWxjsXxyyJyktDownload item:wxxxs){
				if (xxyyguid.contains(item.getXxyyguid())){
					continue;
				}
				getOrderRepairDetailReason(ordrs, irdsMap, item, irds);
				xxyyguid.add(item.getXxyyguid());
			}

			// 两表合一，这里赋值维修项目值
			wxxms = getItfTblWxjsWxxmJyktDownloads(downloadTaskNo, ordrs, wxxms);

			if (ordrs.size()>0) {
				orderRepairDetailReasonService.saveBatch(ordrs);
				ordrs.clear();
			}
			// 修改同步状态
			upSynStatusWxjsXxyyJykt(downloadTaskNo);
			// 修改同步状态
			if (wxxms.size()>0){
				upSynStatusWxJsWxxmJykt(downloadTaskNo);
			}
		}
		return Boolean.FALSE;
	}

	private List<ItfTblWxjsWxxmJyktDownload> getItfTblWxjsWxxmJyktDownloads(String downloadTaskNo,
																			List<OrderRepairDetailReason> ordrs,
																			List<ItfTblWxjsWxxmJyktDownload> wxxms) {
		if (ordrs.size()>0) {
			// 维修现象下载同步   无数据时不处理同时修改同步状态
			// TL_SynDataFrom_tbl_wxjs_wxxm_jykt
			// itf_tbl_wxjs_wxxm_jykt_download   ->order_repair_detail_item
			wxxms = itfTblWxjsWxxmJyktDownloadService.lambdaQuery()
					.eq(ItfTblWxjsWxxmJyktDownload::getDownloadTaskNo, downloadTaskNo).list();
			// 生成维修现象数据
			for (ItfTblWxjsWxxmJyktDownload item: wxxms){
				for (OrderRepairDetailReason reason : ordrs){
					if (reason.getXxyyguid().equals(item.getXxyyguid())){
						reason.setRepairItemId(item.getWxxmh());
						reason.setRepairItemName(item.getMshu());
					}
				}
			}
		}
		return wxxms;
	}

	// pgguid = order_repair_detail.brand_wxjsguid
	// TL_SynDataFrom_tbl_wxjs_wxxm_jykt
	// itf_tbl_wxjs_wxxm_jykt_download  ->order_repair_detail_item
	public Boolean processWxJsWxxmJykt(String downloadTaskNo, String pgguid) {
		List<OrderRepairDetailItem> ordrs = new ArrayList<>();
		List<OrderRepairDetail> irds = new ArrayList<>();
		Map<String,List<OrderRepairDetail>> irdsMap = new HashMap<>();
		List<OrderRepairDetailItem> ordrsOld = new ArrayList<>();
		List<String> wxjsguid = new ArrayList<>();
		List<String> orderRepairDetailIds = new ArrayList<>();

		// 维修现象下载同步   无数据时不处理同时修改同步状态
		// TL_SynDataFrom_tbl_wxjs_wxxm_jykt
		// itf_tbl_wxjs_wxxm_jykt_download   ->order_repair_detail_item
		List<ItfTblWxjsWxxmJyktDownload> wxxms = itfTblWxjsWxxmJyktDownloadService.lambdaQuery()
				.eq(ItfTblWxjsWxxmJyktDownload::getDownloadTaskNo,downloadTaskNo).list();

		if (CollectionUtils.isNotEmpty(wxxms)){
			irds = orderRepairDetailService.lambdaQuery()
					.eq(OrderRepairDetail::getBrandWxjsguid,pgguid).list();
			// 无数据不处理
			if (CollectionUtils.isEmpty(irds)) {
				return Boolean.TRUE;
			}

			irds.stream().forEach(event->{
				orderRepairDetailIds.add(event.getId());
			});


			irdsMap = irds.stream().collect(Collectors.groupingBy(OrderRepairDetail::getBrandWxjsguid));

			ordrsOld = orderRepairDetailItemService.lambdaQuery()
					.in(OrderRepairDetailItem::getOrderRepairDetailId,orderRepairDetailIds).list();

			if (CollectionUtils.isNotEmpty(ordrsOld)){
				ordrsOld.stream().forEach(event->{
					wxjsguid.add(event.getWxjsguid());
				});
			}

			// 生成维修现象数据 暂时忽略更新，无新增
			for (ItfTblWxjsWxxmJyktDownload item:wxxms){
				if (wxjsguid.contains(item.getWxxmguid())){
					continue;
				}
				getOrderRepairDetailItem(ordrs, irdsMap, item);
			}

			if (ordrs.size()>0) {
				orderRepairDetailItemService.saveBatch(ordrs);
				ordrs.clear();
			}
			// 修改同步状态
			upSynStatusWxJsWxxmJykt(downloadTaskNo);
		}
		return Boolean.FALSE;
	}

	// pgguid = order_repair_detail.brand_wxjsguid
	// TL_SynDataFrom_tbl_wxjs_pjmx_jykt
	// itf_tbl_wxjs_pjmx_jykt_download
	public void processWxjsPjmxJykt(String downloadTaskNo) {
		// 直接修改同步状态
		upSynStatusWxjsPjmxJykt(downloadTaskNo);
	}

	// pgguid = order_repair_detail.brand_wxjsguid
	// TL_SynDataFrom_tbl_wxjs_fj_jykt
	// itf_tbl_wxjs_fj_jykt_download  ->order_detail_file
	public Boolean processWxJsFjJykt(String downloadTaskNo, String pgguid) {
		List<OrderDetailFile> ordrs = new ArrayList<>();
		List<OrderRepairDetail> irds = new ArrayList<>();
		Map<String,List<OrderRepairDetail>> irdsMap = new HashMap<>();
		List<OrderDetailFile> ordrsOld = new ArrayList<>();
		List<String> fjguid = new ArrayList<>();

		// 维修现象下载同步   无数据时不处理同时修改同步状态
		// TL_SynDataFrom_tbl_wxjs_fj_jykt
		// itf_tbl_wxjs_fj_jykt_download   ->order_detail_file
		List<ItfTblWxjsFjJyktDownload> wxjsfj = itfTblWxjsFjJyktDownloadService.lambdaQuery()
				.eq(ItfTblWxjsFjJyktDownload::getDownloadTaskNo,downloadTaskNo).list();

		if (CollectionUtils.isNotEmpty(wxjsfj)){
			irds = orderRepairDetailService.lambdaQuery()
					.eq(OrderRepairDetail::getBrandWxjsguid,pgguid).list();
			// 无数据不处理
			if (CollectionUtils.isEmpty(irds)) {
				return Boolean.TRUE;
			}

			irdsMap = irds.stream().collect(Collectors.groupingBy(OrderRepairDetail::getBrandWxjsguid));

			ordrsOld = orderDetailFileService.lambdaQuery()
					.eq(OrderDetailFile::getOrderBaseId,irds.get(0).getOrderBaseId()).list();

			if (CollectionUtils.isNotEmpty(ordrsOld)){
				ordrsOld.stream().forEach(event->{
					fjguid.add(event.getFjguid());
				});
			}

			// 生成维修现象数据 暂时忽略更新，无新增
			for (ItfTblWxjsFjJyktDownload item:wxjsfj){
				if (fjguid.contains(item.getFjguid())){
					continue;
				}
				getOrderDetailFile(ordrs, irds, irdsMap, item);
				fjguid.add(item.getFjguid());
			}

			if (ordrs.size()>0) {
				orderDetailFileService.saveBatch(ordrs);
				ordrs.clear();
			}
			// 修改同步状态
			upSynStatusWxJsFjJykt(downloadTaskNo);
		}
		return Boolean.FALSE;
	}

	private void getOrderDetailFile(List<OrderDetailFile> ordrs, List<OrderRepairDetail> irds,
									Map<String, List<OrderRepairDetail>> irdsMap, ItfTblWxjsFjJyktDownload item) {
		OrderDetailFile n = new OrderDetailFile();
		n.setId(IdWorker.getIdStr());
		n.setFjguid(item.getFjguid());
		n.setOrderBaseId(irds.get(0).getOrderBaseId());
		n.setOrderDetailId(irdsMap.get(item.getWxjsguid()).get(0).getId());
		n.setFileType(21);
		if (item.getTpms().equals("内机条码图像")){
			n.setFileType(2);
		} else if (item.getTpms().equals("外机条码图像")){
			n.setFileType(5);
		} else if (item.getTpms().equals("内机条码")){
			n.setFileType(1);
		} else if (item.getTpms().equals("外机条码")){
			n.setFileType(3);
		} else if (item.getTpms().equals("外机条码")){
			n.setFileType(3);
		} else if (item.getTpms().equals("故障位置图片")){
			n.setFileType(20);
		} else if (item.getTpms().equals("压力检测图片")){
			n.setFileType(21);
		} else if (item.getTpms().equals("旧压缩机条码")){
			n.setFileType(26);
		} else if (item.getTpms().equals("新压缩机条码")){
			n.setFileType(27);
		} else if (item.getTpms().equals("噪音视频")){
			n.setFileType(28);
		} else if (item.getTpms().equals("其他压力检测图片")){
			n.setFileType(21);
		} else if (item.getTpms().equals("其他故障位置图片")){
			n.setFileType(20);
		} else if (item.getTpms().equals("其他噪音视频")){
			n.setFileType(29);
		} else if (item.getTpms().equals("其他")){
			n.setFileType(12);
		}

		if (item.getCreatedDate()!=null){
			n.setCreateTime(item.getCreatedDate());
		}
		n.setCreateBy(item.getCreatedBy());
		n.setUpdateBy(item.getLastModifiedBy());
		if (item.getLastModifiedDate()!=null){
			n.setUpdateTime(item.getLastModifiedDate());
		}
		n.setOutPicture(item.getWjlj());
		n.setNumber(item.getRepairtroubleno());
		n.setRepairItemId(item.getRepairitemno());


		ordrs.add(n);
	}

	private void getOrderRepairDetailItem(List<OrderRepairDetailItem> ordrs, Map<String, List<OrderRepairDetail>> irdsMap, ItfTblWxjsWxxmJyktDownload item) {
		OrderRepairDetailItem n = new OrderRepairDetailItem();
		n.setId(IdWorker.getIdStr());
		n.setOrderRepairDetailId(irdsMap.get(item.getWxjsguid()).get(0).getId());

		n.setWxjsguid(item.getWxxmguid());
		n.setRepairItemNo(item.getWxxmh());
		n.setRemark(item.getMshu());
		n.setAmount(item.getWxfy());
		n.setXxyyguid(item.getXxyyh());
		if (item.getCreatedDate()!=null){
			n.setCreateTime(item.getCreatedDate());
		}
		n.setCreateBy(item.getCreatedBy());
		n.setUpdateBy(item.getLastModifiedBy());
		if (item.getLastModifiedDate()!=null){
			n.setUpdateTime(item.getLastModifiedDate());
		}
		ordrs.add(n);
	}

	private void getOrderRepairDetailReason(List<OrderRepairDetailReason> ordrs, Map<String, List<OrderRepairDetail>> irdsMap,
											ItfTblWxjsXxyyJyktDownload item, List<OrderRepairDetail> irds) {
		OrderRepairDetailReason n = new OrderRepairDetailReason();
		n.setId(IdWorker.getIdStr());
		n.setOrderRepairDetailId(irdsMap.get(item.getWxjsguid()).get(0).getId());
		n.setOrderBaseId(irds.get(0).getOrderBaseId());
		n.setXxyyguid(item.getXxyyguid());
		n.setWxjsguid(item.getWxjsguid());
		n.setRepairBugId("");
		n.setRepairBugParentId("");
		RepairBugApp rba = repairBugAppService.lambdaQuery()
				.eq(RepairBugApp::getBugObjCode, item.getXxyyh())
				.last("limit 1").one();
		if (rba !=null){
			n.setRepairBugId(rba.getBugId());
			n.setRepairBugParentId(rba.getParentId());
		}
		n.setNumber(item.getXxyyh());
		n.setName(item.getXxyyhmc());
		n.setSortNum(item.getGzpx());
		n.setRemark(item.getMshu());


		if (item.getCreatedDate()!=null){
			n.setCreateTime(item.getCreatedDate());
		}
		n.setCreateBy(item.getCreatedBy());
		n.setUpdateBy(item.getLastModifiedBy());
		if (item.getLastModifiedDate()!=null){
			n.setUpdateTime(item.getLastModifiedDate());
		}
		ordrs.add(n);
	}

	// 维修工单这里放的为pgid
	public void processWxjsJykt(String downloadTaskNo, String pgguid) {
		List<OrderRepairDetail> ords = new ArrayList<>();
		List<ItfGreeToFaDownloadTaskList> its = new ArrayList<>();
		List<String> wxjsguid = new ArrayList<>();

		// 提取维修结算表下载记录
		List<ItfTblWxjsJyktDownload> jykts = itfTblWxjsJyktDownloadService.lambdaQuery()
				.eq(ItfTblWxjsJyktDownload::getDownloadTaskNo, downloadTaskNo)
				.eq(ItfTblWxjsJyktDownload::getSynStatus,0).list();

		if (!CollectionUtils.isEmpty(jykts)){
			// 提取工单数据
			OrderBase order = orderBaseService.lambdaQuery()
					.eq(OrderBase::getPgid,pgguid)
					.last("limit 1").one();
			if (order!=null){
				// 提取产品信息，可能不存在
				OrderProduct op = orderProductService.lambdaQuery()
						.eq(OrderProduct::getOrderBaseId,order.getId())
						.eq(OrderProduct::getPgid,order.getPgid())
						.last("limit 1").one();

				// 提取现有的采集附件数据
				List<OrderRepairDetail> fs = orderRepairDetailService.lambdaQuery()
						.eq(OrderRepairDetail::getOrderBaseId,order.getId()).list();
				if (CollectionUtils.isNotEmpty(fs)){
					fs.stream().forEach(event->{
						wxjsguid.add(event.getBrandWxjsguid());
					});
					fs.clear();
				}


				for (ItfTblWxjsJyktDownload item :jykts){
					// 生成维修数据采集明细表数据+三子表数据信息 暂时忽略更新，无新增
					if (!wxjsguid.contains(item.getWxjsguid())){
						getorderRepairDetail(ords, its, order, op, item);
						wxjsguid.add(item.getWxjsguid());
					}
				}
			}

			if (ords.size()>0) {
				orderRepairDetailService.saveBatch(ords);
				ords.clear();
			}
			if (its.size()>0) {
				itfGreeToFaDownloadTaskListService.saveBatch(its);
				its.clear();
			}
		}
		// 修改同步状态
		upSynStatusWxJsJykt(downloadTaskNo);
	}

	private void getorderRepairDetail(List<OrderRepairDetail> ords, List<ItfGreeToFaDownloadTaskList> its,
									  OrderBase order, OrderProduct op, ItfTblWxjsJyktDownload item) {
		OrderRepairDetail n = new OrderRepairDetail();
		n.setId(IdWorker.getIdStr());
		n.setOrderBaseId(order.getId());
		WebsitFWS websitFWS = publicService.shshwdToptshwd(item.getAzwdbh(), order);
		n.setWebsitId(websitFWS.getWebsitId());
		n.setWebsitName(websitFWS.getWdmc());
		// 类型:ALL=整机（一体机）,INSIDE=内机,OUT=外机,INSIDE_OUT=一内一外
		if (item.getNwji().equals(1)){
			n.setType("OUT");
		} else if (item.getNwji().equals(2)){
			n.setType("INSIDE");
		} else {
			n.setType("INSIDE_OUT");
		}
		n.setStatus(1);
		n.setInsideCode(item.getNjtm());
		n.setOutCode(item.getJqtm());
		n.setInvoiceNo(item.getFpbh());
		n.setRemark(item.getBeiz());
		n.setNum(1);
		n.setTrouble(item.getGzxx());
		n.setTroubleAnalysis(item.getGzfx());
		n.setInNumber(item.getNjxin());
		n.setInStyle(item.getNjmc());
		n.setOutStyle(item.getWjms());
		n.setOutNumber(item.getWjxin());
		// 省市区
		n.setProvince(order.getProvince());
		n.setCity(order.getCity());
		n.setArea(order.getArea());
		n.setStreet(order.getStreet());
		n.setProductId(order.getProvinceId());
		n.setCityId(order.getCityId());
		n.setAreaId(order.getAreaId());
		n.setStreetId(order.getStreetId());
		n.setLat(order.getLat());
		n.setLng(order.getLng());
		n.setGpsAddress(item.getGpsdzxx());
		if (op !=null){
			n.setRepairProductId(op.getId());
			n.setMainId(op.getMainId());
			n.setMainName(op.getMainName());
			n.setSmallId(op.getSmallId());
			n.setSmallName(op.getSmallName());
			n.setSeriesId(op.getSeriesId());
			n.setSeriesName(op.getSeriesName());
		}
		n.setWorkerId(order.getWorkerId());
		n.setWorkerName(order.getWorkerName());
		// 数据源无结算状态，根据工单系统默认待结果处理
		n.setClearing(Boolean.FALSE);
		n.setWorkerMobile(order.getWorkerMobile());
		n.setSettleBill(item.getJsdh());
		n.setSettleWebsitId(websitFWS.getWebsitId());
		n.setSettleWebsitName(websitFWS.getWdmc());
		if (item.getAzrq()!=null){
			n.setInstallTime(item.getAzrq());
		}
		n.setRepairTypeThree(item.getWxlx3());
		n.setRepairFees(item.getWxfy());
		n.setTrafficExpense(item.getJtfy());
		n.setOtherFees(item.getQtfy());
		n.setTotalFees(item.getZjfy());
		n.setInstallWebsitId(websitFWS.getWebsitId());
		n.setInstallWebsitName(websitFWS.getWdmc());
		n.setRepaireItem(item.getWxnr());
		n.setBrandPgid(order.getPgid());
		n.setBrandWxjsguid(item.getWxjsguid());
		n.setBrandWxgid(String.valueOf(item.getWxgid()));
		n.setBrandStatus(1120);
		n.setBrandLastStatus(1120);
		if (item.getBwgsj()!=null){
			n.setOverTime(item.getBwgsj());
		}
		if (item.getCreatedDate()!=null){
			n.setCreateTime(item.getCreatedDate());
		}
		n.setCreateBy(item.getCreatedBy());
		n.setUpdateBy(item.getLastModifiedBy());
		if (item.getLastModifiedDate()!=null){
			n.setUpdateTime(item.getLastModifiedDate());
		}
		n.setDataSource(1);
		ords.add(n);

		// 增加处理三级从表的下载任务
		ItfGreeToFaDownloadTaskList tl = new ItfGreeToFaDownloadTaskList();
		tl.setDownloadTaskNo(IdWorker.getIdStr());
		tl.setDownloadKeyValue(item.getWxjsguid());
		tl.setDownloadTaskType(660101);
		tl.setDownloadStatus(0);
		its.add(tl);
	}

	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()
				.eq(OrderInstallDetail::getPgwcmxid,pgguid).list();
		oidsMap = oids.stream().collect(Collectors.groupingBy(OrderInstallDetail::getPgwcmxid));

		if (!CollectionUtils.isEmpty(fjs)){
			// 提取工单数据
			OrderBase order = orderBaseService.lambdaQuery()
					.eq(OrderBase::getId,oids.get(0).getOrderBaseId())
					.last("limit 1").one();
			if (order!=null){
				// 提取现有的采集附件数据
				List<OrderDetailFile> fs = orderDetailFileService.lambdaQuery()
						.select(OrderDetailFile::getFjguid,OrderDetailFile::getFileType)
						.eq(OrderDetailFile::getOrderBaseId,order.getId()).list();
				if (CollectionUtils.isNotEmpty(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()
				.eq(OrderInstallDetail::getPgwcmxid,pgguid).list();
		oidsMap = oids.stream().collect(Collectors.groupingBy(OrderInstallDetail::getPgwcmxid));

		if (!CollectionUtils.isEmpty(tms)){
			// 提取工单数据
			OrderBase order = orderBaseService.lambdaQuery()
					.eq(OrderBase::getId,oids.get(0).getOrderBaseId())
					.last("limit 1").one();
			if (order!=null){
				// 生成商用空调采集条码数据
				processCode(addCodes, oidsMap, tmguidS, tms, order);

				// 条码信息也要放附件表中
				processSyktTMFj(downloadTaskNo, pgguid);

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

	private void processCode(List<OrderInstallDetailCode> addCodes, Map<String, List<OrderInstallDetail>> oidsMap, List<String> tmguidS, List<ItfTblAzWgmxSyktTmmxLsDownload> tms, OrderBase order) {
		// 提取现有的条码数据
		List<OrderInstallDetailCode> codes = orderInstallDetailCodeService.lambdaQuery()
				.select(OrderInstallDetailCode::getTmguid,OrderInstallDetailCode::getStatus)
				.eq(OrderInstallDetailCode::getOrderBaseId, order.getId()).list();
		if (CollectionUtils.isNotEmpty(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();
		}
	}

	private void processSyktTMFj(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<ItfTblAzWgmxSyktTmmxLsDownload> tms = itfTblAzWgmxSyktTmmxLsDownloadService.lambdaQuery()
				.eq(ItfTblAzWgmxSyktTmmxLsDownload::getDownloadTaskNo, downloadTaskNo)
				.eq(ItfTblAzWgmxSyktTmmxLsDownload::getSynStatus,0).list();

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

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

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

				// 修改同步状态
				upSynStatusAzSyktFJ(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()
				.eq(OrderInstallDetail::getPgwcmxid,pgguid).list();
		oidsMap = oids.stream().collect(Collectors.groupingBy(OrderInstallDetail::getPgwcmxid));

		if (!CollectionUtils.isEmpty(kts)){
			// 提取工单数据
			OrderBase order = orderBaseService.lambdaQuery()
					.eq(OrderBase::getId,oids.get(0).getOrderBaseId())
					.last("limit 1").one();
			if (order!=null){
				// 提取现有的采集附件数据
				List<OrderDetailFile> fs = orderDetailFileService.lambdaQuery()
						.select(OrderDetailFile::getFjguid,OrderDetailFile::getFileType)
						.eq(OrderDetailFile::getOrderBaseId,order.getId()).list();
				if (CollectionUtils.isNotEmpty(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,
									  String downloadTaskNo,String pgguid) {
		WebsitSH websitSH;
		OrderInstallDetail a = new OrderInstallDetail();

		OrderPar req = new OrderPar();
		req.setSynReqId(item.getSynReqId());
		a= azWgmxJyktDownloadMapper.getAzjyktInfo(req);
		if (a==null){
			detailDownloadService.updateErrorN(downloadTaskNo, "order_base或order_product表无数据pgguid="+pgguid+"");
			return -1;
		}
		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) {

		a.setId(IdWorker.getIdStr());
		a.setFjguid(item.getFjguid());
		a.setOrderBaseId(order.getId());
		a.setOrderDetailId(oid.getId());
		// setFileName
		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());
		// 类型 0：内机条码1：外机条码4：内机其他图片5：默认拿第一张图片为抽真空图，
		// 其他为外机图片7：上墙图8：特殊安装确认图 2：商用信息采集（必填）3：商用信息采集（选填）

		// '附件类型 1=内机条码 2=上墙图片 3=外机条码 4=内机其他 5=外机其他 6=旧机内机整机图片 7=旧机外机整机图片
		// 8=定位确认书 9=室外机固定图 10=冷凝水管软接图 11=外机电源接线图 12=外机出管处封堵图 13=室内机安装图 14=冷凝水管通气孔图

		// 15=室内机走管图 16=抽真空保压图片 17=电子清单 18=安装完成图片 19=验收报告 20=故障位置图 21=其他图片 22=旧配件名牌Logo图片
		// 23=新配件图片 24=新旧配件图片 25=旧配件图片 26=旧压缩机条码 27=新压缩机条码 28=噪音视频 29=其他噪音视频 30=旧配件名牌
		// 31=变更雪种压力图片 32=变更雪种漏点图片 33=水箱环境安装图 34=供电开关(插头、插座)图 35=安全阀图 36=试水视频（视频格式）
		// 37=临时内机条码 38=临时外机条码 39=旧机内机整机图片 40=旧机外机整机图片 41=机器条码 42=整机安装效果图 43=外机位置图,44:特殊环境安装确认书',

		a.setFileType(21);
		if (item.getType()==0){
			a.setFileType(1);
		} else if (item.getType()==1){
			a.setFileType(3);
		} else if (item.getType()==4){
			a.setFileType(4);
		} else if (item.getType()==5){
			a.setFileType(16);
		} else if (item.getType()==7){
			a.setFileType(5);
		} else if (item.getType()==8){
			a.setFileType(44);
		}
		a.setSortNum(item.getFjsequence());
		if (item.getCreatedDate()!=null){
			a.setCreateTime(item.getCreatedDate());
		}

		a.setCreateBy(item.getCreatedBy());
		if (item.getLastModifiedDate()!=null){
			a.setUpdateTime(item.getLastModifiedDate());
		}
		a.setUpdateBy(item.getLastModifiedBy());
		a.setOutPicture(item.getFjserverpath());
		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(21);
		if (item.getType()==0){
			a.setFileType(1);
		} else if (item.getType()==1){
			a.setFileType(3);
		} else if (item.getType()==4){
			a.setFileType(4);
		} else if (item.getType()==5){
			a.setFileType(16);
		} else if (item.getType()==7){
			a.setFileType(5);
		} else if (item.getType()==8){
			a.setFileType(44);
		}

		a.setSortNum(item.getFjsequence());
		a.setCreateTime(item.getCreatedDate());
		a.setCreateBy(item.getCreatedBy());
		a.setUpdateTime(item.getLastModifiedDate());
		a.setUpdateBy(item.getLastModifiedBy());
		a.setOutPicture(item.getFjserverpath());
		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(21);
		if (item.getType()==0){
			a.setFileType(1);
		} else if (item.getType()==1){
			a.setFileType(3);
		} else if (item.getType()==4){
			a.setFileType(4);
		} else if (item.getType()==5){
			a.setFileType(16);
		} else if (item.getType()==7){
			a.setFileType(5);
		} else if (item.getType()==8){
			a.setFileType(44);
		}
		a.setSortNum(item.getFjsequence());
		a.setCreateTime(item.getCreatedDate());
		a.setCreateBy(item.getCreatedBy());
		a.setUpdateTime(item.getLastModifiedDate());
		a.setUpdateBy(item.getLastModifiedBy());
		a.setOutPicture(item.getFjserverpath());
		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());
		a.setOutPicture(item.getScwj());
		odfs.add(a);
	}

	private void getItfTblAzWgmxSyktTMFj(List<OrderDetailFile> odfs,OrderInstallDetail oid,
										 OrderBase order, ItfTblAzWgmxSyktTmmxLsDownload item) {
		OrderDetailFile a = new OrderDetailFile();
		a.setId(IdWorker.getIdStr());
		a.setFjguid(item.getTmguid());
		a.setOrderBaseId(order.getId());
		a.setOrderDetailId(oid.getId());
		a.setFileName("外机条码");
		if (item.getTmlx()==2){
			a.setFileName("内机条码");
		}

		a.setPgwcmxid(item.getPgwcmxid());
		// 服务器存储图片路径
		a.setBrandFilePath(item.getScwj());
		a.setFileType(3);
		if (item.getTmlx()==2){
			a.setFileType(1);
		}

		a.setCreateTime(item.getCreatedDate());
		a.setCreateBy(item.getCreatedBy());
		a.setUpdateTime(item.getLastModifiedDate());
		a.setUpdateBy(item.getLastModifiedBy());
		a.setOutPicture(item.getScwj());
		odfs.add(a);
	}

	private int getOrderInstallDetailS(List<OrderInstallDetail> oids, int count, OrderBase order, ItfTblAzWgmxSyktDownload item,
									   String downloadTaskNo,String pgguid) throws Exception {
		WebsitSH websitSH;
		OrderInstallDetail a = new OrderInstallDetail();
		OrderPar req = new OrderPar();
		req.setSynReqId(item.getSynReqId());
		a= azWgmxSyktDownloadMapper.getAzsyktInfo(req);
		if (a==null){
			detailDownloadService.updateErrorN(downloadTaskNo, "order_base或order_product表无数据pgguid="+pgguid+"");
			return -1;
		}
		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,
									   String downloadTaskNo,String pgguid) {
		WebsitSH websitSH;
		OrderInstallDetail a = new OrderInstallDetail();
		OrderPar req = new OrderPar();
		req.setSynReqId(item.getSynReqId());
		a= azWgmxQityaDownloadMapper.getAzQitaInfo(req);
		if (a==null){
			detailDownloadService.updateErrorN(downloadTaskNo, "order_base或order_product表无数据pgguid="+pgguid+"");
			return -1;
		}
		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 processOrderInstallDetailSBak(String downloadTaskNo, String pgguid) throws Exception {
		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)
					.last("limit 1").one();

			for (ItfTblAzWgmxSyktDownload item :sykts){
				// 生成采集明细数据
				count = getOrderInstallDetailS(oids, count, order, item, downloadTaskNo, pgguid);
				// 增加处理三级从表的下载任务
				getItfGreeToFaDownloadTaskListS(its, item);
			}
			orderInstallDetailService.saveBatch(oids);
			oids.clear();
			itfGreeToFaDownloadTaskListService.saveBatch(its);
			its.clear();
		}

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


	public void processOrderInstallDetailS(String downloadTaskNo, String pgguid) throws Exception {
		List<OrderInstallDetail> oids = new ArrayList<>();
		List<ItfGreeToFaDownloadTaskList> its = new ArrayList<>();
		List<String> ids = 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)
					.last("limit 1").one();

			// outCjDownloadFlag = 1 代表需要从总部下载
			if ((order !=null && order.getOutCjDownloadFlag().equals(1)) || (order ==null)) {
				List<OrderInstallDetail> orderDetailRec = orderInstallDetailService.lambdaQuery()
						.eq(OrderInstallDetail::getOrderBaseId, order.getId())
						.eq(OrderInstallDetail::getStatus, 1).list();
				if (CollectionUtils.isNotEmpty(orderDetailRec)){
					// 存在已采集的数据忽略下载
				} else {
					// 清除本地的待采集数据
					List<OrderInstallDetail> delorderDetailRec = orderInstallDetailService.lambdaQuery()
							.eq(OrderInstallDetail::getOrderBaseId, order.getId())
							.eq(OrderInstallDetail::getStatus,0).list();
					if (CollectionUtils.isNotEmpty(delorderDetailRec)){
						delorderDetailRec.stream().forEach(ddr -> {
							ids.add(ddr.getId());
						});
						orderInstallDetailService.removeByIds(ids);
					}

					for (ItfTblAzWgmxSyktDownload item :sykts){
						// 生成采集明细数据
						count = getOrderInstallDetailS(oids, count, order, item, downloadTaskNo, pgguid);
						// 增加处理三级从表的下载任务
						getItfGreeToFaDownloadTaskListS(its, item);
					}
					orderInstallDetailService.saveBatch(oids);
					oids.clear();
					itfGreeToFaDownloadTaskListService.saveBatch(its);
					its.clear();
				}
			}
		}

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

	public void processOrderInstallDetailOBak(String downloadTaskNo, String pgguid) {
		List<OrderInstallDetail> oids = new ArrayList<>();
		List<ItfGreeToFaDownloadTaskList> its = new ArrayList<>();
		List<OrderInstallDetailCode> oidcs = 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)
					.last("limit 1").one();

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

				// 增加处理三级从表的下载任务
				getItfGreeToFaDownloadTaskListO(its, item);
			}

			// 生成采集条码数据
			getOrderInstallDetailOtherCode(oids, oidcs, order);

			if (oidcs.size()>0){
				orderInstallDetailCodeService.saveBatch(oidcs);
				oidcs.clear();
			}
			/*if (oids.size()>0){
				orderInstallDetailService.saveBatch(oids);
				oids.clear();
			}
			if (its.size()>0){
				itfGreeToFaDownloadTaskListService.saveBatch(its);
				its.clear();
			}*/
		}

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

	public void processOrderInstallDetailO(String downloadTaskNo, String pgguid) {
		List<OrderInstallDetail> oids = new ArrayList<>();
		List<ItfGreeToFaDownloadTaskList> its = new ArrayList<>();
		List<OrderInstallDetailCode> oidcs = new ArrayList<>();
		List<String> ids = 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)
					.last("limit 1").one();

			// outCjDownloadFlag = 1 代表需要从总部下载
			if ((order !=null && order.getOutCjDownloadFlag().equals(1)) || (order ==null)) {
				List<OrderInstallDetail> orderDetailRec = orderInstallDetailService.lambdaQuery()
						.eq(OrderInstallDetail::getOrderBaseId, order.getId())
						.eq(OrderInstallDetail::getStatus, 1).list();
				if (CollectionUtils.isNotEmpty(orderDetailRec)){
					// 存在已采集的数据忽略下载
				} else {
					// 清除本地的待采集数据
					List<OrderInstallDetail> delorderDetailRec = orderInstallDetailService.lambdaQuery()
							.eq(OrderInstallDetail::getOrderBaseId, order.getId())
							.eq(OrderInstallDetail::getStatus,0).list();
					if (CollectionUtils.isNotEmpty(delorderDetailRec)){
						delorderDetailRec.stream().forEach(ddr -> {
							ids.add(ddr.getId());
						});
						orderInstallDetailService.removeByIds(ids);
					}

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

						// 增加处理三级从表的下载任务
						getItfGreeToFaDownloadTaskListO(its, item);
					}

					// 生成采集条码数据
					getOrderInstallDetailOtherCode(oids, oidcs, order);

					if (oidcs.size()>0){
						orderInstallDetailCodeService.saveBatch(oidcs);
						oidcs.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())
						.last("limit 1").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)
					.last("limit 1").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())
						.last("limit 1").one();

				// 工单ID
				OrderBase orderBase = orderBaseService.lambdaQuery()
						.eq(OrderBase::getPgguid, pgguid)
						.last("limit 1").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 upSynStatusWxJsJykt(String downloadTaskNo) {
		OrderPar req = new OrderPar();
		req.setOrderNo(downloadTaskNo);

		ItfTblWxjsJyktDownload up = new ItfTblWxjsJyktDownload();
		up.setSynStatus(1);
		QueryWrapper upWrapper = new QueryWrapper<ItfTblWxjsJyktDownload>()
				.eq("download_task_no", downloadTaskNo)
				.eq("syn_status",0);
		itfTblWxjsJyktDownloadService.update(up,upWrapper);

		installDownloadTaskListMapper.updateSynStatus(req);
	}

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

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

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

	public void upSynStatusWxjsPjmxJykt(String downloadTaskNo) {
		ItfTblWxjsPjmxJyktDownload up = new ItfTblWxjsPjmxJyktDownload();
		up.setSynStatus(99);
		QueryWrapper upWrapper = new QueryWrapper<ItfTblWxjsPjmxJyktDownload>()
				.eq("download_task_no", downloadTaskNo)
				.eq("syn_status",0);
		itfTblWxjsPjmxJyktDownloadService.update(up,upWrapper);
	}

	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 });
	}

	@Override
	public void updateErrorN(String downloadTaskNo, String errMessage) {
		jdbcTemplate.update(
				"UPDATE itf_gree_to_fa_download_task_list set download_err_msg=?,download_status=99 where download_task_no=?",
				new Object[] { errMessage, downloadTaskNo });
	}

}
