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

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zfire.jiasm.syncdata.base.BaseService;
import com.zfire.jiasm.syncdata.constant.DictTypeEnum;
import com.zfire.jiasm.syncdata.gree.GreeLogic;
import com.zfire.jiasm.syncdata.helper.GreeResponseHelperOther;
import com.zfire.jiasm.syncdata.http.HttpUtil;
import com.zfire.jiasm.syncdata.plus.entity.*;
import com.zfire.jiasm.syncdata.plus.service.*;
import com.zfire.jiasm.syncdata.pojo.bo.*;
import com.zfire.jiasm.syncdata.service.OtherDownService;
import com.zfire.jiasm.syncdata.utils.MyBeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@Slf4j
@Service
public class OtherDownServiceImpl implements OtherDownService {
    @Value("${clientid}")
    private String clientid;
    @Value("${otherurl}")
    private String otherurlbase;

    private String url ="/autoapp-default-server-invoice/api/ext/specialInstallExt/specialInstallApplyUpdate";
    private String addurl =  "/autoapp-default-server-invoice/api/ext/specialInstallExt/addSingleItemForspExt";
    private String settlementUrl = "/autoapp-default-server-greerepairaccounts/api/repairsettlement/getSettlementStatusV2";
    private String feedbackUrl =  "/autoapp-default-server-greeshmasterdata/api/ext/qualityFeedback/addAndSubmit";
    private String repairSettlement = "/autoapp-default-server-greerepairaccounts/api/repairsettlement/gzBatchSettlementV2";
    private String installSettlement = "/autoapp-default-server-installaccounts/api/ext/azwgmx/launchSettlementV2";
    private String installQuerySettlement = "/autoapp-default-server-installaccounts/api/ext/azwgmx/searchWgmxEndStatusV2";
    private String refundsAdd = "/autoapp-default-server-greeshreturngoods/api/zbthh/ext/submit";
    private String refundsUpdate = "/autoapp-default-server-greeshreturngoods/api/zbthh/ext/update";
    private String refundsFeedback = "/autoapp-default-server-greeshreturngoods/api/zbthh/ext/update";
    private String acquisitionAdd = "/autoapp-default-server-guangzhou/api/acquisition/ext/domestic";
    private String solidAcquisitionAdd = "/autoapp-default-server-guangzhou/api/acquisition/ext/domestic/brokenMachine";





    @Resource
    GreeLogic greeLogic;
    @Resource
    QualityFeedbackHeadDownloadService qualityFeedbackHeadDownloadService;
    @Resource
    TableDataQueryTimeService tableDataQueryTimeService;
    @Resource
    BaseService baseService;
    @Resource
    SysDictRefService sysDictRefService;
    @Resource
    NotificationDownloadService notificationDownloadService;
    @Resource
    TblAzwgmxKqazDownloadService tblAzwgmxKqazDownloadService;
    @Resource
    TblAzwgmxKjmmDownloadService tblAzwgmxKjmmDownloadService;
    @Resource
    TblAzwgmxKqcjsjDownloadService tblAzwgmxKqcjsjDownloadService;
    @Resource
    TblAzwgmxUploadService tblAzwgmxUploadService;
    @Resource
    TblAddUploadListService tblAddUploadListService;
    @Resource
    SyncQuerySettlementStatusService syncQuerySettlementStatusService;
    @Resource
    RepairSettlementStatusDownloadService repairSettlementStatusDownloadService;
    @Resource
    InstallSettlementDownloadService installSettlementDownloadService;
    @Resource
    InstallSettlementStatusDownloadService installSettlementStatusDownloadService;
    @Resource
    RepairSettlementDownloadService repairSettlementDownloadService;
    @Resource
    TblRefundsDownloadService tblRefundsDownloadService;
    @Resource
    TblThhDcjsLcUploadService tblThhDcjsLcUploadService;
    @Resource
    TblThhDcjsFjUploadService tblThhDcjsFjUploadService;
    @Resource
    TblazwgmxjyktUploadService tblazwgmxjyktUploadService;
    @Resource
    TblAzWgmxOtherUploadService tblAzWgmxOtherUploadService;
    @Resource
    TblAzWgmxJyktFjUploadService tblAzWgmxJyktFjUploadService;
    @Resource
    TblAzWgmxJyktSpecialUploadService tblAzWgmxJyktSpecialUploadService;
    @Resource
    JdMessageDownloadService jdMessageDownloadService;
    @Resource
    GreeMessageDownloadService greeMessageDownloadService;
    @Resource
    GreeShortMessageReplyDownloadService greeShortMessageReplyDownloadService;
    @Resource
    AccessoriesQueryDownloadService accessoriesQueryDownloadService;


    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");



    @Override
    public void dealWithTableDataQueryTime(TableDataQueryTime item) throws Exception{
        int page=0;
        int size=100;
        int total=0;
        int oldtotal=0;
        List<QualityFeedbackHeadDownload> ads = new ArrayList<>();
        Date synTime = new Date();

        do {
            // 已同步记录数
            oldtotal = oldtotal + size;
            // 总记录数
            total = getData(page,size, ads, item);
            if (total<=0){
                break;
            }
            // 获取到数据
            if (ads.size()>0){
                qualityFeedbackHeadDownloadService.saveOrUpdateBatch(ads);
                ads.clear();
                // 所剩记录数
                total = total - oldtotal;
                if (total<0){
                    total = 0;
                }
                page = page +1;
                if (total>100){
                    size =100;
                } else {
                    size=total;
                }
            } else {
                // 未获取到结束
                total = 0;
            }
        } while (total>0);
        synSuccessTableDataQueryTime(item, total, synTime);
    }

    @Override
    public void notificationQueryDown(TableDataQueryTime item) throws Exception {
        int page=0;
        int size=100;
        int total=0;
        int oldtotal=0;
        List<NotificationDownload> ads = new ArrayList<>();
        Date synTime = new Date();
        Brand brand = baseService.getBrand();

        // 提取商品大类
        List<SysDictRef> sysDictRef =  sysDictRefService.lambdaQuery()
                .select(SysDictRef::getRefDictCode)
                .eq(SysDictRef::getBrandId, brand.getBrandId())
                .eq(SysDictRef::getDictType, DictTypeEnum.DICT_TYPE_MAIN_TYPE.getCode())
                .list();

        for (SysDictRef spid :sysDictRef){
            page=0;
            size=100;
            total=0;
            oldtotal=0;

            do {
                // 已同步记录数
                oldtotal = oldtotal + size;
                // 总记录数
                total = getData(page,size, ads, item, spid.getRefDictCode());
                if (total<=0){
                    break;
                }
                // 获取到数据
                if (ads.size()>0){
                    notificationDownloadService.saveOrUpdateBatch(ads);
                    ads.clear();
                    // 所剩记录数
                    total = total - oldtotal;
                    if (total<0){
                        total = 0;
                    }
                    page = page +1;
                    if (total>100){
                        size =100;
                    } else {
                        size=total;
                    }
                } else {
                    // 未获取到结束
                    total = 0;
                }
            } while (total>0);
        }
        synSuccessTableDataQueryTime(item, total, synTime);
    }

    @Override
    public void detailRefunds(TableDataQueryTime item) throws Exception {
        int page=0;
        int size=100;
        int total=0;
        int oldtotal=0;
        List<TblRefundsDownload> ads = new ArrayList<>();
        Date synTime = new Date();

        do {
            // 已同步记录数
            oldtotal = oldtotal + size;
            // 总记录数
            total = getRefundsData(page,size, item, ads);
            if (total<=0){
                break;
            }
            // 获取到数据
            if (ads.size()>0){
                tblRefundsDownloadService.saveOrUpdateBatch(ads);
                ads.clear();
                // 所剩记录数
                total = total - oldtotal;
                if (total<0){
                    total = 0;
                }
                page = page +1;
                if (total>100){
                    size =100;
                } else {
                    size=total;
                }
            } else {
                // 未获取到结束
                total = 0;
            }
        } while (total>0);
        synSuccessTableDataQueryTime(item, total, synTime);
    }

    @Override
    public void detailMessage(TableDataQueryTime item) throws Exception {
        List<GreeMessageDownload> ads = new ArrayList<>();
        List<GreeShortMessageReplyDownload> shorts = new ArrayList<>();
        getMessageData(item, ads,shorts);
        // 获取到数据
        if (ads.size()>0) {
            greeMessageDownloadService.saveOrUpdateBatch(ads);
            ads.clear();
        }
        if (shorts.size()>0) {
            greeShortMessageReplyDownloadService.saveOrUpdateBatch(shorts);
            shorts.clear();
        }
        synSuccessTableDataQueryTimeT(item);
    }

    @Override
    public void detailJD(TableDataQueryTime item) throws Exception {
        int page=0;
        int size=100;
        int total=0;
        int oldtotal=0;
        List<JdMessageDownload> ads = new ArrayList<>();
        Date synTime = new Date();

        do {
            // 已同步记录数
            oldtotal = oldtotal + size;
            // 总记录数
            total = getJdData(page,size, item, ads);
            if (total<=0){
                break;
            }
            // 获取到数据
            if (ads.size()>0){
                jdMessageDownloadService.saveOrUpdateBatch(ads);
                ads.clear();
                // 所剩记录数
                total = total - oldtotal;
                if (total<0){
                    total = 0;
                }
                page = page +1;
                if (total>100){
                    size =100;
                } else {
                    size=total;
                }
            } else {
                // 未获取到结束
                total = 0;
            }
        } while (total>0);
        synSuccessTableDataQueryTime(item, total, synTime);
    }

    @Override
    public void accessories(TableDataQueryTime item) throws Exception {
        int page=0;
        int size=100;
        int total=0;
        int oldtotal=0;
        List<AccessoriesQueryDownload> ads = new ArrayList<>();
        Date synTime = new Date();

        do {
            // 已同步记录数
            oldtotal = oldtotal + size;
            // 总记录数
            total = getAccessoriesData(page,size, item, ads);
            if (total<=0){
                break;
            }
            // 获取到数据
            if (ads.size()>0){
                accessoriesQueryDownloadService.saveOrUpdateBatch(ads);
                ads.clear();
                // 所剩记录数
                total = total - oldtotal;
                if (total<0){
                    total = 0;
                }
                page = page +1;
                if (total>100){
                    size =100;
                } else {
                    size=total;
                }
            } else {
                // 未获取到结束
                total = 0;
            }
        } while (total>0);
        synSuccessTableDataQueryTime(item, total, synTime);
    }

    @Override
    public void specialInstallQueryDown(TableDataQueryTime item) throws Exception {
        int page=0;
        int size=100;
        int total=0;
        int oldtotal=0;
        List<TblAzwgmxKqazDownload> ads = new ArrayList<>();
        Date synTime = new Date();

        do {
            // 已同步记录数
            oldtotal = oldtotal + size;
            // 总记录数
            total = getData(page,size, item, ads, "kqaz");
            if (total<=0){
                break;
            }
            // 获取到数据
            if (ads.size()>0){
                tblAzwgmxKqazDownloadService.saveOrUpdateBatch(ads);
                ads.clear();
                // 所剩记录数
                total = total - oldtotal;
                if (total<0){
                    total = 0;
                }
                page = page +1;
                if (total>100){
                    size =100;
                } else {
                    size=total;
                }
            } else {
                // 未获取到结束
                total = 0;
            }
        } while (total>0);
        synSuccessTableDataQueryTime(item, total, synTime);
    }

    @Override
    public void tblAzwgmxKjmmQueryDown(TableDataQueryTime item) throws Exception {
        int page=0;
        int size=100;
        int total=0;
        int oldtotal=0;
        List<TblAzwgmxKjmmDownload> ads = new ArrayList<>();
        Date synTime = new Date();

        do {
            // 已同步记录数
            oldtotal = oldtotal + size;
            // 总记录数
            total = getDataKjmm(page,size, item, ads,"kjmm");
            if (total<=0){
                break;
            }
            // 获取到数据
            if (ads.size()>0){
                tblAzwgmxKjmmDownloadService.saveOrUpdateBatch(ads);
                ads.clear();
                // 所剩记录数
                total = total - oldtotal;
                if (total<0){
                    total = 0;
                }
                page = page +1;
                if (total>100){
                    size =100;
                } else {
                    size=total;
                }
            } else {
                // 未获取到结束
                total = 0;
            }
        } while (total>0);
        synSuccessTableDataQueryTime(item, total, synTime);
    }

    @Override
    public void tblAzwgmxKqcjsjQueryDown(TableDataQueryTime item) throws Exception {
        int page=0;
        int size=100;
        int total=0;
        int oldtotal=0;
        List<TblAzwgmxKqcjsjDownload> ads = new ArrayList<>();
        Date synTime = new Date();

        do {
            // 已同步记录数
            oldtotal = oldtotal + size;
            // 总记录数
            total = getDataCjsj(page,size, ads, item,"cjsj");
            if (total<=0){
                break;
            }
            // 获取到数据
            if (ads.size()>0){
                tblAzwgmxKqcjsjDownloadService.saveOrUpdateBatch(ads);
                ads.clear();
                // 所剩记录数
                total = total - oldtotal;
                if (total<0){
                    total = 0;
                }
                page = page +1;
                if (total>100){
                    size =100;
                } else {
                    size=total;
                }
            } else {
                // 未获取到结束
                total = 0;
            }
        } while (total>0);
        synSuccessTableDataQueryTime(item, total, synTime);
    }

    @Override
    public void uploadDatakqaz(TblAzwgmxUpload item) throws Exception {
        TblAzwgmxKqazDownload kqaz = tblAzwgmxKqazDownloadService.lambdaQuery()
                .eq(TblAzwgmxKqazDownload::getPgwcmxid, item.getKeyId())
                .last("limit 1")
                .one();
        if (kqaz !=null ){
            // 同步更新
            if (getDatakqaz(kqaz,"kqaz", item.getId())==0){
                successTblAzwgmxUpload(item);
            }
        }
    }

    @Override
    public void uploadDatacjsj(TblAzwgmxUpload item) throws Exception {
        TblAzwgmxKqcjsjDownload cjsj = tblAzwgmxKqcjsjDownloadService.lambdaQuery()
                .eq(TblAzwgmxKqcjsjDownload::getPgwcmxid, item.getKeyId())
                .last("limit 1")
                .one();
        if (cjsj !=null ){
            // 同步更新
            if (getDatacjsj(cjsj,"cjsj", item.getId())==0){
                successTblAzwgmxUpload(item);
            }
        }
    }

    @Override
    public void uploadDataKjmm(TblAzwgmxUpload item) throws Exception {
        TblAzwgmxKjmmDownload kjmm = tblAzwgmxKjmmDownloadService.lambdaQuery()
                .eq(TblAzwgmxKjmmDownload::getPgwcmxid, item.getKeyId())
                .last("limit 1")
                .one();
        if (kjmm !=null ){
            // 同步更新
            if (getDataKjmm(kjmm,"kjmm", item.getId())==0){
                successTblAzwgmxUpload(item);
            }
        }
    }

    @Override
    public void addCjsj(TblAddUploadList item) throws Exception {
        TblAzwgmxKqcjsjDownload cjsj = tblAzwgmxKqcjsjDownloadService.lambdaQuery()
                .eq(TblAzwgmxKqcjsjDownload::getPgwcmxid, item.getKeyId())
                .last("limit 1")
                .one();
        if (cjsj != null) {
            // 同步更新
            if (addDatacjsj(cjsj, "cjsj", item.getId()) == 0) {
                successTblAzwgmxAdd(item);
            }
        }
    }

    @Override
    public void addKjmm(TblAddUploadList item) throws Exception {
        TblAzwgmxKjmmDownload kjmm = tblAzwgmxKjmmDownloadService.lambdaQuery()
                .eq(TblAzwgmxKjmmDownload::getPgwcmxid, item.getKeyId())
                .last("limit 1")
                .one();
        if (kjmm != null) {
            // 同步更新
            if (addDataKjmm(kjmm, "kjmm", item.getId()) == 0) {
                successTblAzwgmxAdd(item);
            }
        }
    }

    @Override
    public void addFeedBack(TblAddUploadList item) throws Exception{
        QualityFeedbackHeadDownload feedback = qualityFeedbackHeadDownloadService.lambdaQuery()
                .eq(QualityFeedbackHeadDownload::getId, item.getKeyId())
                .last("limit 1")
                .one();
        if (feedback != null) {
            // 同步更新
            if (addDataFeedBack(feedback, item.getId()) == 0) {
                successTblAzwgmxAdd(item);
            }
        }
    }



    @Override
    public void addKqaz(TblAddUploadList item) throws Exception {
        TblAzwgmxKqazDownload kqaz = tblAzwgmxKqazDownloadService.lambdaQuery()
                .eq(TblAzwgmxKqazDownload::getPgwcmxid, item.getKeyId())
                .last("limit 1")
                .one();
        if (kqaz != null) {
            // 同步更新
            if (addDatakqaz(kqaz, "kqaz", item.getId()) == 0) {
                successTblAzwgmxAdd(item);
            }
        }
    }

    @Override
    public void addRefunds(TblAddUploadList item) throws Exception {
        TblRefundsDownload kqaz = tblRefundsDownloadService.lambdaQuery()
                .eq(TblRefundsDownload::getPgguid, item.getKeyId())
                .last("limit 1")
                .one();
        if (kqaz != null) {
            // 同步新增
            if (addDataRfunds(kqaz, item.getId()) == 0) {
                successTblAzwgmxAdd(item);
            }
        }
    }

    @Override
    public void addAcquisition(TblAddUploadList item) throws Exception {
        // 组装参数
        AcquisitionBO request = getreq(item);
        // 同步新增
        if (addAcquisitionUpload(request,item.getId()) == 0) {
            successTblAzwgmxAdd(item);
        }
    }

    @Override
    public void addSolidAcquisition(TblAddUploadList item) throws Exception {
        // 组装参数
        SolidAcquisitionBO request = getSolidReq(item);
        // 同步新增
        if (addSolidAcquisitionUpload(request,item.getId()) == 0) {
            successTblAzwgmxAdd(item);
        }
    }

    @NotNull
    private AcquisitionBO getreq(TblAddUploadList item) {
        AcquisitionBO request = new AcquisitionBO();
        JyktAzWgmxSjcjExt extDto = new JyktAzWgmxSjcjExt();
        Tblazwgmxjykt jykt = new Tblazwgmxjykt();
        List<TblAzWgmxOtherinfo> oi = new ArrayList<>();
        List<TblAzWgmxJyktFj> fj = new ArrayList<>();
        List<TblAzWgmxJyktSpecial> special = new ArrayList<>();

        // 测试随便填写的
        request.setWdno("123");
        request.setWdnm("123");
        request.setXtwdbh("231");
        request.setWxgid("123");
        request.setWxgmc("12432");
        request.setCjwdno("123");
        request.setShji("13711477891");

        // 退换货家用采集上传记录
        getjykt(item, jykt);

        // 退换货-其他安装信息
        getois(item, oi);

        // 退换货-家用空调数据采集附件上传记录
        getfjs(item, fj);

        // 退换货-家用特殊要求采集信息表
        getspecial(item, special);

        extDto.setTblazwgmxjykt(jykt);
        extDto.setTblAzWgmxOtherinfo(oi);
        extDto.setTblAzWgmxJyktFj(fj);
        extDto.setTblAzWgmxJyktSpecial(special);
        request.setJyktAzWgmxSjcjExtDto(extDto);
        return request;
    }

    private void getspecial(TblAddUploadList item, List<TblAzWgmxJyktSpecial> special) {
        List<TblAzWgmxJyktSpecialUpload> sp = tblAzWgmxJyktSpecialUploadService.lambdaQuery()
                .eq(TblAzWgmxJyktSpecialUpload::getWorkerOrderNo, item.getKeyId()).list();
        if (sp.size()>0){
            for (TblAzWgmxJyktSpecialUpload o: sp){
                TblAzWgmxJyktSpecial u = new TblAzWgmxJyktSpecial();
                MyBeanUtils.copyProperties(o,u);
                special.add(u);
            }
        }
    }

    private void getfjs(TblAddUploadList item, List<TblAzWgmxJyktFj> fj) {
        List<TblAzWgmxJyktFjUpload> fjs = tblAzWgmxJyktFjUploadService.lambdaQuery()
                .eq(TblAzWgmxJyktFjUpload::getWorkerOrderNo, item.getKeyId()).list();
        if (fjs.size()>0){
            for (TblAzWgmxJyktFjUpload o: fjs){
                TblAzWgmxJyktFj u = new TblAzWgmxJyktFj();
                MyBeanUtils.copyProperties(o,u);
                u.setReatetime(sdf.format(o.getReatetime()));
                fj.add(u);
            }
        }
    }

    private void getois(TblAddUploadList item, List<TblAzWgmxOtherinfo> oi) {
        List<TblAzWgmxOtherUpload> otherinfo = tblAzWgmxOtherUploadService.lambdaQuery()
                .eq(TblAzWgmxOtherUpload::getWorkerOrderNo, item.getKeyId()).list();
        if (otherinfo.size()>0){
            for (TblAzWgmxOtherUpload o: otherinfo){
                TblAzWgmxOtherinfo u = new TblAzWgmxOtherinfo();
                MyBeanUtils.copyProperties(o,u);
                oi.add(u);
            }
        }
    }

    private void getjykt(TblAddUploadList item, Tblazwgmxjykt jykt) {
        TblazwgmxjyktUpload jt = tblazwgmxjyktUploadService.lambdaQuery()
                .eq(TblazwgmxjyktUpload::getWorkerOrderNo, item.getKeyId())
                .last("limit 1")
                .one();
        if (jt !=null){
            MyBeanUtils.copyProperties(jt, jykt);

            if (jt.getGmsj()!=null) {
                jykt.setGmsj(sdf.format(jt.getGmsj()));
            }
            if (jt.getCjdt()!=null) {
                jykt.setCjdt(sdf.format(jt.getCjdt()));
            }
            if (jt.getCzsj() !=null ){
                jykt.setCzsj(sdf.format(jt.getCzsj()));
            }
            if (jt.getDqjdsj() !=null ){
                jykt.setDqjdsj(sdf.format(jt.getDqjdsj()));
            }
            if (jt.getZjssj() !=null ){
                jykt.setZjssj(sdf.format(jt.getZjssj()));
            }
            if (jt.getScazsj() !=null ){
                jykt.setScazsj(sdf.format(jt.getScazsj()));
            }
            if (jt.getSjcjsj() !=null ){
                jykt.setSjcjsj(sdf.format(jt.getSjcjsj()));
            }
            if (jt.getZjczsj() !=null ){
                jykt.setZjczsj(sdf.format(jt.getZjczsj()));
            }
            if (jt.getWcsj() !=null ){
                jykt.setWcsj(sdf.format(jt.getWcsj()));
            }
        }
    }


    @NotNull
    private SolidAcquisitionBO getSolidReq(TblAddUploadList item) {
        SolidAcquisitionBO request = new SolidAcquisitionBO();
        List<TblThhDcjsLcDtoList> lc = new ArrayList<>();
        List<TblThhDcjsFjDtoList> fj = new ArrayList<>();

        request.setWdno("123");
        request.setWdnm("123");
        request.setXtwdbh("231");
        request.setWxgid("123");
        request.setWxgmc("12432");
        request.setCjwdno("123");
        request.setShji("13711477891");

        List<TblThhDcjsLcUpload> slc = tblThhDcjsLcUploadService.lambdaQuery()
                .eq(TblThhDcjsLcUpload::getWorkerOrderNo, item.getKeyId()).list();
        if (slc.size()>0){
            for (TblThhDcjsLcUpload i: slc){
                TblThhDcjsLcDtoList n = new TblThhDcjsLcDtoList();
                MyBeanUtils.copyProperties(i,n);
                if (i.getCjsj()!=null){
                    n.setCjsj(sdf.format(i.getCjsj()));
                }
                lc.add(n);
            }
        }

        List<TblThhDcjsFjUpload> sfj = tblThhDcjsFjUploadService.lambdaQuery()
                .eq(TblThhDcjsFjUpload::getWorkerOrderNo, item.getKeyId()).list();
        if (sfj.size()>0){
            for (TblThhDcjsFjUpload i: sfj){
                TblThhDcjsFjDtoList n = new TblThhDcjsFjDtoList();
                MyBeanUtils.copyProperties(i,n);
                if (i.getReatetime()!=null){
                    n.setReatetime(sdf.format(i.getReatetime()));
                }
                fj.add(n);
            }
        }

        request.setTblThhDcjsLcDtoList(lc);
        request.setTblThhDcjsFjDtoList(fj);
        return request;
    }

    private int addAcquisitionUpload(AcquisitionBO request,Long id) throws Exception {
        log.info("request: {}", JSONObject.toJSONString(request));
        GreeResponseHelperOther response = greeLogic.greePostOther(otherurlbase + acquisitionAdd, JSONObject.toJSONString(request));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            return 0;
        }
        errorTblAzwgmxAdd(id, response);
        return -1;
    }

    private int addSolidAcquisitionUpload(SolidAcquisitionBO request,Long id) throws Exception {
        log.info("request: {}", JSONObject.toJSONString(request));
        GreeResponseHelperOther response = greeLogic.greePostOther(otherurlbase + solidAcquisitionAdd, JSONObject.toJSONString(request));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            return 0;
        }
        errorTblAzwgmxAdd(id, response);
        return -1;
    }

    @Override
    public void updateRefunds(TblAddUploadList item) throws Exception {
        TblRefundsDownload kqaz = tblRefundsDownloadService.lambdaQuery()
                .eq(TblRefundsDownload::getPgguid, item.getKeyId())
                .last("limit 1")
                .one();
        if (kqaz != null) {
            // 同步更新
            if (updateDataRfunds(kqaz, item.getId()) == 0) {
                successTblAzwgmxAdd(item);
            }
        }
    }

    @Override
    public void feedback(TblAddUploadList item) throws Exception {
        TblRefundsDownload kqaz = tblRefundsDownloadService.lambdaQuery()
                .eq(TblRefundsDownload::getPgguid, item.getKeyId())
                .last("limit 1")
                .one();
        if (kqaz != null) {
            // 过程反馈
            if (feedbackRfunds(kqaz, item.getId()) == 0) {
                successTblAzwgmxAdd(item);
            }
        }
    }

    @Override
    public void repairSettlementStatus(SyncQuerySettlementStatus item) throws Exception {
        List<RepairSettlementStatusDownload> adds = new ArrayList<>();
        if (getSettlementStatus(item,adds)==0){
            successSettlementStatus(item);
            if (adds.size()>0){
                repairSettlementStatusDownloadService.saveOrUpdateBatch(adds);
                adds.clear();
            }
        }
    }

    @Override
    public void installSettlementStatus(SyncQuerySettlementStatus item) throws Exception {
        List<InstallSettlementStatusDownload> adds = new ArrayList<>();
        if (getInstallSettlementStatus(item,adds)==0){
            successSettlementStatus(item);
            if (adds.size()>0){
                installSettlementStatusDownloadService.saveOrUpdateBatch(adds);
                adds.clear();
            }
        }
    }

    @Override
    public void addRepairSettlement(TblAddUploadList item) throws Exception{
        List<RepairSettlementDownload> adds = new ArrayList<>();
        if (addRepairSettlement(item,adds)==0){
            successTblAzwgmxAdd(item);
            if (adds.size()>0){
                repairSettlementDownloadService.saveOrUpdateBatch(adds);
                adds.clear();
            }
        }
    }


    private int getSettlementStatus(SyncQuerySettlementStatus item,List<RepairSettlementStatusDownload> adds) throws Exception {
        SettlementBO req = new SettlementBO();
        req.setClientId(clientid);
        req.setWxjsguids(item.getSettlementId());
        log.info("request: {}", JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(otherurlbase + settlementUrl, JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            JSONArray datas = (JSONArray)JSONArray.parse(response.getData().toString());
            for (int i = 0; i < datas.size(); i++) {
                RepairSettlementStatusDownload add = JSONObject.parseObject(datas.getJSONObject(i).toString(), RepairSettlementStatusDownload.class);
                adds.add(add);
            }
            return 0;
        }
        errorSettlementStatus(item, response);
        return -1;
    }

    private int getInstallSettlementStatus(SyncQuerySettlementStatus item,List<InstallSettlementStatusDownload> adds) throws Exception {
        InstallSettlementBO request = new InstallSettlementBO();
        List<Settlement> wgmxParamList = new ArrayList<>();
        Settlement lst = new Settlement();
        lst.setSpid(101);
        lst.setPgwcmxid(item.getSettlementId());
        request.setClientid(clientid);
        wgmxParamList.add(lst);
        request.setWgmxParamList(wgmxParamList);

        log.info("request: {}", JSONObject.toJSONString(request));
        GreeResponseHelperOther response = greeLogic.greePostOther(otherurlbase + installQuerySettlement, JSONObject.toJSONString(request));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            Boolean flag = Boolean.TRUE;
            JSONArray datas = (JSONArray)JSONArray.parse(response.getData().toString());
            for (int i = 0; i < datas.size(); i++) {
                flag = (Boolean) JSONObject.parseObject(datas.getJSONObject(i).toString()).get("status");
                if (!flag){
                    response.setMessage(JSONObject.parseObject(datas.getJSONObject(i).toString()).get("msg").toString());
                    response.setMessage(response.getMessage());
                    errorTblAzwgmxAdd(item.getId(), response);
                    return 0;
                }
                InstallSettlementStatusDownload add = JSONObject.parseObject(datas.getJSONObject(i).toString(), InstallSettlementStatusDownload.class);
                adds.add(add);
            }
            return 0;
        }
        errorSettlementStatus(item, response);
        return -1;
    }

    private int addRepairSettlement(TblAddUploadList item,List<RepairSettlementDownload> adds) throws Exception {
        RepairSettlementBO req = new RepairSettlementBO();
        req.setClientId(clientid);
        req.setWxjsguids(item.getKeyId());
        log.info("request: {}", JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(otherurlbase + repairSettlement, JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        // String msg = response.getMessage().toString();

        if (response.getStatusCode() == 200){
            JSONArray datas = (JSONArray)JSONArray.parse(response.getData().toString());
            for (int i = 0; i < datas.size(); i++) {
                String data = datas.getJSONObject(i).toString();
                String wxjsguid = JSONObject.parseObject(data).get("wxjsguid").toString();

                String nList = JSONObject.parseObject(data).get("list").toString();
                JSONArray lists = (JSONArray)JSONArray.parse(nList);
                for (int j = 0; j < lists.size(); j++){
                    RepairSettlementDownload add = JSONObject.parseObject(lists.getJSONObject(j).toString(), RepairSettlementDownload.class);
                    add.setWxjsguid(wxjsguid);
                    adds.add(add);
                }
            }
            return 0;
        }
        JSONArray datas = (JSONArray)JSONArray.parse(response.getData().toString());
        response.setMessage(JSONObject.parseObject(datas.getJSONObject(0).toString()).get("msg").toString());
        errorTblAzwgmxAdd(item.getId(), response);
        return -1;
    }


    private void errorSettlementStatus(SyncQuerySettlementStatus item,GreeResponseHelperOther response){
        SyncQuerySettlementStatus up = new SyncQuerySettlementStatus();
        up.setId(item.getId());
        up.setSynStatus(-1);
        if (response.getMessage().length()>255){
            up.setErrMsg(response.getMessage().substring(0,255));
        } else {
            up.setErrMsg(response.getMessage());
        }
        syncQuerySettlementStatusService.updateById(up);
    }

    private void successSettlementStatus(SyncQuerySettlementStatus item) {
        SyncQuerySettlementStatus up = new SyncQuerySettlementStatus();
        up.setId(item.getId());
        up.setSynStatus(1);
        up.setSynReqTime(new Date());
        syncQuerySettlementStatusService.updateById(up);
    }

    private void successRepairSettlement(SyncQuerySettlementStatus item) {
        SyncQuerySettlementStatus up = new SyncQuerySettlementStatus();
        up.setId(item.getId());
        up.setSynStatus(1);
        up.setSynReqTime(new Date());
        syncQuerySettlementStatusService.updateById(up);
    }


    private int addDatacjsj(TblAzwgmxKqcjsjDownload cjsj,String splb,Long id) throws Exception {
        SpecialInstallApplyAddReq req = new SpecialInstallApplyAddReq();
        req.setClientId(clientid);
        req.setSqlb(splb);
        req.setTblAzwgmxKqcjsj(cjsj);
        req.setWdnm("新增网点名");

        log.info("request: {}", JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(otherurlbase + addurl, JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            return 0;
        }
        errorTblAzwgmxAdd(id, response);
        return -1;
    }

    private int addDataKjmm(TblAzwgmxKjmmDownload kjmm,String splb,Long id) throws Exception {
        SpecialInstallApplyAddReq req = new SpecialInstallApplyAddReq();
        req.setClientId(clientid);
        req.setSqlb(splb);
        req.setTblAzwgmxKqkjmm(kjmm);
        req.setWdnm("新增网点名");

        log.info("request: {}", JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(otherurlbase + addurl, JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            return 0;
        }
        errorTblAzwgmxAdd(id, response);
        return -1;
    }


    private int addDatakqaz(TblAzwgmxKqazDownload kqaz,String splb,Long id) throws Exception {
        SpecialInstallApplyAddReq req = new SpecialInstallApplyAddReq();
        req.setClientId(clientid);
        req.setSqlb(splb);
        req.setTblAzwgmxKqaz(kqaz);
        req.setWdnm("新增网点名");

        log.info("request: {}", JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(otherurlbase + addurl, JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            return 0;
        }
        errorTblAzwgmxAdd(id, response);
        return -1;
    }

    private int addDataRfunds(TblRefundsDownload refunds,Long id) throws Exception {
        RefundsAddBO req = new RefundsAddBO();
        BeanUtils.copyProperties(refunds,req);
        req.setClientId(clientid);

        req.setId(refunds.getPgguid());
        req.setXtwdbh("123");
        req.setFkrenmc("test");
        req.setWdno("2341");
        req.setCzren("rest");
        req.setWdmc("test");
        req.setFkren("2345");



        log.info("request: {}", JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(otherurlbase + refundsAdd, JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            return 0;
        }
        errorTblAzwgmxAdd(id, response);
        return -1;
    }

    private int updateDataRfunds(TblRefundsDownload refunds, Long id) throws Exception {
        RefundsUpdateBO req = new RefundsUpdateBO();
        BeanUtils.copyProperties(refunds,req);
        req.setClientId(clientid);

        req.setId(refunds.getPgguid());
        req.setXtwdbh("123");
        req.setFkrenmc("test");
        req.setWdno("2341");
        req.setCzren("rest");
        req.setWdmc("test");
        req.setFkren("2345");



        log.info("request: {}", JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(otherurlbase + refundsUpdate, JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            return 0;
        }
        errorTblAzwgmxAdd(id, response);
        return -1;
    }

    private int feedbackRfunds(TblRefundsDownload refunds, Long id) throws Exception {
        RefundsFeedbackBO req = new RefundsFeedbackBO();
        BeanUtils.copyProperties(refunds,req);
        req.setClientId(clientid);
        req.setXtwdbh("123");
        req.setFkren("2345");
        req.setFkrenmc("test");
        req.setXtwdbh("2546");
        req.setWdno("2341");
        req.setWdmc("test");
        req.setYykssj("2022-04-04 12:12:12");
        req.setYyjssj("2022-04-04 12:12:12");
        req.setFknr("test");
        req.setXhmc("test");
        log.info("request: {}", JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(otherurlbase + refundsFeedback, JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            return 0;
        }
        errorTblAzwgmxAdd(id, response);
        return -1;
    }

    private int addDataFeedBack(QualityFeedbackHeadDownload feedback,Long id) throws Exception {
        log.info("request: {}", JSONObject.toJSONString(feedback));
        GreeResponseHelperOther response = greeLogic.greePostOther(otherurlbase + feedbackUrl, JSONObject.toJSONString(feedback));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            return 0;
        }
        errorTblAzwgmxAdd(id, response);
        return -1;
    }


    private void errorTblAzwgmxAdd(Long id, GreeResponseHelperOther response) {
        TblAddUploadList up = new TblAddUploadList();
        up.setId(id);
        up.setSynStatus(-1);
        up.setSynReqTime(new Date());
        if (response.getMessage().length()>255){
            up.setErrMsg(response.getMessage().substring(0,255));
        } else {
            up.setErrMsg(response.getMessage());
        }
        tblAddUploadListService.updateById(up);
    }



    private void successTblAzwgmxAdd(TblAddUploadList item) {
        TblAddUploadList up = new TblAddUploadList();
        up.setId(item.getId());
        up.setSynStatus(1);
        up.setSynReqTime(new Date());
        tblAddUploadListService.updateById(up);
    }

    private int getDataCjsj(int page, int size, List<TblAzwgmxKqcjsjDownload> ads, TableDataQueryTime item, String splb) throws Exception {
        int total=0;
        QuerySpecialInstallBO req = new QuerySpecialInstallBO();
        req.setClientId(clientid);
        if (item.getSynReqTime() !=null){
            req.setLastSearchDate(sdf.format(item.getSynReqTime()));
        }
        req.setPageNum(page);
        req.setSize(size);
        req.setSqlb(splb);

        log.info("request: {}",JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(item.getUrl(), JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            String data = response.getData().toString();
            String pages = JSONObject.parseObject(data).get("page").toString();
            total = JSONObject.parseObject(pages).getInteger("total");
            JSONArray datas = (JSONArray)JSONArray.parse(JSONObject.parseObject(pages).get("records").toString());
            for (int i = 0; i < datas.size(); i++) {
                TblAzwgmxKqcjsjDownload add = JSONObject.parseObject(datas.getJSONObject(i).toString(), TblAzwgmxKqcjsjDownload.class);
                ads.add(add);
            }
            return total;
        }
        // 同步失败
        synErrorTableDataQueryTime(item, response);
        return -1;
    }

    private int getDataKjmm(int page, int size, TableDataQueryTime item, List<TblAzwgmxKjmmDownload> ads, String splb) throws Exception {
        int total=0;
        QuerySpecialInstallBO req = new QuerySpecialInstallBO();
        req.setClientId(clientid);
        if (item.getSynReqTime() !=null){
            req.setLastSearchDate(sdf.format(item.getSynReqTime()));
        }
        req.setPageNum(page);
        req.setSize(size);
        req.setSqlb(splb);

        log.info("request: {}",JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(item.getUrl(), JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            String data = response.getData().toString();
            String pages = JSONObject.parseObject(data).get("page").toString();
            total = JSONObject.parseObject(pages).getInteger("total");
            JSONArray datas = (JSONArray)JSONArray.parse(JSONObject.parseObject(pages).get("records").toString());
            for (int i = 0; i < datas.size(); i++) {
                TblAzwgmxKjmmDownload add = JSONObject.parseObject(datas.getJSONObject(i).toString(), TblAzwgmxKjmmDownload.class);
                ads.add(add);
            }
            return total;
        }
        // 同步失败
        synErrorTableDataQueryTime(item, response);
        return -1;
    }

    private int getData(int page, int size, TableDataQueryTime item, List<TblAzwgmxKqazDownload> ads, String splb) throws Exception {
        int total=0;
        QuerySpecialInstallBO req = new QuerySpecialInstallBO();
        req.setClientId(clientid);
        if (item.getSynReqTime() !=null){
            req.setLastSearchDate(sdf.format(item.getSynReqTime()));
        }
        req.setPageNum(page);
        req.setSize(size);
        req.setSqlb(splb);

        log.info("request: {}",JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(item.getUrl(), JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            String data = response.getData().toString();
            String pages = JSONObject.parseObject(data).get("page").toString();
            total = JSONObject.parseObject(pages).getInteger("total");
            JSONArray datas = (JSONArray)JSONArray.parse(JSONObject.parseObject(pages).get("records").toString());
            for (int i = 0; i < datas.size(); i++) {
                TblAzwgmxKqazDownload add = JSONObject.parseObject(datas.getJSONObject(i).toString(), TblAzwgmxKqazDownload.class);
                ads.add(add);
            }
            return total;
        }
        // 同步失败
        synErrorTableDataQueryTime(item, response);
        return -1;
    }


    private int getRefundsData(int page, int size, TableDataQueryTime item,
                               List<TblRefundsDownload> ads) throws Exception {
        int total=0;
        QueryRefundsBO req = new QueryRefundsBO();
        req.setClientId(clientid);
        if (item.getSynReqTime() !=null){
            req.setStartTime(sdf.format(item.getSynReqTime()));
        }
        req.setPage(page);
        req.setSize(size);

        log.info("request: {}",JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(item.getUrl(), JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            total =response.getTotal();
            JSONArray datas = (JSONArray)JSONArray.parse(response.getData().toString());
            for (int i = 0; i < datas.size(); i++) {
                TblRefundsDownload add = JSONObject.parseObject(datas.getJSONObject(i).toString(), TblRefundsDownload.class);
                ads.add(add);
            }
            return total;
        }
        // 同步失败
        synErrorTableDataQueryTime(item, response);
        return -1;
    }

    private int getAccessoriesData(int page, int size, TableDataQueryTime item,
                               List<AccessoriesQueryDownload> ads) throws Exception {
        int total=0;
        AccessoriesBO req = new AccessoriesBO();
        req.setClientId(clientid);
        req.setPageNum(page);
        req.setSize(size);

        log.info("request: {}",JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(item.getUrl(), JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            total =response.getTotal();
            JSONArray datas = (JSONArray)JSONArray.parse(response.getData().toString());
            for (int i = 0; i < datas.size(); i++) {
                AccessoriesQueryDownload add = JSONObject.parseObject(datas.getJSONObject(i).toString(), AccessoriesQueryDownload.class);
                ads.add(add);
            }
            return total;
        }
        // 同步失败
        synErrorTableDataQueryTime(item, response);
        return -1;
    }

    private int getJdData(int page, int size, TableDataQueryTime item,
                          List<JdMessageDownload> ads) throws Exception {
        int total=0;
        QueryJdBO req = new QueryJdBO();
        req.setClientId(clientid);
        req.setOrderNo("HA0122103101044552");
        req.setPageNum(page);
        req.setPageSize(size);

        log.info("request: {}",JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(item.getUrl(), JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            total =response.getTotal();
            JSONArray datas = (JSONArray)JSONArray.parse(response.getData().toString());
            for (int i = 0; i < datas.size(); i++) {
                JdMessageDownload add = JSONObject.parseObject(datas.getJSONObject(i).toString(), JdMessageDownload.class);
                ads.add(add);
            }
            return total;
        }
        // 同步失败
        synErrorTableDataQueryTime(item, response);
        return -1;
    }


    private void getMessageData(TableDataQueryTime item, List<GreeMessageDownload> ads,
                                List<GreeShortMessageReplyDownload> shorts) throws Exception {
        MessageBO req = new MessageBO();
        req.setAzorwx(1);
        req.setPgid("20210521162706142");
        req.setPhone("18970944263");

        log.info("request: {}",JSONObject.toJSONString(req));
        GreeResponseHelperOther response = HttpUtil.httpGetInfo(String.format(item.getUrl(), String.valueOf(req.getAzorwx()),req.getPgid(),req.getPhone()),greeLogic.greeGetT());

        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
             JSONArray datas = (JSONArray)JSONArray.parse(response.getData().toString());
            for (int i = 0; i < datas.size(); i++) {
                GreeMessageDownload add = JSONObject.parseObject(datas.getJSONObject(i).toString(), GreeMessageDownload.class);
                ads.add(add);
                String ls = JSONObject.parseObject(datas.getJSONObject(i).toString()).get("rerunContentList").toString();
                JSONArray ds = (JSONArray)JSONArray.parse(ls);
                for (int j = 0; j < ds.size(); j++){
                    GreeShortMessageReplyDownload ad = JSONObject.parseObject(ds.getJSONObject(j).toString(), GreeShortMessageReplyDownload.class);
                    ad.setPgid(add.getPgid());
                    shorts.add(ad);
                }
            }
            return ;
        }
        // 同步失败
        synErrorTableDataQueryTime(item, response);
    }


    private void synSuccessTableDataQueryTime(TableDataQueryTime item, int total, Date synTime) {
        if (total >-1){
            TableDataQueryTime up = new TableDataQueryTime();
            up.setId(item.getId());
            up.setSynStatus(1);
            up.setSynReqTime(synTime);
            tableDataQueryTimeService.updateById(up);
        }
    }


    private void synSuccessTableDataQueryTimeT(TableDataQueryTime item) {
        TableDataQueryTime up = new TableDataQueryTime();
        up.setId(item.getId());
        up.setSynStatus(1);
        up.setSynReqTime(new Date());
        tableDataQueryTimeService.updateById(up);
    }

    private int getData(int page, int size, List<QualityFeedbackHeadDownload> ads, TableDataQueryTime item) throws Exception {
        int total=0;
        QualityFeedbackHeadBO req = new QualityFeedbackHeadBO();
        req.setClientId(clientid);
        req.setLastSearchTime(sdf.format(item.getSynReqTime()));
        req.setPage(page);
        req.setSize(size);

        log.info("request: {}", JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(item.getUrl(), JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            total =response.getTotal();
            JSONArray datas = (JSONArray)JSONArray.parse(response.getData().toString());
            for (int i = 0; i < datas.size(); i++) {
                QualityFeedbackHeadDownload add = JSONObject.parseObject(datas.getJSONObject(i).toString(), QualityFeedbackHeadDownload.class);
                ads.add(add);
            }
            return total;
        }
        // 同步失败
        synErrorTableDataQueryTime(item, response);
        return -1;
    }

    private int getData(int page, int size, List<NotificationDownload> ads, TableDataQueryTime item, String spId) throws Exception {
        int total=0;
        QueryNotificationBO req = new QueryNotificationBO();
        req.setClientId(clientid);
        req.setLastSearchDate(item.getSynReqTime().toInstant());
        req.setPage(page);
        req.setSize(size);
        req.setSpid(spId);

        log.info("request: {}",JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(item.getUrl(), JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            total =response.getTotal();
            JSONArray datas = (JSONArray)JSONArray.parse(response.getData().toString());
            for (int i = 0; i < datas.size(); i++) {
                NotificationDownload add = JSONObject.parseObject(datas.getJSONObject(i).toString(), NotificationDownload.class);
                ads.add(add);
            }
            return total;
        }
        // 同步失败
        synErrorTableDataQueryTime(item, response);
        return -1;
    }

    private void synErrorTableDataQueryTime(TableDataQueryTime item, GreeResponseHelperOther response) {
        TableDataQueryTime up = new TableDataQueryTime();
        up.setId(item.getId());
        up.setSynStatus(-1);
        if (response.getMessage().length()>255){
            up.setErrMsg(response.getMessage().substring(0,255));
        } else {
            up.setErrMsg(response.getMessage());
        }
        tableDataQueryTimeService.updateById(up);
    }


    private void successTblAzwgmxUpload(TblAzwgmxUpload item) {
        TblAzwgmxUpload up = new TblAzwgmxUpload();
        up.setId(item.getId());
        up.setSynStatus(1);
        up.setSynReqTime(new Date());
        tblAzwgmxUploadService.updateById(up);
    }


    private int getDatakqaz(TblAzwgmxKqazDownload kqaz,String splb,Long id) throws Exception {
        SpecialInstallApplyUpdateReq req = new SpecialInstallApplyUpdateReq();
        req.setClientId(clientid);
        req.setPgwcmxid(kqaz.getPgwcmxid());
        req.setSqlb(splb);
        req.setTblAzwgmxKqaz(kqaz);
        req.setWdnm("修改网点名");

        log.info("request: {}", JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(otherurlbase + url, JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            return 0;
        }
        errorTblAzwgmxUpload(id, response);
        return -1;
    }

    private int getDataKjmm(TblAzwgmxKjmmDownload kjmm,String splb,Long id) throws Exception {
        SpecialInstallApplyUpdateReq req = new SpecialInstallApplyUpdateReq();
        req.setClientId(clientid);
        req.setPgwcmxid(kjmm.getPgwcmxid());
        req.setSqlb(splb);
        req.setTblAzwgmxKqkjmm(kjmm);
        req.setWdnm("修改网点名");

        log.info("request: {}", JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(otherurlbase + url, JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            return 0;
        }
        errorTblAzwgmxUpload(id, response);
        return -1;
    }

    private int getDatacjsj(@NotNull TblAzwgmxKqcjsjDownload cjsj, String splb, Long id) throws Exception {
        SpecialInstallApplyUpdateReq req = new SpecialInstallApplyUpdateReq();
        req.setClientId(clientid);
        req.setPgwcmxid(cjsj.getPgwcmxid());
        req.setSqlb(splb);
        req.setTblAzwgmxKqcjsj(cjsj);
        req.setWdnm("修改网点名");

        log.info("request: {}", JSONObject.toJSONString(req));
        GreeResponseHelperOther response = greeLogic.greePostOther(otherurlbase + url, JSONObject.toJSONString(req));
        log.info("response: {}",JSONObject.toJSONString(response));
        if (response.getStatusCode() == 200){
            return 0;
        }
        errorTblAzwgmxUpload(id, response);
        return -1;
    }

    private void errorTblAzwgmxUpload(Long id, GreeResponseHelperOther response) {
        TblAzwgmxUpload up = new TblAzwgmxUpload();
        up.setId(id);
        up.setSynStatus(-1);
        up.setSynReqTime(new Date());
        if (response.getMessage().length()>255){
            up.setErrMsg(response.getMessage().substring(0,255));
        } else {
            up.setErrMsg(response.getMessage());
        }
        tblAzwgmxUploadService.updateById(up);
    }
}
