package com.unis.crk.common.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.unis.crk.basic.entity.Attaches;
import com.unis.crk.basic.entity.BasicEnum;
import com.unis.crk.basic.entity.SysParams;
import com.unis.crk.basic.service.*;
import com.unis.crk.business.kcgl.entity.*;
import com.unis.crk.business.kcgl.service.*;
import com.unis.crk.business.qcck.entity.DataCrkywCkcmDefault;
import com.unis.crk.business.qcck.entity.DataCrkywCkcmzDefault;
import com.unis.crk.business.qcck.entity.DataCrkywCkcpzDefault;
import com.unis.crk.business.qcck.entity.DataCrkywCkrmdjDefault;
import com.unis.crk.business.qcck.service.IDataCrkywCkcmDefaultService;
import com.unis.crk.business.qcck.service.IDataCrkywCkcmzDefaultService;
import com.unis.crk.business.qcck.service.IDataCrkywCkcpzDefaultService;
import com.unis.crk.business.qcck.service.IDataCrkywCkrmdjDefaultService;
import com.unis.crk.business.qcrk.entity.*;
import com.unis.crk.business.qcrk.service.*;
import com.unis.crk.common.entity.Bizflowtrail;
import com.unis.crk.common.entity.DataCenterUpload;
import com.unis.crk.common.entity.DeleteDataRecord;
import com.unis.crk.common.mapper.DataCenterUploadMapper;
import com.unis.crk.common.service.IBizflowtrailService;
import com.unis.crk.common.service.IDataCenterUploadService;
import com.unis.crk.common.service.IDeleteDataRecordService;
import com.unis.crk.common.service.IUpdataLogService;
import com.unis.crk.cplbusiness.entity.*;
import com.unis.crk.cplbusiness.service.*;
import com.unis.crk.enums.TableNames;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.*;

@Transactional
@Service
public class DataCenterUploadServiceImpl extends ServiceImpl<DataCenterUploadMapper,DataCenterUpload>  implements IDataCenterUploadService {
    @Resource
    private  DataCenterUploadMapper dataCenterUploadMapper;
    @Autowired
    private IDeleteDataRecordService deleteDataRecordService;
    //枚举
    @Autowired
    private IBasicEnumService basicEnumService;
    //系统参数
    @Autowired
    private ISysParamsService sysParamsService;
    @Autowired
    IBasicStorehouseService basicStorehouseService;
    @Autowired
    IBasicWarehouseService basicWarehouseService;
    //原粮入库
    @Autowired
    IBizflowtrailService bizflowtrailService;
    @Autowired
    IDataCrkywRmdjDefaultService dataCrkywRmdjDefaultService;
    @Autowired
    IDataCrkywQyxxDefaultService dataCrkywQyxxDefaultService;
    @Autowired
    IDataCrkywJyxxDefaultService dataCrkywJyxxDefaultService;

    @Autowired
    IDataCrkywJyxxFlt001Service dataCrkywJyxxFlt001Service;

    @Autowired
    IDataCrkywCmzDefaultService dataCrkywCmzDefaultService;
    @Autowired
    IDataCrkywCpzDefaultService dataCrkywCpzDefaultService;
    @Autowired
    IDataCrkywJsxxDefaultService dataCrkywJsxxDefaultService;
    @Autowired
    IDataCrkywZcDefaultService dataCrkywZcDefaultService;

    @Autowired
    IDataCrkywRkcmDefaultService dataCrkywRkcmDefaultService;
    @Autowired
    IDataCrkywTzdxxDefaultService dataCrkywTzdxxDefaultService;
    @Autowired
    IDataCrkywTzdxxFlt001Service dataCrkywTzdxxFlt001Service;
    //原粮出库
    @Autowired
    IDataCrkywCkrmdjDefaultService dataCrkywCkrmdjDefaultService;
    @Autowired
    IDataCrkywCkcpzDefaultService dataCrkywCkcpzDefaultService;
    @Autowired
    IDataCrkywCkcmzDefaultService dataCrkywCkcmzDefaultService;
    @Autowired
    IDataCrkywCkcmDefaultService dataCrkywCkcmDefaultService;

    //原粮库存管理
    @Autowired
    IDataKcglFcbgzDefaultService dataKcglFcbgzDefaultService;
    @Autowired
    IDataKcglKcbdDefaultService dataKcglKcbdDefaultService;
    @Autowired
    IDataKcglKcswDefaultService dataKcglKcswDefaultService;
    @Autowired
    IDataKcglQckcDefaultService dataKcglQckcDefaultService;
    @Autowired
    IDataKcglXckcDefaultService dataKcglXckcDefaultService;


    //成品粮库存调整
    @Autowired
    INventoryAdjustmentService nventoryAdjustmentService;
    //成品粮领用
    @Autowired
    IOllectionReviewService  ollectionReviewService;
    //成品粮商品拆分
    @Autowired
    ISettlementManagementService settlementManagementService;
    //标签打印
    @Autowired
    IDataCrkywCplbjdyDefaultService dataCrkywCplbjdyDefaultService;
    //成品粮出库
    @Autowired
    IDataCrkywCplckDefaultService dataCrkywCplckDefaultService;
    //成品粮出库从表
    @Autowired
    IDataCrkywCplckFlt001Service dataCrkywCplckFlt001Service;
    //成品粮评分
    @Autowired
    IDataCrkywCplpfDefaultService  dataCrkywCplpfDefaultService;
    //成品粮抽样质检主表
    @Autowired
    IDataCrkywCpljyxxDefaultService dataCrkywCpljyxxDefaultService;
    //成品粮抽样质检从表
    @Autowired
    IDataCrkywCpljyxxFlt001Service dataCrkywCpljyxxFlt001Service;
    //成品粮入库
    @Autowired
    IDataCrkywCplrkDefaultService dataCrkywCplrkDefaultService;
    @Autowired
    IDataCrkywCplrkFlt001Service dataCrkywCplrkFlt001Service;
    //成品粮分库保管账
    @Autowired
    IDataKcglCplfcbgzDefaultService dataKcglCplfcbgzDefaultService;
    //成品粮库存变动
    @Autowired
    IDataKcglCplkcbdDefaultService dataKcglCplkcbdDefaultService;
    //成品粮库存实物
    @Autowired
    IDataKcglCplkcswDefaultService dataKcglCplkcswDefaultService;
    //成品粮期初库存
    @Autowired
    IDataKcglCplqckcDefaultService dataKcglCplqckcDefaultService;
    //成品粮形成库存
    @Autowired
    IDataKcglCplxckcDefaultService dataKcglCplxckcDefaultService;
    //成品粮分拣
    @Autowired
    IDataCrkywCplfjDefaultService dataCrkywCplfjDefaultService;

    //成品粮分拣从表
    @Autowired
    IDataCrkywCplfjFlt001Service dataCrkywCplfjFlt001Service;

    //成品粮商品信息
    @Autowired
    IDataCrkywCplspDefaultService dataCrkywCplspDefaultService;
    //附件表
    @Autowired
    IAttachesService attachesService;
    //成品粮通知单主表
    @Autowired
    IDataCrkywCpltzdxxDefaultService dataCrkywCpltzdxxDefaultService;
    //成品粮通知单从表
    @Autowired
    IDataCrkywCpltzdxxFlt001Service dataCrkywCpltzdxxFlt001Service;
    @Autowired
    IUpdataLogService updataLogService;
    //车辆调度
    @Autowired
    IDispatchEhicleManagementService dispatchEhicleManagementService;
    //人员调度
    @Autowired
    IDispatcPersonnelManagementService dispatcPersonnelManagementService;
    @Override
    public JSONObject uploadSjzxData(String unitId,String topic,String tableNames) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status","300"); //失败
        SysParams sysParams = sysParamsService.getById("curUnit");
        if (StrUtil.isBlank(unitId)){
            if (sysParams == null ||StrUtil.isBlank(sysParams.getParamVal())) { //当前单位id
                updataLogService.saveUploadLog(unitId,"",jsonObject.getString("message"));
                jsonObject.put("message","未传入当前单位Id");
                return jsonObject;
            }
            unitId = sysParams.getParamVal();
        }
        //得到是否上传数据
        sysParams = sysParamsService.getById("isStopUploadData");
        if (sysParams == null ||StrUtil.equals("1", sysParams.getParamVal())) { //表示停止上传数据
            jsonObject.put("message","停止上传数据");
            updataLogService.saveUploadLog(unitId,"",jsonObject.getString("message"));
            return jsonObject;
        }
        sysParams = sysParamsService.getById("upSJzxdata.url");
        if (sysParams == null || StrUtil.isBlank(sysParams.getParamVal())) { //上传数据地址
            jsonObject.put("message","未查询到上传数据地址");
            updataLogService.saveUploadLog(unitId,"",jsonObject.getString("message"));
            return jsonObject;
        }

        //将unitId放入json
        jsonObject.put("unitId",unitId);
        String limit = "limit 0,25";
//        String limit = "limit 0,1";
        try {
            //解析JSON数据
            //{basicStorehouse:[{},{}],basicWarehouse[{},{}]}
            JSONArray datas = new JSONArray();
            StringBuilder operatlog = new StringBuilder("1000");
            Boolean isNull = true;
            operatlog =  getUpSjzxloadData(unitId, limit, datas, operatlog,isNull,tableNames);

            if (datas.size() <=0){
                jsonObject.put("message","未查询到上传数据");
                updataLogService.saveUploadLog(unitId,"",jsonObject.getString("message"));
                return jsonObject;
            }
            //上传数据
            JSONObject data = new JSONObject();
            data.put("type","data");
            data.put("value",JSONArray.toJSONStringWithDateFormat(datas,JSONObject.DEFFAULT_DATE_FORMAT));
//            System.out.println(datas);

            JSONObject postData = new JSONObject();
            postData.put("platform", "inOutLib");
            if (StrUtil.isBlank(topic)){
                topic = "all";
            }
//            postData.put("topic", "inOutLib.all");
            postData.put("topic", "inOutLib."+topic);
            postData.put("sign", "DD012479178D51FD33D06D7F3A4F0557");
            postData.put("data",data);
            System.out.println("参数:"+postData.toString());
            RestTemplate client = new RestTemplate();
            JSONObject json = client.postForEntity(sysParams.getParamVal(), postData, JSONObject.class).getBody();
            System.out.println("数据上传返回值:"+json);
            //成功再更新上传时间
            if (!StrUtil.equals(json.getString("code"),"200")){
                jsonObject.put("message",json.getString("message")+",此表数据未上传"+json.getString("updateFailData"));
            }else {
                //更新上传时间
                updateUplpadTimeData(json.get("data"));
                jsonObject.put("message","上传数据成功,"+operatlog);
            }
        }catch (Exception e){
            e.printStackTrace();
            jsonObject.put("message","上传数据失败："+e.getMessage());
        }

        return jsonObject;
    }
    @Override
    public JSONObject uploadSjzxDataByTopic(String unitId,String topic) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status","300"); //失败
        SysParams sysParams = sysParamsService.getById("curUnit");
        //得到是否上传数据
        sysParams = sysParamsService.getById("isStopUploadData");
        if (sysParams == null ||StrUtil.equals("1", sysParams.getParamVal())) { //表示停止上传数据
            jsonObject.put("message","停止上传数据");
            updataLogService.saveUploadLog(unitId,"",jsonObject.getString("message"));
            return jsonObject;
        }
        sysParams = sysParamsService.getById("upSJzxdata.url");
        if (sysParams == null || StrUtil.isBlank(sysParams.getParamVal())) { //上传数据地址
            jsonObject.put("message","未查询到上传数据地址");
            updataLogService.saveUploadLog(unitId,"",jsonObject.getString("message"));
            return jsonObject;
        }

        //将unitId放入json
        jsonObject.put("unitId",unitId);
        String limit = "limit 0,25";
//        String limit = "limit 0,1";
        try {
            //解析JSON数据
            //{basicStorehouse:[{},{}],basicWarehouse[{},{}]}
            JSONArray datas = new JSONArray();
            StringBuilder operatlog = new StringBuilder("1000");
            Boolean isNull = true;
            operatlog =  getUpSjzxloadDataByTopic(unitId, limit, datas, operatlog,isNull,topic);

            if (datas.size() <=0){
                jsonObject.put("message","未查询到上传数据");
                updataLogService.saveUploadLog(unitId,"",jsonObject.getString("message"));
                return jsonObject;
            }
            //上传数据
            JSONObject data = new JSONObject();
            data.put("type","data");
            data.put("value",JSONArray.toJSONStringWithDateFormat(datas,JSONObject.DEFFAULT_DATE_FORMAT));
//            System.out.println(datas);

            JSONObject postData = new JSONObject();
            postData.put("platform", "inOutLib");
            if (StrUtil.isBlank(topic)){
                topic = "all";
            }
//            postData.put("topic", "inOutLib.all");
            postData.put("topic", "inOutLib."+topic);
            postData.put("sign", "DD012479178D51FD33D06D7F3A4F0557");
            postData.put("data",data);
            System.out.println("上传业务数据数据："+postData);
            RestTemplate client = new RestTemplate();
            JSONObject json = client.postForEntity(sysParams.getParamVal(), postData, JSONObject.class).getBody();
            System.out.println("上传业务数返回值："+json);
            //成功再更新上传时间
            if (!StrUtil.equals(json.getString("code"),"200")){
                jsonObject.put("message",json.getString("message")+",此表数据未上传"+json.getString("updateFailData"));
            }else {
                //更新上传时间
                updateUplpadTimeData(json.get("data"));
                jsonObject.put("message","上传业务数据成功,"+operatlog);
            }
        }catch (Exception e){
            e.printStackTrace();
            jsonObject.put("message","上传业务数据失败："+e.getMessage());
        }

        return jsonObject;
    }

    private void updateUplpadTimeData(Object data) {
        if(data == null){
            return;
        }
        LinkedHashMap<String,List<String>> javaObject = (LinkedHashMap)data;
        QueryWrapper queryWrapper = new QueryWrapper<DataCenterUpload>();
        String tableNames = "data_kcgl_cpljgdj_default,data_crkyw_cpltzdxx_flt_001";

        for (Map.Entry<String,List<String>> entry : javaObject.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            String str = value.toString();
            String replace = str.replace("[", "").replace("]", "");
            if(StrUtil.isNotBlank(replace)){
                String[] split = replace.split(",");
                if(split.length>0){
                    for(int i = 0;i<split.length;i++){
                        String sql=null;
                        String now = DateUtil.now();
                        String dataId = split[i].trim();
                        if (key.contains("attaches") ){
                            dataCenterUploadMapper.executeUpdate("update "+key+" SET FLAG =1 WHERE    SelfID ='"+dataId+"'");
//                            dataCenterUploadMapper.updataAfterUpload(key,split[i],now);
                            continue;
                        }
                        if (key.contains("basic_enum") ){
                            dataCenterUploadMapper.executeUpdate("update "+key+" SET EDIT_TIME ='"+now+"' WHERE    enumId ='"+dataId+"'");
//                            dataCenterUploadMapper.updataAfterUpload(key,split[i],now);
                            continue;
                        }
                        if (tableNames.contains(key.toLowerCase()) || key.contains("tzdxx")){
                            dataCenterUploadMapper.executeUpdate("update "+key+" SET UPDATE_TIME ='"+now+"' WHERE    dataId ='"+dataId+"'");
//                            dataCenterUploadMapper.updataAfterUpload(key,split[i],now);
                            continue;
                        }
                       if(!key.contains("tzdxx") && (key.contains("Cpl")||key.contains("cpl")||key.contains("ollection_review")||key.contains("settlement_management")||key.contains("ollectionReviewQueryWrapper")||key.contains("nventory_adjustment")||key.contains("dispatc_personnel_management")||key.contains("dispatch_ehicle_management"))){
//                           dataCenterUploadMapper.updataAfterUploadcpl(key,split[i],now);
                           dataCenterUploadMapper.executeUpdate("update "+key+" SET updateTime ='"+now+"' WHERE    dataId ='"+dataId+"'");
                        }
                       else  if(key.contains("bizflowtrail")){
//                           dataCenterUploadMapper.updataAfterUploadcpl(key,split[i],now);
                           dataCenterUploadMapper.executeUpdate("update "+key+" SET UPDATE_TIME ='"+now+"' WHERE    TrailID ='"+dataId+"'");
                        }
                        else{
                           dataCenterUploadMapper.executeUpdate("update "+key+" SET UPDATE_TIME ='"+now+"' WHERE    dataId ='"+dataId+"'");
//                           dataCenterUploadMapper.updataAfterUpload(key,split[i],now);

                        }


                    }
                }}

        }
    }



    /**
     * 根据单位Id删除上传数据中心数据
     *
     * @param unitId
     * @return
     */
    @Override
    public JSONObject deleteSjzxData(String unitId,String topic) {
        {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("status","300"); //失败
            SysParams sysParams = sysParamsService.getById("curUnit");
            if (StrUtil.isBlank(unitId)){
                if (sysParams == null ||StrUtil.isBlank(sysParams.getParamVal())) { //当前单位id
                    jsonObject.put("message","未传入当前单位Id!");
                    updataLogService.saveUploadLog(unitId,"",jsonObject.getString("message"));
                    return jsonObject;
                }
                unitId = sysParams.getParamVal();
            }
            //得到是否上传数据
            sysParams = sysParamsService.getById("isStopUploadData");
            if (sysParams == null ||StrUtil.equals("1", sysParams.getParamVal())) { //表示停止上传数据
                jsonObject.put("message","停止上传数据");
                updataLogService.saveUploadLog(unitId,"",jsonObject.getString("message"));
                return jsonObject;
            }
            sysParams = sysParamsService.getById("upSJzxdata.url");
            if (sysParams == null || StrUtil.isBlank(sysParams.getParamVal())) { //上传数据地址
                jsonObject.put("message","未查询到上传数据地址");
                updataLogService.saveUploadLog(unitId,"",jsonObject.getString("message"));
                return jsonObject;
            }

            //将unitId放入json
            jsonObject.put("unitId",unitId);
            String limit = "limit 0,25";
            try {
                if (StrUtil.isBlank(topic)){
                    topic = "all";
                }
                //解析JSON数据
                //{basicStorehouse:[{},{}],basicWarehouse[{},{}]}
                JSONArray datas = new JSONArray();
                StringBuilder operatlog = new StringBuilder("1000");
                List<DeleteDataRecord> deleteDataRecords = delUpSjzxloadDataByTopic(unitId, limit, datas, topic, operatlog);

                if (datas.size() <=0){
                    jsonObject.put("message","未查询到上传数据");
                    updataLogService.saveUploadLog(unitId,"",jsonObject.getString("message"));
                    return jsonObject;
                }
                //上传数据
                JSONObject data = new JSONObject();
                data.put("type","data");
                data.put("value",JSONArray.toJSONStringWithDateFormat(datas,JSONObject.DEFFAULT_DATE_FORMAT));

                JSONObject postData = new JSONObject();
                postData.put("platform", "inOutLib");

                postData.put("topic", "inOutLib."+topic);
                postData.put("sign", "DD012479178D51FD33D06D7F3A4F0557");
                postData.put("data",data);
                System.out.println("上传删除数据:"+postData);
                RestTemplate client = new RestTemplate();
                JSONObject json = client.postForEntity(sysParams.getParamVal(), postData, JSONObject.class).getBody();
                System.out.println("上传删除返回值："+json);
                //更新上传时间
                if (!StrUtil.equals(json.getString("code"),"200")){
                    jsonObject.put("message",json.getString("message")+",此表数据未上传"+json.getString("updateFailData"));
                }else {
                    //更新上传时间
                    Iterator<DeleteDataRecord> iterator = deleteDataRecords.iterator();
                    if(iterator.hasNext()){
                        DeleteDataRecord next = iterator.next();
                        next.setUploadTime(new Date());
                        deleteDataRecordService.updateById(next);
                    }
                    operatlog.append("delete_data_record").append(deleteDataRecords.size()).append("条;");
                    jsonObject.put("message","上传删除数据成功,"+operatlog);
                }
            }catch (Exception e){
                e.printStackTrace();
                jsonObject.put("message","上传删除数据失败："+e.getMessage());
            }

            return jsonObject;
        }
    }

    @Override
    public String test(String unitId) {
        String limit = "limit 0,100";
        JSONArray datas = new JSONArray();
        String tablenames="";
        StringBuilder operatlog = new StringBuilder("1000");
        operatlog =  getUpSjzxloadData(unitId, limit, datas, operatlog,true,tablenames);
        boolean b = false;
//        operatlog = uploadJsSjzxRkData(unitId,limit,datas,operatlog,b);
//        operatlog = uploadJsSjzxlCkData(unitId,limit,datas,operatlog,b);
//        uploadJsSjzxKcData(unitId,limit,datas,operatlog,b);
//        uploadJsSjzxCplKcData(unitId,limit,datas,operatlog,b);
//        uploadJsSjzxKcbdData(unitId,limit,datas,operatlog,b);
//        uploadJsSjzxTzzdData(unitId,limit,datas,operatlog,b);
//        uploadJsSjzxQckcData(unitId,limit,datas,operatlog,b);
//        uploadJsSjspData(unitId,limit,datas,operatlog,b);
//        uploadJsSjattachesData(unitId,limit,datas,operatlog,b);
        System.out.println(datas);
        return operatlog.toString();
    }


    private List<DeleteDataRecord> delUpSjzxloadDataByTopic(String unitId, String limit, JSONArray datas,String topic, StringBuilder operatlog) {{
        List<String> tableNames = new ArrayList<>();
        if (!StringUtils.equals("all",topic)){
            //成品粮
            if (StrUtil.equals("cpl.tzd",topic)){ //通知单
                tableNames.add("data_crkyw_cpltzdxx_default");
                tableNames.add("data_crkyw_cpltzdxx_flt_001");
            }
            if (StrUtil.equals("cpl.rk",topic)){ //入库
                tableNames.add("data_crkyw_cplrk_default");
                tableNames.add("data_crkyw_cplrk_flt_001");
            }
            if (StrUtil.equals("cpl.ck",topic)){ //出库
                tableNames.add("data_crkyw_cplck_default");
                tableNames.add("data_crkyw_cplck_flt_001");
            }
            if (StrUtil.equals("cpl.zj",topic)){ //化验
                tableNames.add("data_crkyw_cpljyxx_default");
                tableNames.add("data_crkyw_cpljyxx_flt_001");
            }
            if (StrUtil.equals("cpl.qc",topic)){ //期初
                tableNames.add("data_kcgl_cplqckc_default");
            }
            if (StrUtil.equals("cpl.kcbd",topic)){ //库存变动
                tableNames.add("data_kcgl_cplkcbd_default");
                tableNames.add("data_kcgl_cplkcsw_default");
                tableNames.add("data_kcgl_cplxckc_default");
                tableNames.add("data_kcgl_cplfcbgz_default");
            }
            //原粮
            if (StrUtil.equals("yuliang.rk",topic)){ //入库
                tableNames.add("bizflowtrail");
                tableNames.add("data_crkyw_cmz_default");
                tableNames.add("data_crkyw_cpz_default");
                tableNames.add("data_crkyw_zc_default");
                tableNames.add("data_crkyw_jsxx_default");
                tableNames.add("data_crkyw_jyxx_default");
                tableNames.add("data_crkyw_jyxx_flt_001");
                tableNames.add("data_crkyw_qyxx_default");
                tableNames.add("data_crkyw_rkcm_default");
                tableNames.add("data_crkyw_rkdj_default");
            }
            if (StrUtil.equals("yuliang.ck",topic)){ //出库
                tableNames.add("bizflowtrail");
                tableNames.add("data_crkyw_ckcm_default");
                tableNames.add("data_crkyw_ckcmz_default");
                tableNames.add("data_crkyw_zc_default");
                tableNames.add("data_crkyw_ckcpz_default");
                tableNames.add("data_crkyw_ckrmdj_default");
            }
            if (StrUtil.equals("yuliang.kcbd",topic)){ //库存变动
                tableNames.add("data_kcgl_kcbd_default");
                tableNames.add("data_kcgl_fcbgz_default");
                tableNames.add("data_kcgl_kcsw_default");
                tableNames.add("data_kcgl_xckc_default");

            }
            if (StrUtil.equals("yuliang.qc",topic)){ //期初
                tableNames.add("data_kcgl_qckc_default");
            }
            if (StrUtil.equals("yuliang.tzd",topic)){ //通知单
                tableNames.add("data_crkyw_tzdxx_default");
                tableNames.add("data_crkyw_tzdxx_flt_001");
            }
/*            if (StrUtil.equals("other",topic)){

                //成品粮
                tableNames.add("data_kcgl_cplkcsw_default");
                tableNames.add("data_kcgl_cplxckc_default");
                tableNames.add("data_kcgl_cplfcbgz_default");
                //原粮
                tableNames.add("data_kcgl_fcbgz_default");
                tableNames.add("data_kcgl_kcsw_default");
                tableNames.add("data_kcgl_xckc_default");
            }*/
        }
        QueryWrapper<DeleteDataRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.isNull("UPLOAD_TIME"); //上传时间为空
        queryWrapper.orderByDesc("DELETE_TIME");
        queryWrapper.last(limit);
        List<DeleteDataRecord> list = deleteDataRecordService.list(queryWrapper);
        if (list.size() > 0){
            for (int i = 0; i <list.size() ; i++) {
                DeleteDataRecord deleteDataRecord = list.get(i);
                JSONObject data = new JSONObject();
                data.put("table",deleteDataRecord.getTableName());
                data.put("opt","del");
                data.put("dataInfo",deleteDataRecord.getDataid());
                data.put("unitid",deleteDataRecord.getUnitid());
                datas.add(data);
            }
        }

        return list;
    }
    }


    private StringBuilder getUpSjzxloadDataCplrk(String unitId, String limit, JSONArray datas, StringBuilder operatlog){
        //成品粮入库
        QueryWrapper<DataCrkywCplrkDefault> cplrkQueryWrapper = new QueryWrapper<>();
        cplrkQueryWrapper.eq("unitid",unitId);
        cplrkQueryWrapper.isNull("updateTime"); //上传时间为空
        cplrkQueryWrapper.eq("isstaging",'1');//查询正式保存为1的数据
        cplrkQueryWrapper.last(limit);
        List<DataCrkywCplrkDefault> cplrkList = dataCrkywCplrkDefaultService.list(cplrkQueryWrapper);
        if (cplrkList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cplrk_default");
            data.put("opt","add");
            data.put("dataInfo",cplrkList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_cplrk_default").append(cplrkList.size()).append("条;");


        //成品粮入库从表
        QueryWrapper<DataCrkywCplrkFlt001> cplrkFltQueryWrapper = new QueryWrapper<>();
        cplrkFltQueryWrapper.eq("unitid",unitId);
        cplrkFltQueryWrapper.isNull("updateTime"); //上传时间为空
        cplrkFltQueryWrapper.eq("isstaging",'1');//查询正式保存为1的数据
        cplrkFltQueryWrapper.last(limit);
        List<DataCrkywCplrkFlt001> cplrkFltList = dataCrkywCplrkFlt001Service.list(cplrkFltQueryWrapper);
        if (cplrkFltList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cplrk_flt_001");
            data.put("opt","add");
            data.put("dataInfo",cplrkFltList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_cplrk_flt_001").append(cplrkFltList.size()).append("条;");
        return operatlog;
    }
    private StringBuilder getUpSjzxloadDataCplck(String unitId, String limit, JSONArray datas, StringBuilder operatlog){
        //成品粮出主表
        QueryWrapper<DataCrkywCplckDefault> dataCrkywCplckQueryWrapper = new QueryWrapper<>();
        dataCrkywCplckQueryWrapper.eq("unitid",unitId);
        dataCrkywCplckQueryWrapper.isNull("updateTime"); //上传时间为空
        dataCrkywCplckQueryWrapper.eq("isstaging",'1');//查询正式保存为1的数据
        dataCrkywCplckQueryWrapper.last(limit);
        List<DataCrkywCplckDefault> cplckList = dataCrkywCplckDefaultService.list(dataCrkywCplckQueryWrapper);
        if (cplckList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cplck_default");
            data.put("opt","add");
            data.put("dataInfo",cplckList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_cplck_default").append(cplckList.size()).append("条;");


        //成品粮出库从表
        QueryWrapper<DataCrkywCplckFlt001> dataCrkywCplckFltQueryWrapper = new QueryWrapper<>();
        dataCrkywCplckFltQueryWrapper.eq("unitid",unitId);
        dataCrkywCplckFltQueryWrapper.isNull("updateTime"); //上传时间为空
        dataCrkywCplckFltQueryWrapper.eq("isstaging",'1');//查询正式保存为1的数据
        dataCrkywCplckFltQueryWrapper.last(limit);
        List<DataCrkywCplckFlt001> cplckFltList = dataCrkywCplckFlt001Service.list(dataCrkywCplckFltQueryWrapper);
        if (cplckFltList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cplck_flt_001");
            data.put("opt","add");
            data.put("dataInfo",cplckFltList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_cplck_flt_001").append(cplckFltList.size()).append("条;");
        return operatlog;
    }

    private StringBuilder getUpSjzxloadData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean b,String tableNames) {

        if(StrUtil.isBlank(tableNames)){
            //成品粮
            uploadJsSjzxcplTzdData(unitId,limit,datas,operatlog,b);
            uploadJsSjzxTzdData(unitId,limit,datas,operatlog,b);
            uploadJsSjzxCplCkData(unitId,limit,datas,operatlog,b);
            uploadJsSjzxCplRkData(unitId,limit,datas,operatlog,b);
            uploadJsSjzxCplZjData(unitId,limit,datas,operatlog,b);
            uploadJsSjzxCplPfData(unitId,limit,datas,operatlog,b);
            uploadJsSjzxCplQckcData(unitId,limit,datas,operatlog,b);
            uploadJsSjzxCplKcData(unitId,limit,datas,operatlog,b);
            uploadJsSjzxCplKcbdData(unitId,limit,datas,operatlog,b);
            uploadJsSjzxCplbjdyData(unitId,limit,datas,operatlog,b);
            uploadJsSjzxCplYbgnData(unitId,limit,datas,operatlog,b);
            uploadJsSjzxCplFjData(unitId,limit,datas,operatlog,b);
            //原粮
            uploadJsSjzxRkData(unitId,limit,datas,operatlog,b);
            uploadJsSjzxlCkData(unitId,limit,datas,operatlog,b);
            uploadJsSjzxKcData(unitId,limit,datas,operatlog,b);
            uploadJsSjzxKcbdData(unitId,limit,datas,operatlog,b);
            uploadJsSjzxTzzdData(unitId,limit,datas,operatlog,b);
            uploadJsSjzxQckcData(unitId,limit,datas,operatlog,b);
            //字典数据
            uploadJsSjzxEnumData(unitId,limit,datas,operatlog,b);
            //商品
            uploadJsSjspData(unitId,limit,datas,operatlog,b);
            //附件
            uploadJsSjattachesData(unitId,limit,datas,operatlog,b);
        }else{
            //成品粮
            if(tableNames.contains(TableNames.cpltzdxx) || tableNames.contains(TableNames.cpltzdxxFlt)){
                uploadJsSjzxcplTzdData(unitId,limit,datas,operatlog,b);
            }
            if(tableNames.contains(TableNames.tzdxx) || tableNames.contains(TableNames.tzdxxFlt)){
                uploadJsSjzxTzdData(unitId,limit,datas,operatlog,b);
            }
            if(tableNames.contains(TableNames.cplck)){
                uploadJsSjzxCplCkData(unitId,limit,datas,operatlog,b);
            }
            if(tableNames.contains(TableNames.cplrk)){
                uploadJsSjzxCplRkData(unitId,limit,datas,operatlog,b);
            }
            if(tableNames.contains(TableNames.cpljyxx) || tableNames.contains(TableNames.cpljyxxFlt)){
                uploadJsSjzxCplZjData(unitId,limit,datas,operatlog,b);
            }
            if(tableNames.contains(TableNames.cplpf)){
                uploadJsSjzxCplPfData(unitId,limit,datas,operatlog,b);
            }
            if(tableNames.contains(TableNames.cplqckc)){
                uploadJsSjzxCplQckcData(unitId,limit,datas,operatlog,b);
            }
            if(tableNames.contains(TableNames.cplkcsw) ||tableNames.contains(TableNames.cplxckc) ||tableNames.contains(TableNames.cplfcbgz) ){
                uploadJsSjzxCplKcData(unitId,limit,datas,operatlog,b);
            }
            if(tableNames.contains(TableNames.cplkcbd)){
                uploadJsSjzxCplKcbdData(unitId,limit,datas,operatlog,b);
            }
            if(tableNames.contains(TableNames.cplbjdy)){
                uploadJsSjzxCplbjdyData(unitId,limit,datas,operatlog,b);
            }
            if( tableNames.contains(TableNames.nventoryAdjustment) || tableNames.contains(TableNames.ollectionReview) ||tableNames.contains(TableNames.settlementManagement) ||tableNames.contains(TableNames.ehicle) ||tableNames.contains(TableNames.commoditySplitting) ||tableNames.contains(TableNames.personnel)){
                uploadJsSjzxCplYbgnData(unitId,limit,datas,operatlog,b);
            }
            if( tableNames.contains(TableNames.cplfj) || tableNames.contains(TableNames.cplfjFlt)){
                uploadJsSjzxCplFjData(unitId,limit,datas,operatlog,b);
            }
            //原粮出入库中传入出门表即可上传整个流程数据
            if(tableNames.contains(TableNames.ckcm)){
                uploadJsSjzxlCkData(unitId,limit,datas,operatlog,b);
            }
            if(tableNames.contains(TableNames.rkcm)){
                uploadJsSjzxlCkData(unitId,limit,datas,operatlog,b);
            }
            if(tableNames.contains(TableNames.kcbd)){
                uploadJsSjzxKcbdData(unitId,limit,datas,operatlog,b);
            }
            if(tableNames.contains(TableNames.kcsw)){
                uploadJsSjzxKcData(unitId,limit,datas,operatlog,b);
            }
            if(tableNames.contains(TableNames.qckc)){
                uploadJsSjzxQckcData(unitId,limit,datas,operatlog,b);
            }
            if(tableNames.contains(TableNames.tzdxx)){
                uploadJsSjzxTzzdData(unitId,limit,datas,operatlog,b);
            }
            if(tableNames.contains(TableNames.baseEnum)){
                //字典数据
                uploadJsSjzxEnumData(unitId,limit,datas,operatlog,b);
            }
            if(tableNames.contains(TableNames.attaches)){
                //文件
                uploadJsSjattachesData(unitId,limit,datas,operatlog,b);
            }
            if(tableNames.contains(TableNames.cplSp)){
                //商品
                uploadJsSjspData(unitId,limit,datas,operatlog,b);
            }
        }
        return operatlog;

    }
    private StringBuilder getUpSjzxloadDataByTopic(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean b,String topic) {

            //成品粮
            if (StrUtil.equals("cpl.tzd",topic)){ //通知单
                uploadJsSjzxcplTzdData(unitId,limit,datas,operatlog,b);
                return operatlog;
            }
            if (StrUtil.equals("cpl.rk",topic)){ //入库
                uploadJsSjzxCplRkData(unitId,limit,datas,operatlog,b);
//                uploadJsSjzxCplKcData(unitId,limit,datas,operatlog,b);
                return operatlog;
            }
            if (StrUtil.equals("cpl.ck",topic)){ //出库
                uploadJsSjzxCplCkData(unitId,limit,datas,operatlog,b);
//                uploadJsSjzxCplKcData(unitId,limit,datas,operatlog,b);
                return operatlog;
            }
            if (StrUtil.equals("cpl.zj",topic)){ //化验
                uploadJsSjzxCplZjData(unitId,limit,datas,operatlog,b);
                return operatlog;
            }
            if (StrUtil.equals("cpl.qc",topic)){ //期初
                uploadJsSjzxCplQckcData(unitId,limit,datas,operatlog,b);
//                uploadJsSjzxCplKcData(unitId,limit,datas,operatlog,b);
                return operatlog;
            }
            if (StrUtil.equals("cpl.kcbd",topic)){ //库存变动
                uploadJsSjzxCplKcbdData(unitId,limit,datas,operatlog,b);
                uploadJsSjzxCplKcData(unitId,limit,datas,operatlog,b);

                return operatlog;
            }

        if (StrUtil.equals("cpl.pf",topic)){ //评分
            uploadJsSjzxCplPfData(unitId,limit,datas,operatlog,b);
//                uploadJsSjzxCplKcData(unitId,limit,datas,operatlog,b);
            return operatlog;
        }

            //原粮
            if (StrUtil.equals("yuliang.rk",topic)){ //入库
                uploadJsSjzxRkData(unitId,limit,datas,operatlog,b);
//                uploadJsSjzxKcData(unitId,limit,datas,operatlog,b);
                return operatlog;
            }
            if (StrUtil.equals("yuliang.ck",topic)){ //出库
                uploadJsSjzxlCkData(unitId,limit,datas,operatlog,b);
//                uploadJsSjzxKcData(unitId,limit,datas,operatlog,b);
                return operatlog;
            }
            if (StrUtil.equals("yuliang.kcbd",topic)){ //库存变动
                uploadJsSjzxKcbdData(unitId,limit,datas,operatlog,b);
                uploadJsSjzxKcData(unitId,limit,datas,operatlog,b);
                return operatlog;
            }
        if (StrUtil.equals("yuliang.qc",topic)){ //期初
                uploadJsSjzxQckcData(unitId,limit,datas,operatlog,b);
                return operatlog;
            }
            if (StrUtil.equals("yuliang.tzd",topic)){ //通知单
                uploadJsSjzxTzzdData(unitId,limit,datas,operatlog,b);
                uploadJsSjzxKcData(unitId,limit,datas,operatlog,b);
                return operatlog;
            }
            if (StrUtil.equals("other",topic)){

                //成品粮
                uploadJsSjzxCplKcData(unitId,limit,datas,operatlog,b);
                uploadJsSjzxKcData(unitId,limit,datas,operatlog,b);

            }
            if (StrUtil.equals("all",topic)){
                    //成品粮
                    uploadJsSjzxcplTzdData(unitId,limit,datas,operatlog,b);
                    uploadJsSjzxCplCkData(unitId,limit,datas,operatlog,b);
                    uploadJsSjzxTzdData(unitId,limit,datas,operatlog,b);
                    uploadJsSjzxCplRkData(unitId,limit,datas,operatlog,b);
                    uploadJsSjzxCplZjData(unitId,limit,datas,operatlog,b);
                    uploadJsSjzxCplPfData(unitId,limit,datas,operatlog,b);
                    uploadJsSjzxCplQckcData(unitId,limit,datas,operatlog,b);
                    uploadJsSjzxCplKcData(unitId,limit,datas,operatlog,b);
                    uploadJsSjzxCplKcbdData(unitId,limit,datas,operatlog,b);
                    uploadJsSjzxCplbjdyData(unitId,limit,datas,operatlog,b);
                    uploadJsSjzxCplYbgnData(unitId,limit,datas,operatlog,b);
                    uploadJsSjzxCplFjData(unitId,limit,datas,operatlog,b);
                    //原粮
                    uploadJsSjzxRkData(unitId,limit,datas,operatlog,b);
                    uploadJsSjzxKcData(unitId,limit,datas,operatlog,b);
                    uploadJsSjzxlCkData(unitId,limit,datas,operatlog,b);
                    uploadJsSjzxKcbdData(unitId,limit,datas,operatlog,b);
                    uploadJsSjzxTzzdData(unitId,limit,datas,operatlog,b);
                    uploadJsSjzxQckcData(unitId,limit,datas,operatlog,b);
                    //字典数据
                    uploadJsSjzxEnumData(unitId,limit,datas,operatlog,b);
                    //商品
                    uploadJsSjspData(unitId,limit,datas,operatlog,b);
                    //附件
                    uploadJsSjattachesData(unitId,limit,datas,operatlog,b);
            }
        return operatlog;

    }



    /**
     * 上传成品粮订单主从表
     * @param unitId 单位ID
     * @param limit 条数
     * @param datas
     * @param operatlog
     * @return
     */
    @Override
    public StringBuilder uploadJsSjzxcplTzdData(String unitId, String limit, JSONArray datas, StringBuilder operatlog,boolean isNull) {

        //成品订单主表
        QueryWrapper<DataCrkywCpltzdxxDefault> dataCrkywCpltzdxxQueryWrapper = new QueryWrapper<>();
        dataCrkywCpltzdxxQueryWrapper.eq("unitid",unitId);
        if (isNull)dataCrkywCpltzdxxQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataCrkywCpltzdxxQueryWrapper.last(limit);
        List<DataCrkywCpltzdxxDefault> cpltzdxxList = dataCrkywCpltzdxxDefaultService.list(dataCrkywCpltzdxxQueryWrapper);
        if (cpltzdxxList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cpltzdxx_default");
            data.put("opt","add");
            data.put("dataInfo",cpltzdxxList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_cpltzdxx_default").append(cpltzdxxList.size()).append("条;");


        //成品订单从表
        QueryWrapper<DataCrkywCpltzdxxFlt001> dataCrkywCpltzdxxFltQueryWrapper = new QueryWrapper<>();
        dataCrkywCpltzdxxFltQueryWrapper.eq("unitid",unitId);
        if (isNull)dataCrkywCpltzdxxFltQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataCrkywCpltzdxxFltQueryWrapper.last(limit);
        List<DataCrkywCpltzdxxFlt001> cpltzdxxFlt = dataCrkywCpltzdxxFlt001Service.list(dataCrkywCpltzdxxFltQueryWrapper);
        if (cpltzdxxFlt.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cpltzdxx_flt_001");
            data.put("opt","add");
            data.put("dataInfo",cpltzdxxFlt);
            datas.add(data);
        }
        operatlog.append("data_crkyw_cpltzdxx_flt_001").append(cpltzdxxFlt.size()).append("条;");
        return operatlog;
    }

    /**
     * 原粮订单粮上传数据
     * @param unitId 单位ID
     * @param limit 条数
     * @param datas
     * @param operatlog
     * @return
     */
    @Override
    public StringBuilder uploadJsSjzxTzdData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {

        QueryWrapper<DataCrkywTzdxxDefault> tzdxxQueryWrapper = new QueryWrapper<>();

        if(StrUtil.isNotBlank(unitId)){
            tzdxxQueryWrapper.eq("UnitID",unitId);
        }
        if(isNull) {
            tzdxxQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        }
        tzdxxQueryWrapper.last(limit);
        List<DataCrkywTzdxxDefault> tzdxxList = dataCrkywTzdxxDefaultService.list(tzdxxQueryWrapper);
        if (tzdxxList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_tzdxx_default");
            data.put("opt","add");
            data.put("dataInfo",tzdxxList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_tzdxx_default").append(tzdxxList.size()).append("条;");
        return operatlog;
    }

    /**
     * 成品粮出库
     * @param unitId 单位ID
     * @param limit 条数
     * @param datas
     * @param operatlog
     * @param isNull 上传时间是否为空
     * @return
     */
    @Override
    public StringBuilder uploadJsSjzxCplCkData(String unitId, String limit, JSONArray datas, StringBuilder operatlog,boolean isNull) {
        //成品粮出主表
        QueryWrapper<DataCrkywCplckDefault> dataCrkywCplckQueryWrapper = new QueryWrapper<>();
        dataCrkywCplckQueryWrapper.eq("unitid",unitId);
        dataCrkywCplckQueryWrapper.eq("isstaging",'1');//查询正式保存为1的数据
        if (isNull){
            dataCrkywCplckQueryWrapper.isNull("updateTime");
        }//上传时间为空
        dataCrkywCplckQueryWrapper.last(limit);
        List<DataCrkywCplckDefault> cplckList = dataCrkywCplckDefaultService.list(dataCrkywCplckQueryWrapper);
        if (cplckList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cplck_default");
            data.put("opt","add");
            data.put("dataInfo",cplckList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_cplck_default").append(cplckList.size()).append("条;");


        //成品粮出库从表
        QueryWrapper<DataCrkywCplckFlt001> dataCrkywCplckFltQueryWrapper = new QueryWrapper<>();
        dataCrkywCplckFltQueryWrapper.eq("unitid",unitId);
        dataCrkywCplckFltQueryWrapper.eq("isstaging",'1');//查询正式保存为1的数据
        if (isNull){
            dataCrkywCplckFltQueryWrapper.isNull("updateTime");
        }; //上传时间为空
        dataCrkywCplckFltQueryWrapper.last(limit);
        List<DataCrkywCplckFlt001> cplckFltList = dataCrkywCplckFlt001Service.list(dataCrkywCplckFltQueryWrapper);
        if (cplckFltList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cplck_flt_001");
            data.put("opt","add");
            data.put("dataInfo",cplckFltList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_cplck_flt_001").append(cplckFltList.size()).append("条;");
        return operatlog;
    }

    /**
     * 成品粮入库主从表数据
     * @param unitId 单位ID
     * @param limit 条数
     * @param datas
     * @param operatlog
     * @param isNull 上传时间是否为空
     * @return
     */
    @Override
    public StringBuilder uploadJsSjzxCplRkData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {
        //成品粮入库
        QueryWrapper<DataCrkywCplrkDefault> cplrkQueryWrapper = new QueryWrapper<>();
        cplrkQueryWrapper.eq("unitid",unitId);
        cplrkQueryWrapper.eq("isstaging",'1');//查询正式保存为1的数据
        if (isNull) {
            cplrkQueryWrapper.isNull("updateTime");
        } //上传时间为空
        cplrkQueryWrapper.last(limit);
        List<DataCrkywCplrkDefault> cplrkList = dataCrkywCplrkDefaultService.list(cplrkQueryWrapper);
        if (cplrkList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cplrk_default");
            data.put("opt","add");
            data.put("dataInfo",cplrkList);
            datas.add(data);
        }
        System.out.println("入库数据："+unitId+cplrkList);
        operatlog.append("data_crkyw_cplrk_default").append(cplrkList.size()).append("条;");


        //成品粮入库从表
        QueryWrapper<DataCrkywCplrkFlt001> cplrkFltQueryWrapper = new QueryWrapper<>();
        cplrkFltQueryWrapper.eq("unitid",unitId);
        cplrkFltQueryWrapper.eq("isstaging",'1');//查询正式保存为1的数据
        if (isNull){
            cplrkFltQueryWrapper.isNull("updateTime"); //上传时间为空
        }
        cplrkFltQueryWrapper.last(limit);
        List<DataCrkywCplrkFlt001> cplrkFltList = dataCrkywCplrkFlt001Service.list(cplrkFltQueryWrapper);
        if (cplrkFltList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cplrk_flt_001");
            data.put("opt","add");
            data.put("dataInfo",cplrkFltList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_cplrk_flt_001").append(cplrkFltList.size()).append("条;");
        return operatlog;
    }

    /**
     * 成品粮入库质检主从表数据
     * @param unitId 单位ID
     * @param limit 条数
     * @param datas
     * @param operatlog
     * @param isNull 上传时间是否为空
     * @return
     */
    @Override
    public StringBuilder uploadJsSjzxCplZjData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {
        //成品粮质检主表
        QueryWrapper<DataCrkywCpljyxxDefault> jyxxDefaultQueryWrapper = new QueryWrapper<>();
        jyxxDefaultQueryWrapper.eq("unitid",unitId);
        if (isNull) jyxxDefaultQueryWrapper.isNull("updateTime"); //上传时间为空
        jyxxDefaultQueryWrapper.last(limit);
        List<DataCrkywCpljyxxDefault> cpljyxxList = dataCrkywCpljyxxDefaultService.list(jyxxDefaultQueryWrapper);
        if (cpljyxxList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cpljyxx_default");
            data.put("opt","add");
            data.put("dataInfo",cpljyxxList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_cpljyxx_default").append(cpljyxxList.size()).append("条;");


        //成品粮质检从表
        QueryWrapper<DataCrkywCpljyxxFlt001> jyxxFltQueryWrapper = new QueryWrapper<>();
        jyxxFltQueryWrapper.eq("unitid",unitId);
        if (isNull)jyxxFltQueryWrapper.isNull("updateTime"); //上传时间为空
        jyxxFltQueryWrapper.last(limit);
        List<DataCrkywCpljyxxFlt001> cpljyxxFltList = dataCrkywCpljyxxFlt001Service.list(jyxxFltQueryWrapper);
        if (cpljyxxFltList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cpljyxx_flt_001");
            data.put("opt","add");
            data.put("dataInfo",cpljyxxFltList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_cpljyxx_flt_001").append(cpljyxxFltList.size()).append("条;");
        return operatlog;
    }

    @Override
    public StringBuilder uploadJsSjzxCplPfData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {
        //成品粮评分
        QueryWrapper<DataCrkywCplpfDefault> dataCrkywCplpfQueryWrapper = new QueryWrapper<>();
        dataCrkywCplpfQueryWrapper.eq("unitid",unitId);
        if (isNull)dataCrkywCplpfQueryWrapper.isNull("updateTime"); //上传时间为空
        dataCrkywCplpfQueryWrapper.last(limit);
        List<DataCrkywCplpfDefault> cplpfList = dataCrkywCplpfDefaultService.list(dataCrkywCplpfQueryWrapper);
        if (cplpfList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cplpf_default");
            data.put("opt","add");
            data.put("dataInfo",cplpfList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_cplpf_default").append(cplpfList.size()).append("条;");
        return operatlog;
    }

    /**
     * 上传成品期初数据
     * @param unitId 单位ID
     * @param limit 条数
     * @param datas
     * @param operatlog
     * @param isNull 上传时间是否为空
     * @return
     */
    @Override
    public StringBuilder uploadJsSjzxCplQckcData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {
        //成品粮期初库存
        QueryWrapper<DataKcglCplqckcDefault> dataKcglCplqckcQueryWrapper = new QueryWrapper<>();
        dataKcglCplqckcQueryWrapper.eq("unitid",unitId);
        if (isNull)dataKcglCplqckcQueryWrapper.isNull("updateTime"); //上传时间为空
        dataKcglCplqckcQueryWrapper.eq("isstaging",'1');//查询正式保存为1的数据
        dataKcglCplqckcQueryWrapper.last(limit);
        List<DataKcglCplqckcDefault> cplqckcList = dataKcglCplqckcDefaultService.list(dataKcglCplqckcQueryWrapper);
        if (cplqckcList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_kcgl_cplqckc_default");
            data.put("opt","add");
            data.put("dataInfo",cplqckcList);
            datas.add(data);
        }
        operatlog.append("data_kcgl_cplqckc_default").append(cplqckcList.size()).append("条;");
        return operatlog;
    }

    /**
     * 上传成品库存(库存实物、分仓保管账、形成库存)数据
     * @param unitId 单位ID
     * @param limit 条数
     * @param datas
     * @param operatlog
     * @param isNull 上传时间是否为空
     * @return
     */
    @Override
    public StringBuilder uploadJsSjzxCplKcData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {
        //成品粮库存实物
        QueryWrapper<DataKcglCplkcswDefault> dataKcglCplkcswQueryWrapper = new QueryWrapper<>();
        dataKcglCplkcswQueryWrapper.eq("unitid",unitId);
        if (isNull)dataKcglCplkcswQueryWrapper.isNull("updateTime"); //上传时间为空
        dataKcglCplkcswQueryWrapper.last(limit);
        List<DataKcglCplkcswDefault> cplkcswList = dataKcglCplkcswDefaultService.list(dataKcglCplkcswQueryWrapper);
        if (cplkcswList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_kcgl_cplkcsw_default");
            data.put("opt","add");
            data.put("dataInfo",cplkcswList);
            datas.add(data);
        }
        operatlog.append("data_kcgl_cplkcsw_default").append(cplkcswList.size()).append("条;");
        //成品粮库形成库存
        QueryWrapper<DataKcglCplxckcDefault> dataKcglCplxckcQueryWrapper = new QueryWrapper<>();
        dataKcglCplxckcQueryWrapper.eq("unitid",unitId);
        if (isNull)dataKcglCplxckcQueryWrapper.isNull("updateTime"); //上传时间为空
        dataKcglCplxckcQueryWrapper.last(limit);
        List<DataKcglCplxckcDefault> cplxckcList = dataKcglCplxckcDefaultService.list(dataKcglCplxckcQueryWrapper);
        if (cplxckcList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_kcgl_cplxckc_default");
            data.put("opt","add");
            data.put("dataInfo",cplxckcList);
            datas.add(data);
        }
        operatlog.append("data_kcgl_cplxckc_default").append(cplxckcList.size()).append("条;");

        //成品粮分仓保管账
        QueryWrapper<DataKcglCplfcbgzDefault> dataKcglCplfcbgzQueryWrapper = new QueryWrapper<>();
        dataKcglCplfcbgzQueryWrapper.eq("unitid",unitId);
        if (isNull)dataKcglCplfcbgzQueryWrapper.isNull("updateTime"); //上传时间为空
        dataKcglCplfcbgzQueryWrapper.last(limit);
        List<DataKcglCplfcbgzDefault> cplfcbgzList = dataKcglCplfcbgzDefaultService.list(dataKcglCplfcbgzQueryWrapper);
        if (cplfcbgzList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_kcgl_cplfcbgz_default");
            data.put("opt","add");
            data.put("dataInfo",cplfcbgzList);
            datas.add(data);
        }
        operatlog.append("data_kcgl_cplfcbgz_default").append(cplfcbgzList.size()).append("条;");
        return operatlog;
    }

    /**
     * 成品粮库存变动
     * @param unitId 单位ID
     * @param limit 条数
     * @param datas
     * @param operatlog
     * @param isNull 上传时间是否为空
     * @return
     */
    @Override
    public StringBuilder uploadJsSjzxCplKcbdData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {
        //成品粮库存变动
        QueryWrapper<DataKcglCplkcbdDefault> dataKcglCplkcbdQueryWrapper = new QueryWrapper<>();
        dataKcglCplkcbdQueryWrapper.eq("unitid",unitId);
        if (isNull)dataKcglCplkcbdQueryWrapper.isNull("updateTime"); //上传时间为空
        dataKcglCplkcbdQueryWrapper.eq("isstaging",'1');//查询正式保存为1的数据
        dataKcglCplkcbdQueryWrapper.last(limit);
        List<DataKcglCplkcbdDefault> cplkcbdList = dataKcglCplkcbdDefaultService.list(dataKcglCplkcbdQueryWrapper);
        if (cplkcbdList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_kcgl_cplkcbd_default");
            data.put("opt","add");
            data.put("dataInfo",cplkcbdList);
            datas.add(data);
        }
        operatlog.append("data_kcgl_cplkcbd_default").append(cplkcbdList.size()).append("条;");
        return operatlog;
    }

    /**
     * 成品粮标签打印
     * @param unitId 单位ID
     * @param limit 条数
     * @param datas
     * @param operatlog
     * @param isNull 上传时间是否为空
     * @return
     */
    @Override
    public StringBuilder uploadJsSjzxCplbjdyData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {
        QueryWrapper<DataCrkywCplbjdyDefault> dataCrkywCplbjdyQueryWrapper = new QueryWrapper<>();
        dataCrkywCplbjdyQueryWrapper.eq("unitid",unitId);
        if (isNull)dataCrkywCplbjdyQueryWrapper.isNull("updateTime"); //上传时间为空
        dataCrkywCplbjdyQueryWrapper.last(limit);
        List<DataCrkywCplbjdyDefault> cplbjdyList = dataCrkywCplbjdyDefaultService.list(dataCrkywCplbjdyQueryWrapper);
        if (cplbjdyList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cplbjdy_default");
            data.put("opt","add");
            data.put("dataInfo",cplbjdyList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_cplbjdy_default").append(cplbjdyList.size()).append("条;");
        return operatlog;
    }

    /**
     * 上传成品粮应标功能（商品拆分、商品领用、库存调整、人员调度，车辆调度）数据
     * @param unitId 单位ID
     * @param limit 条数
     * @param datas
     * @param operatlog
     * @param isNull 上传时间是否为空
     * @return
     */
    @Override
    public StringBuilder uploadJsSjzxCplYbgnData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {
        //成品商品拆分
        QueryWrapper<SettlementManagement> settlementManagementQueryWrapper = new QueryWrapper<>();
        settlementManagementQueryWrapper.eq("unitid",unitId);
        if (isNull)settlementManagementQueryWrapper.isNull("updateTime"); //上传时间为空
        settlementManagementQueryWrapper.last(limit);
        List<SettlementManagement> settlementManagementList = settlementManagementService.list(settlementManagementQueryWrapper);
        if (settlementManagementList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","settlement_management");
            data.put("opt","add");
            data.put("dataInfo",settlementManagementList);
            datas.add(data);
        }
        operatlog.append("settlement_management").append(settlementManagementList.size()).append("条;");


        //成品商品领用
        QueryWrapper<OllectionReview> ollectionReviewQueryWrapper = new QueryWrapper<>();
        ollectionReviewQueryWrapper.eq("unitid",unitId);
        if (isNull)ollectionReviewQueryWrapper.isNull("updateTime"); //上传时间为空
        ollectionReviewQueryWrapper.last(limit);
        List<OllectionReview> ollectionReviewList = ollectionReviewService.list(ollectionReviewQueryWrapper);
        if (ollectionReviewList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","ollection_review");
            data.put("opt","add");
            data.put("dataInfo",ollectionReviewList);
            datas.add(data);
        }
        operatlog.append("ollection_review").append(ollectionReviewList.size()).append("条;");

        //成品商品库存调整
        QueryWrapper<NventoryAdjustment> nventoryAdjustmentQueryWrapper = new QueryWrapper<>();
        nventoryAdjustmentQueryWrapper.eq("unitid",unitId);
        if (isNull)nventoryAdjustmentQueryWrapper.isNull("updateTime"); //上传时间为空
        nventoryAdjustmentQueryWrapper.last(limit);
        List<NventoryAdjustment> nventoryAdjustmentList = nventoryAdjustmentService.list(nventoryAdjustmentQueryWrapper);
        if (nventoryAdjustmentList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","nventory_adjustment");
            data.put("opt","add");
            data.put("dataInfo",nventoryAdjustmentList);
            datas.add(data);
        }
        operatlog.append("nventory_adjustment").append(nventoryAdjustmentList.size()).append("条;");

        //人员调度管理
        QueryWrapper<DispatcPersonnelManagement> dispatcPersonnelManagementQueryWrapper = new QueryWrapper<>();
        dispatcPersonnelManagementQueryWrapper.eq("unitid",unitId);
        if (isNull) dispatcPersonnelManagementQueryWrapper.isNull("updateTime"); //上传时间为空
        dispatcPersonnelManagementQueryWrapper.last(limit);
        List<DispatcPersonnelManagement> dispatcPersonnelManagementList = dispatcPersonnelManagementService.list(dispatcPersonnelManagementQueryWrapper);
        if (dispatcPersonnelManagementList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","dispatc_personnel_management");
            data.put("opt","add");
            data.put("dataInfo",dispatcPersonnelManagementList);
            datas.add(data);
        }
        operatlog.append("dispatc_personnel_management").append(dispatcPersonnelManagementList.size()).append("条;");

        //车辆调度管理
        QueryWrapper<DispatchEhicleManagement> dispatchEhicleManagementQueryWrapper = new QueryWrapper<>();
        dispatchEhicleManagementQueryWrapper.eq("unitid",unitId);
        if (isNull) dispatchEhicleManagementQueryWrapper.isNull("updateTime"); //上传时间为空
        dispatchEhicleManagementQueryWrapper.last(limit);
        List<DispatchEhicleManagement> dispatchEhicleManagementList = dispatchEhicleManagementService.list(dispatchEhicleManagementQueryWrapper);
        if (dispatchEhicleManagementList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","dispatch_ehicle_management");
            data.put("opt","add");
            data.put("dataInfo",dispatchEhicleManagementList);
            datas.add(data);
        }
        operatlog.append("dispatch_ehicle_management").append(dispatchEhicleManagementList.size()).append("条;");
        return operatlog;
    }

    /**
     * 上传原粮入库
     * @param unitId 单位ID
     * @param limit 条数
     * @param datas
     * @param operatlog
     * @param isNull 上传时间是否为空
     * @return
     */
    @Override
    public StringBuilder uploadJsSjzxRkData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {
        //原粮流程规律表
        QueryWrapper<Bizflowtrail> bizflowtrailQueryWrapper = new QueryWrapper<>();
        bizflowtrailQueryWrapper.eq("unitid",unitId);
        if (isNull) bizflowtrailQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        bizflowtrailQueryWrapper.last(limit);
        List<Bizflowtrail> bizflowtrailList = bizflowtrailService.list(bizflowtrailQueryWrapper);
        if (bizflowtrailList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","bizflowtrail");
            data.put("opt","add");
            data.put("dataInfo",bizflowtrailList);
            datas.add(data);
        }
        operatlog.append("bizflowtrail").append(bizflowtrailList.size()).append("条;");

        //原粮汽车入库-称毛重
        QueryWrapper<DataCrkywCmzDefault> dataCrkywCmzQueryWrapper = new QueryWrapper<>();
        dataCrkywCmzQueryWrapper.eq("unitid",unitId);
        if (isNull)dataCrkywCmzQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataCrkywCmzQueryWrapper.last(limit);
        List<DataCrkywCmzDefault> cmzList = dataCrkywCmzDefaultService.list(dataCrkywCmzQueryWrapper);
        if (cmzList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cmz_default");
            data.put("opt","add");
            data.put("dataInfo",cmzList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_cmz_default").append(cmzList.size()).append("条;");

        //原粮汽车入库-称皮重
        QueryWrapper<DataCrkywCpzDefault> dataCrkywCpzQueryWrapper = new QueryWrapper<>();
        dataCrkywCpzQueryWrapper.eq("unitid",unitId);
        if (isNull)dataCrkywCpzQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataCrkywCpzQueryWrapper.last(limit);
        List<DataCrkywCpzDefault> cpzList = dataCrkywCpzDefaultService.list(dataCrkywCpzQueryWrapper);
        if (cpzList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cpz_default");
            data.put("opt","add");
            data.put("dataInfo",cpzList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_cpz_default").append(cpzList.size()).append("条;");
        //原粮汽车出入库-值仓
        QueryWrapper<DataCrkywZcDefault> dataCrkywZcQueryWrapper = new QueryWrapper<>();
        dataCrkywZcQueryWrapper.eq("UnitID",unitId);
        if (isNull)dataCrkywZcQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataCrkywZcQueryWrapper.last(limit);
        List<DataCrkywZcDefault> zcList = dataCrkywZcDefaultService.list(dataCrkywZcQueryWrapper);
        if (zcList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_zc_default");
            data.put("opt","add");
            data.put("dataInfo",zcList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_zc_default").append(zcList.size()).append("条;");

        //原粮汽车入库-结算信息
        QueryWrapper<DataCrkywJsxxDefault> dataCrkywJsxxQueryWrapper = new QueryWrapper<>();
        dataCrkywJsxxQueryWrapper.eq("unitid",unitId);
        if (isNull)dataCrkywJsxxQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataCrkywJsxxQueryWrapper.last(limit);
        List<DataCrkywJsxxDefault> jsxxList = dataCrkywJsxxDefaultService.list(dataCrkywJsxxQueryWrapper);
        if (jsxxList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_jsxx_default");
            data.put("opt","add");
            data.put("dataInfo",jsxxList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_jsxx_default").append(jsxxList.size()).append("条;");

        //原粮汽车入库-检验信息
        QueryWrapper<DataCrkywJyxxDefault> dataCrkywJyxxQueryWrapper = new QueryWrapper<>();
        dataCrkywJyxxQueryWrapper.eq("unitid",unitId);
        if (isNull)dataCrkywJyxxQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataCrkywJyxxQueryWrapper.last(limit);
        List<DataCrkywJyxxDefault> jyxxList = dataCrkywJyxxDefaultService.list(dataCrkywJyxxQueryWrapper);
        if (jyxxList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_jyxx_default");
            data.put("opt","add");
            data.put("dataInfo",jyxxList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_jyxx_default").append(jyxxList.size()).append("条;");

        //原粮汽车入库-检验信息从表
        QueryWrapper<DataCrkywJyxxFlt001> dataCrkywJyxxFltQueryWrapper = new QueryWrapper<>();
        dataCrkywJyxxFltQueryWrapper.eq("unitid",unitId);
        if (isNull)dataCrkywJyxxFltQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataCrkywJyxxFltQueryWrapper.last(limit);
        List<DataCrkywJyxxFlt001> jyxxFltList = dataCrkywJyxxFlt001Service.list(dataCrkywJyxxFltQueryWrapper);
        if (jyxxFltList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_jyxx_flt_001");
            data.put("opt","add");
            data.put("dataInfo",jyxxFltList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_jyxx_flt_001").append(jyxxFltList.size()).append("条;");

        //原粮汽车入库-扦样信息
        QueryWrapper<DataCrkywQyxxDefault> dataCrkywQyxxQueryWrapper = new QueryWrapper<>();
        dataCrkywQyxxQueryWrapper.eq("unitid",unitId);
        if (isNull)dataCrkywQyxxQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataCrkywQyxxQueryWrapper.last(limit);
        List<DataCrkywQyxxDefault> qyxxList = dataCrkywQyxxDefaultService.list(dataCrkywQyxxQueryWrapper);
        if (qyxxList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_qyxx_default");
            data.put("opt","add");
            data.put("dataInfo",qyxxList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_qyxx_default").append(qyxxList.size()).append("条;");


        //原粮汽车入库-出门
        QueryWrapper<DataCrkywRkcmDefault> dataCrkywRkcmQueryWrapper = new QueryWrapper<>();
        dataCrkywRkcmQueryWrapper.eq("unitid",unitId);
        if (isNull) dataCrkywRkcmQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataCrkywRkcmQueryWrapper.last(limit);
        List<DataCrkywRkcmDefault> rkcmList = dataCrkywRkcmDefaultService.list(dataCrkywRkcmQueryWrapper);
        if (rkcmList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_rkcm_default");
            data.put("opt","add");
            data.put("dataInfo",rkcmList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_rkcm_default").append(rkcmList.size()).append("条;");


        //原粮汽车入库-入门登记
        QueryWrapper<DataCrkywRmdjDefault> dataCrkywRmdjQueryWrapper = new QueryWrapper<>();
        dataCrkywRmdjQueryWrapper.eq("unitid",unitId);
        if (isNull) dataCrkywRmdjQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataCrkywRmdjQueryWrapper.last(limit);
        List<DataCrkywRmdjDefault> rkdjList = dataCrkywRmdjDefaultService.list(dataCrkywRmdjQueryWrapper);
        if (rkdjList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_rkdj_default");
            data.put("opt","add");
            data.put("dataInfo",rkdjList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_rkdj_default").append(rkdjList.size()).append("条;");

        return operatlog;
    }

    /**
     * 上传原粮出库数据
     * @param unitId 单位ID
     * @param limit 条数
     * @param datas
     * @param operatlog
     * @param isNull 上传时间是否为空
     * @return
     */
    @Override
    public StringBuilder uploadJsSjzxlCkData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {
        //原粮流程规律表
        QueryWrapper<Bizflowtrail> bizflowtrailQueryWrapper = new QueryWrapper<>();
        bizflowtrailQueryWrapper.eq("unitid",unitId);
        if (isNull) bizflowtrailQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        bizflowtrailQueryWrapper.last(limit);
        List<Bizflowtrail> bizflowtrailList = bizflowtrailService.list(bizflowtrailQueryWrapper);
        if (bizflowtrailList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","bizflowtrail");
            data.put("opt","add");
            data.put("dataInfo",bizflowtrailList);
            datas.add(data);
        }
        operatlog.append("bizflowtrail").append(bizflowtrailList.size()).append("条;");

        //原粮汽车出库-出门
        QueryWrapper<DataCrkywCkcmDefault> dataCrkywCkcmQueryWrapper = new QueryWrapper<>();
        dataCrkywCkcmQueryWrapper.eq("unitid",unitId);
        if (isNull)dataCrkywCkcmQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataCrkywCkcmQueryWrapper.last(limit);
        List<DataCrkywCkcmDefault> ckcmList = dataCrkywCkcmDefaultService.list(dataCrkywCkcmQueryWrapper);
        if (ckcmList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_ckcm_default");
            data.put("opt","add");
            data.put("dataInfo",ckcmList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_ckcm_default").append(ckcmList.size()).append("条;");

        //原粮汽车出库-称毛重
        QueryWrapper<DataCrkywCkcmzDefault> dataCrkywCkcmzQueryWrapper = new QueryWrapper<>();
        dataCrkywCkcmzQueryWrapper.eq("unitid",unitId);
        if (isNull)dataCrkywCkcmzQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataCrkywCkcmzQueryWrapper.last(limit);
        List<DataCrkywCkcmzDefault> ckcmzList = dataCrkywCkcmzDefaultService.list(dataCrkywCkcmzQueryWrapper);
        if (ckcmzList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_ckcmz_default");
            data.put("opt","add");
            data.put("dataInfo",ckcmzList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_ckcmz_default").append(ckcmzList.size()).append("条;");

        //原粮汽车出入库-值仓
        QueryWrapper<DataCrkywZcDefault> dataCrkywZcQueryWrapper = new QueryWrapper<>();
        dataCrkywZcQueryWrapper.eq("UnitID",unitId);
        if (isNull)dataCrkywZcQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataCrkywZcQueryWrapper.last(limit);
        List<DataCrkywZcDefault> zcList = dataCrkywZcDefaultService.list(dataCrkywZcQueryWrapper);
        if (zcList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_zc_default");
            data.put("opt","add");
            data.put("dataInfo",zcList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_zc_default").append(zcList.size()).append("条;");

        //原粮汽车出库-称皮重
        QueryWrapper<DataCrkywCkcpzDefault> dataCrkywCkcpzQueryWrapper = new QueryWrapper<>();
        dataCrkywCkcpzQueryWrapper.eq("unitid",unitId);
        if (isNull)dataCrkywCkcpzQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataCrkywCkcpzQueryWrapper.last(limit);
        List<DataCrkywCkcpzDefault> ckcpzList = dataCrkywCkcpzDefaultService.list(dataCrkywCkcpzQueryWrapper);
        if (ckcpzList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_ckcpz_default");
            data.put("opt","add");
            data.put("dataInfo",ckcpzList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_ckcpz_default").append(ckcpzList.size()).append("条;");


        //原粮汽车出库-出入库入门登记
        QueryWrapper<DataCrkywCkrmdjDefault> dataCrkywCkrmdjQueryWrapper = new QueryWrapper<>();
        dataCrkywCkrmdjQueryWrapper.eq("unitid",unitId);
        if (isNull)dataCrkywCkrmdjQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataCrkywCkrmdjQueryWrapper.last(limit);
        List<DataCrkywCkrmdjDefault> ckrmdjList = dataCrkywCkrmdjDefaultService.list(dataCrkywCkrmdjQueryWrapper);
        if (ckrmdjList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_ckrmdj_default");
            data.put("opt","add");
            data.put("dataInfo",ckrmdjList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_ckrmdj_default").append(ckrmdjList.size()).append("条;");
        return operatlog;
    }

    @Override
    public StringBuilder uploadJsSjzxKcData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {
        //库存管理-分库保管账
        QueryWrapper<DataKcglFcbgzDefault> dataKcglFcbgzQueryWrapper = new QueryWrapper<>();
        dataKcglFcbgzQueryWrapper.eq("unitid",unitId);
        if (isNull)dataKcglFcbgzQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataKcglFcbgzQueryWrapper.last(limit);
        List<DataKcglFcbgzDefault> fcbgzList = dataKcglFcbgzDefaultService.list(dataKcglFcbgzQueryWrapper);
        if (fcbgzList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_kcgl_fcbgz_default");
            data.put("opt","add");
            data.put("dataInfo",fcbgzList);
            datas.add(data);
        }
        operatlog.append("data_kcgl_fcbgz_default").append(fcbgzList.size()).append("条;");

        //库存管理-库存实物
        QueryWrapper<DataKcglKcswDefault> dataKcglKcswQueryWrapper = new QueryWrapper<>();
        dataKcglKcswQueryWrapper.eq("unitid",unitId);
        if (isNull)dataKcglKcswQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataKcglKcswQueryWrapper.last(limit);
        List<DataKcglKcswDefault> kcswList = dataKcglKcswDefaultService.list(dataKcglKcswQueryWrapper);
        if (kcswList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_kcgl_kcsw_default");
            data.put("opt","add");
            data.put("dataInfo",kcswList);
            datas.add(data);
        }
        operatlog.append("data_kcgl_kcsw_default").append(kcswList.size()).append("条;");

        //库存管理-形成库存
        QueryWrapper<DataKcglXckcDefault> dataKcglXckcQueryWrapper = new QueryWrapper<>();
        dataKcglXckcQueryWrapper.eq("unitid",unitId);
        if (isNull)dataKcglXckcQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataKcglXckcQueryWrapper.last(limit);
        List<DataKcglXckcDefault> xckcList = dataKcglXckcDefaultService.list(dataKcglXckcQueryWrapper);
        if (xckcList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_kcgl_xckc_default");
            data.put("opt","add");
            data.put("dataInfo",xckcList);
            datas.add(data);
        }
        operatlog.append("data_kcgl_xckc_default").append(xckcList.size()).append("条;");


        return operatlog;
    }

    @Override
    public StringBuilder uploadJsSjzxKcbdData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {

        //库存管理-库存变动
        QueryWrapper<DataKcglKcbdDefault> dataKcglKcbdQueryWrapper = new QueryWrapper<>();
        dataKcglKcbdQueryWrapper.eq("unitid",unitId);
        if (isNull)dataKcglKcbdQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataKcglKcbdQueryWrapper.last(limit);
        List<DataKcglKcbdDefault> kcbdList = dataKcglKcbdDefaultService.list(dataKcglKcbdQueryWrapper);
        if (kcbdList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_kcgl_kcbd_default");
            data.put("opt","add");
            data.put("dataInfo",kcbdList);
            datas.add(data);
        }
        operatlog.append("data_kcgl_kcbd_default").append(kcbdList.size()).append("条;");
        return operatlog;
    }

    @Override
    public StringBuilder uploadJsSjzxTzzdData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {
        //原粮汽车出入库-通用单主表
        QueryWrapper<DataCrkywTzdxxDefault> dataCrkywTzdxxQueryWrapper = new QueryWrapper<>();
        dataCrkywTzdxxQueryWrapper.eq("unitid",unitId);
        if (isNull)dataCrkywTzdxxQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataCrkywTzdxxQueryWrapper.last(limit);
        List<DataCrkywTzdxxDefault> tzdxxList = dataCrkywTzdxxDefaultService.list(dataCrkywTzdxxQueryWrapper);
        if (tzdxxList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_tzdxx_default");
            data.put("opt","add");
            data.put("dataInfo",tzdxxList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_tzdxx_default").append(tzdxxList.size()).append("条;");


        //原粮汽车出入库-通用单从表
        QueryWrapper<DataCrkywTzdxxFlt001> dataCrkywTzdxxFltQueryWrapper = new QueryWrapper<>();
        dataCrkywTzdxxFltQueryWrapper.eq("unitid",unitId);
        if (isNull)dataCrkywTzdxxFltQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataCrkywTzdxxFltQueryWrapper.last(limit);
        List<DataCrkywTzdxxFlt001> tzdxxFltList = dataCrkywTzdxxFlt001Service.list(dataCrkywTzdxxFltQueryWrapper);
        if (tzdxxFltList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_tzdxx_flt_001");
            data.put("opt","add");
            data.put("dataInfo",tzdxxFltList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_tzdxx_flt_001").append(tzdxxFltList.size()).append("条;");
        return operatlog;
    }

    @Override
    public StringBuilder uploadJsSjzxQckcData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {
        //库存管理-期初库存
        QueryWrapper<DataKcglQckcDefault> dataKcglQckcQueryWrapper = new QueryWrapper<>();
        dataKcglQckcQueryWrapper.eq("unitid",unitId);
        if (isNull)dataKcglQckcQueryWrapper.isNull("UPDATE_TIME"); //上传时间为空
        dataKcglQckcQueryWrapper.last(limit);
        List<DataKcglQckcDefault> qckcList = dataKcglQckcDefaultService.list(dataKcglQckcQueryWrapper);
        if (qckcList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_kcgl_qckc_default");
            data.put("opt","add");
            data.put("dataInfo",qckcList);
            datas.add(data);
        }
        operatlog.append("data_kcgl_qckc_default").append(qckcList.size()).append("条;");
        return operatlog;
    }

    /**
     * 分拣数据上传
     * @param unitId 单位ID
     * @param limit 条数
     * @param datas
     * @param operatlog
     * @param isNull 上传时间是否为空
     * @return
     */
    @Override
    public StringBuilder uploadJsSjzxCplFjData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {
        //分拣主表
        QueryWrapper<DataCrkywCplfjDefault> dataKcglFjQueryWrapper = new QueryWrapper<>();
        dataKcglFjQueryWrapper.eq("unitid",unitId);
        if (isNull)dataKcglFjQueryWrapper.isNull("updateTime"); //上传时间为空
        dataKcglFjQueryWrapper.last(limit);
        List<DataCrkywCplfjDefault> fjList = dataCrkywCplfjDefaultService.list(dataKcglFjQueryWrapper);
        if (fjList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cplfj_default");
            data.put("opt","add");
            data.put("dataInfo",fjList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_cplfj_default").append(fjList.size()).append("条;");
        //分拣从表
        QueryWrapper<DataCrkywCplfjFlt001> dataKcglfjFlt001QueryWrapper = new QueryWrapper<>();
        dataKcglfjFlt001QueryWrapper.eq("unitid",unitId);
        if (isNull)dataKcglfjFlt001QueryWrapper.isNull("updateTime"); //上传时间为空
        dataKcglfjFlt001QueryWrapper.last(limit);
        List<DataCrkywCplfjFlt001> fj001List = dataCrkywCplfjFlt001Service.list(dataKcglfjFlt001QueryWrapper);
        if (fjList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cplfj_flt_001");
            data.put("opt","add");
            data.put("dataInfo",fjList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_cplfj_flt_001").append(fjList.size()).append("条;");
        return operatlog;
    }

    /**
     * 分拣数据上传
     * @param unitId 单位ID
     * @param limit 条数
     * @param datas
     * @param operatlog
     * @param isNull 上传时间是否为空
     * @return
     */
    @Override
    public StringBuilder uploadJsSjzxEnumData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {
        //分拣主表
        QueryWrapper<BasicEnum> enumQueryWrapper = new QueryWrapper<>();
        if (isNull)enumQueryWrapper.isNull("EDIT_TIME"); //(以修改时间为上传时间)上传时间为空
        enumQueryWrapper.last(limit);
        List<BasicEnum> fjList = basicEnumService.list(enumQueryWrapper);
        if (fjList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","basic_enum");
            data.put("opt","add");
            data.put("dataInfo",fjList);
            datas.add(data);
        }
        operatlog.append("basic_enum").append(fjList.size()).append("条;");
        return operatlog;
    }

    /**
     * 上传商品信息
     * @param unitId 单位ID
     * @param limit 条数
     * @param datas
     * @param operatlog
     * @param isNull 上传时间是否为空
     * @return
     */
    @Override
    public StringBuilder uploadJsSjspData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {
        QueryWrapper<DataCrkywCplspDefault> spQueryWrapper = new QueryWrapper<>();
        spQueryWrapper.eq("unitid",unitId);
        if (isNull)spQueryWrapper.isNull("updateTime"); //(以修改时间为上传时间)上传时间为空
        spQueryWrapper.last(limit);
        List<DataCrkywCplspDefault> spList = dataCrkywCplspDefaultService.list(spQueryWrapper);
        if (spList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","data_crkyw_cplsp_default");
            data.put("opt","add");
            data.put("dataInfo",spList);
            datas.add(data);
        }
        operatlog.append("data_crkyw_cplsp_default").append(spList.size()).append("条;");
        return operatlog;



    }

    /**
     * 上传附件信息
     * @param unitId 单位ID
     * @param limit 条数
     * @param datas
     * @param operatlog
     * @param isNull 上传时间是否为空
     * @return
     */
    @Override
    public StringBuilder uploadJsSjattachesData(String unitId, String limit, JSONArray datas, StringBuilder operatlog, boolean isNull) {
        QueryWrapper<Attaches> attachesQueryWrapper = new QueryWrapper<>();
        attachesQueryWrapper.eq("UnitID",unitId);
        if (isNull)attachesQueryWrapper.isNull("FLAG"); //(以修改时间为上传时间)上传时间为空
        attachesQueryWrapper.last(limit);
        List<Attaches> attachesList = attachesService.list(attachesQueryWrapper);
        if (attachesList.size() > 0){
            JSONObject data = new JSONObject();
            data.put("table","attaches");
            data.put("opt","add");
            data.put("dataInfo",attachesList);
            datas.add(data);
        }
        operatlog.append("attaches").append(attachesList.size()).append("条;");
        return operatlog;


    }

    /**
     * 判断是否是json字符串，是返回code
     * @param s
     * @return
     */
    public static  String  judge(String s){
        Integer k=0;
        boolean json = JSONUtil.isJson(s);
        if(json){
            cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(s);
            String code = jsonObject.getStr("code");
            return code;
        }else{
            return s;
        }

    }


}
