package com.ruoyi.dimp.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.Gson;
import com.ruoyi.adjust.service.IDPatentDataCollationLogService;
import com.ruoyi.common.constant.ApplicantType;
import com.ruoyi.common.constant.ImpStatus;
import com.ruoyi.common.constant.IpcType;
import com.ruoyi.common.constant.LocStr;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.PojoUtils;
import com.ruoyi.dimp.domain.DPatentEffectiveInfo;
import com.ruoyi.dimp.domain.DPatentEffectiveInfoPreDetail;
import com.ruoyi.dimp.domain.DPatentEffectiveInfoPreImp;
import com.ruoyi.dimp.mapper.DPatentEffectiveInfoMapper;
import com.ruoyi.dimp.service.IDPatentEffectiveInfoService;
import com.ruoyi.reportpub.domain.DPatentPubInfo;
import com.ruoyi.reportpub.service.IDPatentPubInfoService;
import com.ruoyi.system.domain.BladeRegion;
import com.ruoyi.system.domain.DFixAddressArea;
import com.ruoyi.system.domain.DIpcType;
import com.ruoyi.system.service.IBladeRegionService;
import com.ruoyi.system.service.IDFixAddressAreaService;
import com.ruoyi.system.service.IDIpcTypeService;

/**
 * 专利有效导入Service业务层处理
 *
 * @author ruoyi
 * @date 2023-03-19
 */
@Service
public class DPatentEffectiveInfoServiceImpl extends ServiceImpl<DPatentEffectiveInfoMapper, DPatentEffectiveInfo> implements IDPatentEffectiveInfoService {
	private static final Logger logger = LoggerFactory.getLogger(DPatentEffectiveInfoServiceImpl.class);

	@Autowired
	private IDPatentPubInfoService dPatentPubInfoService;
	@Autowired
	private IBladeRegionService bladeRegionService;
	@Autowired
	private DPatentEffectiveInfoMapper dPatentEffectiveInfoMapper;
	@Autowired
	private IDIpcTypeService dIpcTypeService;
	@Autowired
	private IDPatentDataCollationLogService dPatentDataCollationLogService;
	@Autowired
	private IDFixAddressAreaService dFixAddressAreaService;

	@Override
	public void deleteWidthImpBatch(String impBatch) {
		dPatentEffectiveInfoMapper.deleteWidthImpBatch(impBatch);
	}

	public void doRefreshHv() {
		long beginTime = System.currentTimeMillis();
		logger.debug("开始刷新专利有效高价值数据");
		List<DPatentEffectiveInfo> list = queryList(new DPatentEffectiveInfo());
		logger.debug("查询完成，一共:" + list.size() + "条");

		for (int i = 0; i < list.size(); i++) {
			logger.debug("开始刷新第[" + i + "]条专利有效数据的高价值,一共[" + list.size() + "]条");
			DPatentEffectiveInfo old = list.get(i);
			String appNumber = old.getAppNumber();
			if (StringUtils.isNotBlank(appNumber)) {
				DPatentPubInfo pub = dPatentPubInfoService.queryByAppNumber(appNumber, true);
				if (pub != null && StringUtils.isNotBlank(pub.getHighValue())) {
					DPatentEffectiveInfo up = new DPatentEffectiveInfo();
					up.setId(old.getId());
					String hv = pub.getHighValue();
					up.setHighValuePub(hv);
					if (hv.contains("1")) {
						up.setHvSeisPub("1");
					} else {
						up.setHvSeisPub("0");
					}

//					if (hv.contains("2")) {
//						up.setHvKeep10Pub("1");
//					} else {
//						up.setHvKeep10Pub("0");
//					}
//					if (hv.contains("3")) {
//						up.setHvHaveOverseasPub("1");
//					} else {
//						up.setHvHaveOverseasPub("0");
//					}
//					20230710
					if (hv.contains("3")) {
						up.setHvKeep10Pub("1");
					} else {
						up.setHvKeep10Pub("0");
					}
					if (hv.contains("2")) {
						up.setHvHaveOverseasPub("1");
					} else {
						up.setHvHaveOverseasPub("0");
					}

					if (hv.contains("4")) {
						up.setHvHighPledgePub("1");
					} else {
						up.setHvHighPledgePub("0");
					}
					if (hv.contains("5")) {
						up.setHvTechnologyAwardPub("1");
					} else {
						up.setHvTechnologyAwardPub("0");
					}
					updateById(up);
				}

			}

		}

	}

	@Override
	public void cleanData() {
		logger.debug("开始数据清洗...");
		List<DPatentEffectiveInfo> list = queryList(new DPatentEffectiveInfo());
		for (int i = 0; i < list.size(); i++) {
			logger.debug("开始清洗第" + i + "条数据，一共" + list.size() + "条");

			DPatentEffectiveInfo data = list.get(i);

			String applyNumber = data.getAppNumber();
			if (StringUtils.isBlank(applyNumber)) {
				logger.warn("数据id:" + data.getId() + "的申请号为空，跳过清洗");
				continue;
			}
			DPatentPubInfo pubInfo = dPatentPubInfoService.queryByAppNumber(applyNumber, false);
			doCleanData(pubInfo, data,null);
		}

	}

//	public void doCleanData2(DPatentEffectiveInfo d) {
//
//		if (StringUtils.isBlank(d.getModifyProvinceCode()) && StringUtils.isNotBlank(d.getProvinceCode()) ) {
//			d.setModifyProvinceCode(d.getProvinceCode());
//		}
//		
//		if (StringUtils.isBlank(d.getModifyProvinceName()) && StringUtils.isNotBlank(d.getProvinceName()) ) {
//			d.setModifyProvinceName(d.getProvinceName());
//		}
//		
//		
//		if (StringUtils.isBlank(d.getProvinceCode()) && StringUtils.isNotBlank(d.getProvinceName())) {
//			BladeRegion bladeRegion = bladeRegionService.selectByProvinceName(d.getProvinceName());
//			if (bladeRegion != null) {
//				d.setProvinceCode(bladeRegion.getCode());
//			}
//		}
//		
//		if (StringUtils.isBlank(d.getModifyCityCode()) && StringUtils.isNotBlank(d.getCityCode()) ) {
//			d.setModifyCityCode(d.getCityCode());
//		}
//		
//		if (StringUtils.isBlank(d.getModifyCityName()) && StringUtils.isNotBlank(d.getCityName()) ) {
//			d.setModifyCityName(d.getCityName());
//		}
//		
//		if (StringUtils.isBlank(d.getCityCode()) && StringUtils.isNotBlank(d.getCityName())&& StringUtils.isNotBlank(d.getProvinceCode())) {
//			BladeRegion bladeRegion = bladeRegionService.selectByCityName(d.getCityName(),d.getProvinceCode());
//			if (bladeRegion != null) {
//				d.setCityCode(bladeRegion.getCode());
//			}
//		}
//
//		
//		
//		if (StringUtils.isBlank(d.getModifyAreaCode()) && StringUtils.isNotBlank(d.getAreaCode()) ) {
//			d.setModifyAreaCode(d.getAreaCode());
//		}
//		
//		if (StringUtils.isBlank(d.getModifyAreaName()) && StringUtils.isNotBlank(d.getAreaName()) ) {
//			d.setModifyAreaName(d.getAreaName());
//		}
//		
//		if (StringUtils.isBlank(d.getAreaCode()) && StringUtils.isNotBlank(d.getAreaName())
//				&& StringUtils.isNotBlank(d.getCityCode())) {
//			BladeRegion bladeRegion = bladeRegionService.selectByAreaName(d.getAreaName(), d.getCityCode());
//			if (bladeRegion != null) {
//				d.setAreaCode(bladeRegion.getCode());
//			}
//		}
//		
//		
//	}
	
	private static DFixAddressArea getByAddress(Map<String,DFixAddressArea>fixMap,String addr) {
		if(fixMap==null || fixMap.isEmpty()) {
			return null;
		}
		if(StringUtils.isBlank(addr)) {
			return null;
		}
		return fixMap.get(addr);
		
	}

	@Override
	public DPatentEffectiveInfo doCleanData(DPatentPubInfo pub, DPatentEffectiveInfo data,Map<String,DFixAddressArea>fixMap) {
//        u.setId(data.getId());
//		boolean needAjdLog=false;
//		DPatentDataCollationLog adjLog=new DPatentDataCollationLog();
//		adjLog.setDataType("act");

		DPatentEffectiveInfo u = data;
		
		//准备从固定地址中导
//		TODO	
		
		if (pub == null) {
			logger.debug("没有匹配到公开数据,申请号:" + data.getAppNumber());
			u.setPubMatch("0");// 末匹配
			u.setNotThisArea("1");

			if (StringUtils.isBlank(u.getProvinceCode()) && StringUtils.isNotBlank(u.getProvinceName())) {
				BladeRegion bladeRegion = bladeRegionService.selectByProvinceName(u.getProvinceName());
				if (bladeRegion != null) {
					u.setProvinceCode(bladeRegion.getCode());
				}
			}
			if (StringUtils.isBlank(u.getCityCode()) && StringUtils.isNotBlank(u.getCityName()) && StringUtils.isNotBlank(u.getProvinceCode())) {
				BladeRegion bladeRegion = bladeRegionService.selectByCityName(u.getCityName(), u.getProvinceCode());
				if (bladeRegion != null) {
					u.setCityCode(bladeRegion.getCode());
				}
			}

			if (StringUtils.isBlank(u.getModifyPatenteeType()) && StringUtils.isNotBlank(u.getPatenteeType())) {
				u.setModifyPatenteeType(u.getPatenteeType());
			}
			u.setModifyProvinceCode(u.getProvinceCode());
			u.setModifyProvinceName(u.getProvinceName());
			u.setModifyCityCode(u.getCityCode());
			u.setModifyCityName(u.getCityName());

			u.setProvinceCodePub(u.getProvinceCode());
			u.setProvinceNamePub(u.getProvinceName());
			u.setCityCodePub(u.getCityCode());
			u.setCityNamePub(u.getCityName());
			
			
			DFixAddressArea fixArea=getByAddress(fixMap,u.getAppliAddress());
			if(fixArea!=null) {
				logger.debug("匹配到固定地址,"+u.getAppliAddress()+",fixArea:"+new Gson().toJson(fixArea));
				u.setModifyProvinceName(fixArea.getProvinceName());
				u.setModifyProvinceCode(fixArea.getProvinceCode());
				u.setModifyCityCode(fixArea.getCityCode());
				u.setModifyCityName(fixArea.getCityName());
				u.setModifyAreaCode(fixArea.getAreaCode());
				u.setModifyAreaName(fixArea.getAreaName());
			}
			

			if (StringUtils.isBlank(u.getIpcType()) && StringUtils.isNotBlank(u.getIpcMain())) {
				if ("外观设计".equals(u.getPatentType())) {
					String locStr = toModifyLocStr(u.getIpcMain().trim());
					u.setIpcType(locStr);
					u.setIpcTypeName(LocStr.ALL.get(locStr));

				} else {
					if (u.getIpcMain().trim().length() >= 3) {
						u.setIpcType(u.getIpcMain().trim().substring(0, 1));
						u.setIpcSubType(u.getIpcMain().trim().substring(0, 3));

						IpcType ipcType = IpcType.valueOf(u.getIpcType());
						if (ipcType != null) {
							u.setIpcTypeName(ipcType.getTypeName());
						}
						DIpcType dIpcType = dIpcTypeService.getDIpcTypeByCode(u.getIpcSubType());
						if (dIpcType != null) {
							u.setIpcSubTypeName(dIpcType.getName());
						}

					}

				}
			}

		} else {
			u.setProvinceNamePub(pub.getYunnanModifyAppliProvince());
			u.setCityNamePub(pub.getYunnanModifyAppliCity());
			u.setAreaNamePub(pub.getYunnanModifyAppliCounty());

			u.setProvinceCodePub(pub.getYunnanModifyAppliProvinceCode());
			u.setCityCodePub(pub.getYunnanModifyAppliCityCode());
			u.setAreaCodePub(pub.getYunnanModifyAppliCountyCode());

			u.setPubMatch("1");

			if (StringUtils.isBlank(u.getCityName()) && StringUtils.isNotBlank(u.getCityNamePub())) {
				u.setCityName(u.getCityNamePub());
			}

			if (StringUtils.isBlank(u.getProvinceCodePub()) && StringUtils.isNotBlank(u.getProvinceNamePub())) {
				BladeRegion bladeRegion = bladeRegionService.selectByProvinceName(u.getProvinceNamePub());
				if (bladeRegion != null) {
					u.setProvinceCodePub(bladeRegion.getCode());
					pub.setYunnanModifyAppliProvinceCode(bladeRegion.getCode());
				}
			}

			if (StringUtils.isBlank(u.getCityCodePub()) && StringUtils.isNotBlank(u.getCityNamePub()) && StringUtils.isNotBlank(u.getProvinceCodePub())) {
				BladeRegion bladeRegion = bladeRegionService.selectByCityName(u.getCityNamePub(), u.getProvinceCodePub());
				if (bladeRegion != null) {
					u.setCityCodePub(bladeRegion.getCode());
					pub.setYunnanModifyAppliCityCode(bladeRegion.getCode());
				}
			}

			if (StringUtils.isBlank(u.getAreaCodePub()) && StringUtils.isNotBlank(u.getAreaNamePub()) && StringUtils.isNotBlank(u.getCityCodePub())) {
				BladeRegion bladeRegion = bladeRegionService.selectByAreaName(u.getAreaNamePub(), u.getCityCodePub());
				if (bladeRegion != null) {
					u.setAreaCodePub(bladeRegion.getCode());
					pub.setYunnanModifyAppliCountyCode(bladeRegion.getCode());
				}
			}

			if (StringUtils.isBlank(u.getAreaCode()) && StringUtils.isNotBlank(u.getAreaCodePub())) {
				u.setAreaCode(u.getAreaCodePub());
			}

			if (StringUtils.isBlank(u.getAreaName()) && StringUtils.isNotBlank(u.getAreaNamePub())) {
				u.setAreaName(u.getAreaNamePub());
			}

//			 private String highValuePub;
			u.setHighValuePub(pub.getHighValue());
//			    /**
//			     * 专利权人类型(新)
//			     */
//			    private String modifyPatenteeType;
			if (StringUtils.isBlank(u.getModifyPatenteeType()) && StringUtils.isNotBlank(u.getPatenteeType())) {
				u.setModifyPatenteeType(u.getPatenteeType());
			}

			String modifyAppliTypePub = null;
			if (StringUtils.isNotBlank(pub.getModifyAppliType())) {
				ApplicantType at = ApplicantType.getByCode(pub.getModifyAppliType());
				if (at != null) {
					modifyAppliTypePub = at.getTypeName();
				}
			}

			if (StringUtils.isBlank(u.getModifyPatenteeType())) {
				if (StringUtils.isNotBlank(modifyAppliTypePub)) {
					u.setModifyPatenteeType(modifyAppliTypePub);
				}
			} else {
				// 修改专利授权人类型
				if (StringUtils.isNotBlank(modifyAppliTypePub) && !u.getModifyPatenteeType().equals(modifyAppliTypePub)) {
//					needAjdLog=true;
//					adjLog.setAppliType0(u.getModifyPatenteeType());
//					adjLog.setAppliType(modifyAppliTypePub);
//					u.setModifyPatenteeType(modifyAppliTypePub);
				}
			}
			
			
			DFixAddressArea fixArea=getByAddress(fixMap,u.getAppliAddress());
			if(fixArea!=null) {
				logger.debug("匹配到固定地址,"+u.getAppliAddress()+",fixArea:"+new Gson().toJson(fixArea));
				u.setModifyProvinceName(fixArea.getProvinceName());
				u.setModifyProvinceCode(fixArea.getProvinceCode());
				u.setModifyCityCode(fixArea.getCityCode());
				u.setModifyCityName(fixArea.getCityName());
				u.setModifyAreaCode(fixArea.getAreaCode());
				u.setModifyAreaName(fixArea.getAreaName());
			}
//			    private String preCountsPub;
			u.setPreCountsPub(pub.getPreCounts());
			u.setPreCounts(pub.getPreCounts());
//			    private String licCountsPub;
			u.setLicCountsPub(pub.getLicCounts());
			u.setLicCounts(pub.getLicCounts());
//			    private String titlePub;
			u.setTitlePub(pub.getTitle());
//			    private String ipcMainPub;
			u.setIpcMainPub(pub.getIpcMain());
//			    private String pleCountsPub;
			u.setPleCountsPub(pub.getPleCounts());
			u.setPleCounts(pub.getPleCounts());
//			    private String appTranCountsPub;
			u.setAppTranCountsPub(pub.getAppTranCounts());
			u.setAppTranCounts(pub.getAppTranCounts());
//			    private String locStrPub;
			u.setLocStrPub(pub.getLocStr());
//			    private String curtCountsPub;
			u.setCurtCountsPub(pub.getCurtCounts());
			u.setCurtCounts(pub.getCurtCounts());
//			    private String nationalEcoStrPub;
			u.setNationalEcoStrPub(pub.getNationalEcoStr());
//			    private String agencyNamePub;
			u.setAgencyNamePub(pub.getAgencyName());
			if (StringUtils.isBlank(u.getAgencyName())) {
				u.setAgencyName(pub.getAgencyName());
			}
//			    private String pubNumberPub;
			u.setPubNumberPub(pub.getPubNumber());
//			    private String appliAddressPub;
			u.setAppliAddressPub(pub.getAppliAddress());
//			    private String patTranCountsPub;
			u.setPatTranCountsPub(pub.getPatTranCounts());
			u.setPatTranCounts(pub.getPatTranCounts());
//			    private String patentTypePub;
			u.setPatentTypePub(pub.getPatentType());

//			    private String appliTypePub;
			u.setAppliTypePub(pub.getAppliType());
//			    private String pubDatePub;
			u.setPubDatePub(pub.getPubDate());
//			    private String priNumberPub;
			u.setPriNumberPub(pub.getPriNumber());
//			    private String priDatePub;
			u.setPriDatePub(pub.getPriDate());
//			    private String timeCreatePub;
			u.setTimeCreatePub(pub.getTimeCreate());
//			    private String timeUpdatePub;
			u.setTimeUpdatePub(pub.getTimeUpdate());
//			    private String currentOwnersPub;
			u.setCurrentOwnersPub(pub.getCurrentOwners());
//			    private String cownerAddressPub;
			u.setCownerAddressPub(pub.getCownerAddress());

			String hv = pub.getHighValue();
			if (StringUtils.isNotBlank(hv)) {
				if (hv.contains("1")) {
					u.setHvSeisPub("1");
				} else {
					u.setHvSeisPub("0");
				}
//				if (hv.contains("2")) {
//					u.setHvKeep10Pub("1");
//				} else {
//					u.setHvKeep10Pub("0");
//				}
//				if (hv.contains("3")) {
//					u.setHvHaveOverseasPub("1");
//				} else {
//					u.setHvHaveOverseasPub("0");
//				}
//				20230710 2,3 对调
				if (hv.contains("3")) {
					u.setHvKeep10Pub("1");
				} else {
					u.setHvKeep10Pub("0");
				}
				if (hv.contains("2")) {
					u.setHvHaveOverseasPub("1");
				} else {
					u.setHvHaveOverseasPub("0");
				}
				if (hv.contains("4")) {
					u.setHvHighPledgePub("1");
				} else {
					u.setHvHighPledgePub("0");
				}
				if (hv.contains("5")) {
					u.setHvTechnologyAwardPub("1");
				} else {
					u.setHvTechnologyAwardPub("0");
				}
			}

			if (StringUtils.isBlank(u.getHighValuePub())) {
				u.setHighValuePub(pub.getHighValue());
			}
			if (StringUtils.isBlank(u.getPubNumber())) {
				u.setPubNumber(pub.getPubNumber());
			}

			u.setPatentStatus(pub.getPatentStatus());

			// 当前专利状态
			if (StringUtils.isBlank(u.getPatentStatus())) {
				u.setPatentStatus(pub.getStatus());
			}

//            @Excel(name = "当前专利人")
//            private String patentHolderPub;
			if (StringUtils.isBlank(u.getPatentHolderPub())) {
				u.setPatentHolderPub(pub.getPatentHolderPub());
			}

//            @Excel(name = "分类号")
//            private String ipcMain;
			// 优先用导入字段中的分类号
			if (StringUtils.isBlank(u.getIpcMain()) && StringUtils.isNotBlank(u.getMainClassNumber())) {
				u.setIpcMain(u.getMainClassNumber());
			}
			if (StringUtils.isBlank(u.getIpcMain())) {
				u.setIpcMain(pub.getIpcMain());
			}

//            @Excel(name = "分类号")
//            private String locStr;
			if (StringUtils.isBlank(u.getLocStr())) {
				u.setLocStr(pub.getLocStr());
			}

//            @Excel(name = "国民经济行业分类")
//            private String nationalEcoStr;
			if (StringUtils.isBlank(u.getNationalEcoStr())) {
				u.setNationalEcoStr(pub.getNationalEcoStr());
			}

//            private String status;
			if (StringUtils.isBlank(u.getStatus())) {
				u.setStatus(pub.getStatus());
			}

//            private String ipcType;
			if (StringUtils.isBlank(u.getIpcType()) && StringUtils.isNotBlank(u.getIpcMain())) {
				if ("外观设计".equals(u.getPatentType())) {
					String locStr = toModifyLocStr(u.getIpcMain().trim());
					u.setIpcType(locStr);
					u.setIpcTypeName(LocStr.ALL.get(locStr));

				} else {
					if (u.getIpcMain().trim().length() >= 3) {
						u.setIpcType(u.getIpcMain().trim().substring(0, 1));
						u.setIpcSubType(u.getIpcMain().trim().substring(0, 3));

						IpcType ipcType = IpcType.valueOf(u.getIpcType());
						if (ipcType != null) {
							u.setIpcTypeName(ipcType.getTypeName());
						}
						DIpcType dIpcType = dIpcTypeService.getDIpcTypeByCode(u.getIpcSubType());
						if (dIpcType != null) {
							u.setIpcSubTypeName(dIpcType.getName());
						}

					}

				}
			}

			if (StringUtils.isBlank(u.getIpcType())) {
				if ("外观设计".equals(u.getPatentType())) {
					u.setIpcType(pub.getModifyLocStr());
					u.setIpcTypeName(pub.getModifyLocStrDesc());
				} else {
					if (pub.getIpcMain().trim().length() >= 3) {
						u.setIpcType(pub.getIpcMain().trim().substring(0, 1));
						u.setIpcSubType(pub.getIpcMain().trim().substring(1, 3));

						IpcType ipcType = IpcType.valueOf(u.getIpcType());
						if (ipcType != null) {
							u.setIpcTypeName(ipcType.getTypeName());
						}
						DIpcType dIpcType = dIpcTypeService.getDIpcTypeByCode(u.getIpcSubType());
						if (dIpcType != null) {
							u.setIpcSubTypeName(dIpcType.getName());
						}

					}
				}
			}

			if (StringUtils.isBlank(u.getProvinceCode()) && StringUtils.isNotBlank(u.getProvinceName())) {
				BladeRegion bladeRegion = bladeRegionService.selectByProvinceName(u.getProvinceName());
				if (bladeRegion != null) {
					u.setProvinceCode(bladeRegion.getCode());
				}
			}

			if (StringUtils.isBlank(u.getCityCode()) && StringUtils.isNotBlank(u.getCityName()) && StringUtils.isNotBlank(u.getProvinceCode())) {
				BladeRegion bladeRegion = bladeRegionService.selectByCityName(u.getCityName(), u.getProvinceCode());
				if (bladeRegion != null) {
					u.setCityCode(bladeRegion.getCode());
				}
			}

			if (StringUtils.isBlank(u.getModifyProvinceCode())) {
				u.setModifyProvinceCode(u.getProvinceCode());
			}
			if (StringUtils.isBlank(u.getModifyProvinceName())) {
				u.setModifyProvinceName(u.getProvinceName());
			}

			if (StringUtils.isBlank(u.getModifyCityCode())) {
				u.setModifyCityCode(u.getCityCode());
			}
			if (StringUtils.isBlank(u.getModifyCityName())) {
				u.setModifyCityName(u.getCityName());
			}

			if (StringUtils.isBlank(u.getModifyAreaCode())) {
				u.setModifyAreaCode(u.getAreaCode());
			}
			if (StringUtils.isBlank(u.getModifyAreaName())) {
				u.setModifyAreaName(u.getAreaName());
			}
			if (StringUtils.isNotBlank(u.getProvinceCodePub())) {
				if (StringUtils.isBlank(u.getModifyProvinceCode())) {
					u.setModifyProvinceCode(u.getProvinceCodePub());
				} else if (!u.getModifyProvinceCode().equals(u.getProvinceCodePub())) {
//					needAjdLog=true;
//					adjLog.setModifyAppliProvinceCode0(u.getModifyProvinceCode());
//					adjLog.setModifyAppliProvinceCode(u.getProvinceCodePub());
//					u.setModifyProvinceCode(u.getProvinceCodePub());
				}
			}

			if (StringUtils.isNotBlank(u.getProvinceNamePub())) {
				if (StringUtils.isBlank(u.getModifyProvinceName())) {
					u.setModifyProvinceName(u.getProvinceNamePub());
				} else if (!u.getModifyProvinceName().equals(u.getProvinceNamePub())) {
//					needAjdLog=true;
//					adjLog.setModifyAppliProvince0(u.getModifyProvinceName());
//					adjLog.setModifyAppliProvince(u.getProvinceNamePub());
//					u.setModifyProvinceName(u.getProvinceNamePub());
				}
			}

			if (StringUtils.isNotBlank(u.getCityCodePub())) {
				if (StringUtils.isBlank(u.getModifyCityCode())) {
					u.setModifyCityCode(u.getCityCodePub());
				} else if (!u.getModifyCityCode().equals(u.getCityCodePub())) {
//					needAjdLog=true;
//					adjLog.setModifyAppliCityCode(u.getCityCodePub());
//					adjLog.setModifyAppliCityCode0(u.getModifyCityCode());
//					u.setModifyCityCode(u.getCityCodePub());
				}
			}

			if (StringUtils.isNotBlank(u.getCityNamePub())) {
				if (StringUtils.isBlank(u.getModifyCityName())) {
					u.setModifyCityName(u.getCityNamePub());
				} else if (!u.getModifyCityName().equals(u.getCityNamePub())) {
//					needAjdLog=true;
//					adjLog.setModifyAppliCity0(u.getModifyCityName());
//					adjLog.setModifyAppliCity(u.getCityNamePub());
//					u.setModifyCityName(u.getCityNamePub());
				}
			}

			if (StringUtils.isNotBlank(u.getAreaCodePub())) {
				if (StringUtils.isBlank(u.getModifyAreaCode())) {
					u.setModifyAreaCode(u.getAreaCodePub());
				} else if (!u.getModifyCityCode().equals(u.getAreaCodePub())) {
//					needAjdLog=true;
//					adjLog.setModifyAppliCityCode(u.getAreaCodePub());
//					adjLog.setModifyAppliCityCode0(u.getModifyCityCode());
//					u.setModifyAreaCode(u.getAreaCodePub());
				}
			}

			if (StringUtils.isNotBlank(u.getAreaNamePub())) {
				if (StringUtils.isBlank(u.getModifyAreaName())) {
					u.setModifyAreaName(u.getAreaNamePub());
				} else if (!u.getModifyAreaName().equals(u.getAreaNamePub())) {
//					needAjdLog=true;
//					adjLog.setModifyAppliCounty(u.getAreaNamePub());
//					adjLog.setModifyAppliCounty0(u.getModifyAreaName());
//					u.setModifyAreaName(u.getAreaNamePub());
				}

			}

//			TODO	20230523
			if (StringUtils.isNotBlank(u.getModifyCityCode())) {
				if (StringUtils.isBlank(u.getModifyAreaCode()) || !u.getModifyAreaCode().trim().startsWith(u.getModifyCityCode().trim())
						|| "530142".equals(u.getModifyAreaCode().trim()) || "530143".equals(u.getModifyAreaCode().trim())) {
//					u.setNotThisArea("1");// 非本区划
					if (StringUtils.isNotBlank(pub.getModifyCownerCountyCode())) {
						u.setModifyAreaCode(pub.getModifyCownerCountyCode());
						u.setModifyAreaName(pub.getModifyCownerCounty());
						if (!u.getModifyAreaCode().trim().startsWith(u.getModifyCityCode().trim())) {
							u.setNotThisArea("1");// 非本区划
						} else {
							u.setNotThisArea("0");
						}
					}
//					else if(StringUtils.isNotBlank(pub.getmodifyap())) {
//						
//					}
					else {
						u.setNotThisArea("1");// 非本区划
					}
				} else {
					u.setNotThisArea("0");
				}
			}
//			if(needAjdLog) {
//				adjLog.setCreateTime(new Date());
//				adjLog.setCreateBy("系统自动");
//				dPatentDataCollationLogService.save(adjLog);
//			}

//            updateById(u);//TODO	不入库了，让调用这个方法的程序去入库
		}

		if (pub != null) {
			// 20231018
			u.setCownerAddress(pub.getCownerAddress());
			u.setModifyCownerAddress(pub.getModifyCownerAddress());
			u.setCownerProvince(pub.getCownerProvince());
			u.setCownerCity(pub.getCownerCity());
			u.setCownerCounty(pub.getCownerCounty());
			u.setModifyCownerProvince(pub.getModifyCownerProvince());
			u.setModifyCownerCity(pub.getModifyCownerCity());
			u.setModifyCownerCounty(pub.getModifyCownerCounty());
			u.setCownerProvinceCode(pub.getCownerProvinceCode());
			u.setCownerCityCode(pub.getCownerCityCode());
			u.setCownerCountyCode(pub.getCownerCountyCode());
			u.setModifyCownerProvinceCode(pub.getModifyCownerProvinceCode());
			u.setModifyCownerCityCode(pub.getModifyCownerCityCode());
			u.setModifyCownerCountyCode(pub.getModifyCownerCountyCode());
		}

		return u;

	}

	public static DPatentEffectiveInfo doCleanData3(DPatentPubInfo pub, DPatentEffectiveInfo data) {
		DPatentEffectiveInfo u = new DPatentEffectiveInfo();
		u.setId(data.getId());
		u.setCownerAddress(pub.getCownerAddress());
		u.setModifyCownerAddress(pub.getModifyCownerAddress());
		u.setCownerProvince(pub.getCownerProvince());
		u.setCownerCity(pub.getCownerCity());
		u.setCownerCounty(pub.getCownerCounty());
		u.setModifyCownerProvince(pub.getModifyCownerProvince());
		u.setModifyCownerCity(pub.getModifyCownerCity());
		u.setModifyCownerCounty(pub.getModifyCownerCounty());
		u.setCownerProvinceCode(pub.getCownerProvinceCode());
		u.setCownerCityCode(pub.getCownerCityCode());
		u.setCownerCountyCode(pub.getCownerCountyCode());
		u.setModifyCownerProvinceCode(pub.getModifyCownerProvinceCode());
		u.setModifyCownerCityCode(pub.getModifyCownerCityCode());
		u.setModifyCownerCountyCode(pub.getModifyCownerCountyCode());
		return u;
	}

//	@Autowired
//	private IDPatentEffectiveInfoService dPatentEffectiveInfoService;

	/**
	 * 重匹配
	 * 
	 * 20230613
	 */
	public void reMatch() {
		DPatentEffectiveInfo dPatentEffectiveInfo = new DPatentEffectiveInfo();
		dPatentEffectiveInfo.setPubMatch("0");
		List<DPatentEffectiveInfo> actList = queryList(dPatentEffectiveInfo);
		logger.debug("一共查询到" + actList.size() + "条末匹配数据");
		for (DPatentEffectiveInfo act : actList) {
			if (StringUtils.isNotBlank(act.getAppNumber())) {
				DPatentPubInfo pub = dPatentPubInfoService.queryByAppNumber(act.getAppNumber(), false);
				DPatentEffectiveInfo u = doCleanData(pub, act,null);
				updateById(u);
			}
		}
	}

	private MatchThread[] threads = new MatchThread[10];

	public static class MatchThread extends Thread {
		List<DPatentEffectiveInfo> list;
		IDPatentPubInfoService dPatentPubInfoService;
		IDPatentEffectiveInfoService dPatentEffectiveInfoService;

		public MatchThread(List<DPatentEffectiveInfo> listArr, IDPatentPubInfoService dPatentPubInfoService,
				IDPatentEffectiveInfoService dPatentEffectiveInfoService) {
			this.list = listArr;
			this.dPatentPubInfoService = dPatentPubInfoService;
			this.dPatentEffectiveInfoService = dPatentEffectiveInfoService;
		}

		public void run() {
			for (int i = 0; i < list.size(); i++) {
				logger.debug("开始匹配第[" + i + "]条有效数据，一共[" + list.size() + "]条");
				DPatentEffectiveInfo act = list.get(i);
				DPatentPubInfo pub = dPatentPubInfoService.queryByAppNumber(act.getAppNumber(), false);
				if (pub != null) {
					DPatentEffectiveInfo u = doCleanData3(pub, act);
					dPatentEffectiveInfoService.updateById(u);
				}
			}
			logger.debug("有效数据同步线程[" + Thread.currentThread().getName() + "]同步完成");

		}
	}

	public void reMatch3() {

		List<DPatentEffectiveInfo>[] listArr = new ArrayList[10];
		for (int i = 0; i < 10; i++) {
			listArr[i] = new ArrayList<DPatentEffectiveInfo>();
			threads[i] = new MatchThread(listArr[i], dPatentPubInfoService, this);
			threads[i].setName("act-match-" + i);
		}

		DPatentEffectiveInfo dPatentEffectiveInfo = new DPatentEffectiveInfo();
		List<DPatentEffectiveInfo> actList = queryList(dPatentEffectiveInfo);
		logger.debug("一共查询到" + actList.size() + "条末匹配的有效数据");
		for (DPatentEffectiveInfo act : actList) {
//			logger.debug("开始匹配第[" + i + "]条有效数据，一共[" + actList.size() + "]条");
			if (StringUtils.isNotBlank(act.getAppNumber())) {
				listArr[act.getId().intValue() % 10].add(act);
//				DPatentPubInfo pub = dPatentPubInfoService.queryByAppNumber(act.getAppNumber(), false);
//				if (pub != null) {
//					DPatentEffectiveInfo u = doCleanData3(pub, act);
//					updateById(u);
//				}
			}
		}

		for (int i = 0; i < 10; i++) {
			threads[i].start();
		}
	}

	public void reMatch2() {
		DPatentEffectiveInfo dPatentEffectiveInfo = new DPatentEffectiveInfo();
		dPatentEffectiveInfo.setNotThisArea("1");
//		TODO	
//		dPatentEffectiveInfo.setAppNumber("2018210954880");
		List<DPatentEffectiveInfo> actList = queryList(dPatentEffectiveInfo);
		logger.debug("一共查询到" + actList.size() + "条非本区划数据");
		int totalCnt = 0;
		for (DPatentEffectiveInfo act : actList) {
			if (StringUtils.isNotBlank(act.getAppNumber())) {

				DPatentPubInfo pub = dPatentPubInfoService.queryByAppNumber(act.getAppNumber(), false);

				String notThisArea = act.getNotThisArea();

				DPatentEffectiveInfo u = doCleanData(pub, act,null);
				updateById(u);

				if ("1".equals(notThisArea) && "0".equals(u.getNotThisArea())) {
					totalCnt++;
					logger.debug("修正一条非本区划数据");
				}
			}
		}
		logger.debug("一共修正" + totalCnt + "条非本区划数据");
	}

	@Override
	public String importData(List<DPatentEffectiveInfoPreDetail> dataList, DPatentEffectiveInfoPreImp imp) {

		long successNum = 0;
		long errorNum = 0;
		long insertNum = 0;
		long updateNum = 0;
		long skipNum = 0;
		long totalNum = dataList.size();
		StringBuilder successMsg = new StringBuilder();
		StringBuilder failureMsg = new StringBuilder();

		List<String> failMsgList = new ArrayList<String>();
//		Map<String, UaBranchInfo> branchInfoMap2 = new HashMap<String, UaBranchInfo>();
//		Map<String, AreaCache> areaInfoMap = new HashMap<String, AreaCache>();
//		Map<String, UaMemberActivityRel> activityRelMap = new HashMap<String, UaMemberActivityRel>();
		
		logger.debug("开始加载固定地址"); 
		Map<String,DFixAddressArea>fixMap=dFixAddressAreaService.loadAll();
		logger.debug("固定地址加载完成");
		for (int j = 0; j < dataList.size(); j++) {
			DPatentEffectiveInfoPreDetail repd = dataList.get(j);

			DPatentEffectiveInfo extDPatentEffectiveInfo = new DPatentEffectiveInfo();
//			extDPatentEffectiveInfo.setProvinceName(repd.getProvinceName());

			if (StringUtils.isNotBlank(repd.getImpBatch()) && repd.getImpBatch().trim().length() == 6) {
				extDPatentEffectiveInfo.setYearBatch(repd.getImpBatch().trim().substring(0, 4));
				extDPatentEffectiveInfo.setMonthBatch(repd.getImpBatch().trim().substring(4, 6));

			}
			extDPatentEffectiveInfo.setAppNumber(repd.getAppNumber());

			int i = j + 1;
			DPatentEffectiveInfo branchPointsSum = PojoUtils.copyTo(DPatentEffectiveInfo.class, repd);

//            TODO	不再查询是否存在
//            List<DPatentEffectiveInfo> list = queryList(extDPatentEffectiveInfo);
			List<DPatentEffectiveInfo> list = null;
			if (list != null && !list.isEmpty()) {
				DPatentEffectiveInfo d = list.get(0);
//			BeanUtils.copyBeanProp(d, branchPointsSum);
				branchPointsSum.setId(d.getId());
				branchPointsSum.setUpdateTime(new Date());
				this.updateById(branchPointsSum);
				updateNum++;
				repd.setImpState(ImpStatus.IMP_UPDATE);
			} else {
				String impBatch = imp.getImpBatch();
				if (StringUtils.isNotBlank(impBatch) && impBatch.trim().length() == 6) {
					branchPointsSum.setYearBatch(impBatch.trim().substring(0, 4));
					branchPointsSum.setMonthBatch(impBatch.trim().substring(4, 6));
					branchPointsSum.setCreateMonth(branchPointsSum.getYearBatch() + "-" + branchPointsSum.getMonthBatch());// 20230705
				}
				if (StringUtils.isBlank(branchPointsSum.getImpBatch())) {
					branchPointsSum.setImpBatch(impBatch);
				}
				branchPointsSum.setCreateTime(new Date());
//				branchPointsSum.setCreateMonth(new SimpleDateFormat("yyyyMM").format(new Date()));
				branchPointsSum.setIpcMain(repd.getMainClassNumber());// 主分类号

				String appNumber = branchPointsSum.getAppNumber();
				if (StringUtils.isNotBlank(appNumber)) {
					DPatentPubInfo pub = dPatentPubInfoService.queryByAppNumber(appNumber, false);
//					if (pub != null) {
					doCleanData(pub, branchPointsSum,fixMap);
//					}
				}

//				doCleanData2(branchPointsSum);

				save(branchPointsSum);

				repd.setImpState(ImpStatus.IMP_INSERT);
				insertNum++;
			}

			successNum++;

		}

		successMsg.append("导入专利有效数据完成，共【" + totalNum + "】条，插入【" + insertNum + "】条");
		if (updateNum > 0) {
			successMsg.append(",更新【" + updateNum + "】条");
		}
		if (errorNum > 0) {
			successMsg.append(",失败条数【" + errorNum + "】条,");
			successMsg.append("<br/>失败原因如下:");

			for (int i = 0; i < failMsgList.size(); i++) {
				if (i < 10) {
					successMsg.append(failMsgList.get(i));
				} else {
					successMsg.append("<br/>还有更多失败，请重新导入试试");
					break;
				}
			}
		}
		imp.setTotalNum(totalNum);
		imp.setInsertNum(insertNum);
		imp.setUpdateNum(updateNum);
		imp.setSkipNum(skipNum);
		imp.setErrorNum(errorNum);
		imp.setErrReason(successMsg.toString());

		successMsg.append("<br/>");
		return successMsg.toString();

	}

	public static String toModifyLocStr(String locStr) {
		if (StringUtils.isBlank(locStr)) {
			return null;
		}
		String locStr2 = locStr.trim();
		if (locStr.contains(";")) {
//    		14-03;14-04
			locStr2 = locStr2.substring(0, locStr2.indexOf(";"));
		}
		if (locStr2.contains("-")) {
			locStr2 = locStr2.replace("-", "");
		}
		String locStr3 = null;
		if (locStr2.length() <= 3) {
			locStr3 = locStr2.substring(0, 1);
		} else {
			locStr3 = locStr2.substring(0, 2);
		}

		return Integer.parseInt(locStr3) + "";
	}

	/**
	 * 查询专利有效导入列表
	 *
	 * @param dPatentEffectiveInfo 专利有效导入
	 * @return 专利有效导入集合
	 * @date 2023-03-19
	 */
	@Override
	public List<DPatentEffectiveInfo> queryList(DPatentEffectiveInfo dPatentEffectiveInfo) {
		QueryWrapper<DPatentEffectiveInfo> queryWrapper = Wrappers.query();
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getAppNumber())) {
			queryWrapper.eq("app_number", dPatentEffectiveInfo.getAppNumber());
		}
		String cityCode=SecurityUtils.needFilterByCityCode();
		if(StringUtils.isNotBlank(cityCode)) {
			queryWrapper.eq("city_code", cityCode);
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getAppDate())) {
			queryWrapper.eq("app_date", dPatentEffectiveInfo.getAppDate());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getPatenteeName())) {
			queryWrapper.like("patentee_name", dPatentEffectiveInfo.getPatenteeName());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getPatenteeType())) {
			queryWrapper.eq("patentee_type", dPatentEffectiveInfo.getPatenteeType());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getModifyPatenteeType())) {
			queryWrapper.eq("modify_patentee_type", dPatentEffectiveInfo.getModifyPatenteeType());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getAppliAddress())) {
			queryWrapper.eq("appli_address", dPatentEffectiveInfo.getAppliAddress());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getProvinceCodePub())) {
			queryWrapper.eq("province_code_pub", dPatentEffectiveInfo.getProvinceCodePub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getProvinceNamePub())) {
			queryWrapper.eq("province_name_pub", dPatentEffectiveInfo.getProvinceNamePub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getCityCodePub())) {
			queryWrapper.eq("city_code_pub", dPatentEffectiveInfo.getCityCodePub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getCityNamePub())) {
			queryWrapper.eq("city_name_pub", dPatentEffectiveInfo.getCityNamePub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getAreaCodePub())) {
			queryWrapper.eq("area_code_pub", dPatentEffectiveInfo.getAreaCodePub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getAreaNamePub())) {
			queryWrapper.eq("area_name_pub", dPatentEffectiveInfo.getAreaNamePub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getProvinceCode())) {
			queryWrapper.eq("province_code", dPatentEffectiveInfo.getProvinceCode());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getProvinceName())) {
			queryWrapper.like("province_name", dPatentEffectiveInfo.getProvinceName());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getCityCode())) {
			queryWrapper.eq("city_code", dPatentEffectiveInfo.getCityCode());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getCityName())) {
			queryWrapper.like("city_name", dPatentEffectiveInfo.getCityName());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getAreaCode())) {
			queryWrapper.eq("area_code", dPatentEffectiveInfo.getAreaCode());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getAreaName())) {
			queryWrapper.like("area_name", dPatentEffectiveInfo.getAreaName());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getHighValuePub())) {
			queryWrapper.eq("high_value_pub", dPatentEffectiveInfo.getHighValuePub());
		}
		if (StringUtils.isNotNull(dPatentEffectiveInfo.getAddressAdjustmentTime())) {
			queryWrapper.eq("address_adjustment_time", dPatentEffectiveInfo.getAddressAdjustmentTime());
		}
		if (StringUtils.isNotNull(dPatentEffectiveInfo.getApplyAdjustmentTime())) {
			queryWrapper.eq("apply_adjustment_time", dPatentEffectiveInfo.getApplyAdjustmentTime());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getInventionName())) {
			queryWrapper.like("invention_name", dPatentEffectiveInfo.getInventionName());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getPubNumber())) {
			queryWrapper.eq("pub_number", dPatentEffectiveInfo.getPubNumber());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getPatentStatus())) {
			queryWrapper.eq("patent_status", dPatentEffectiveInfo.getPatentStatus());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getPatentHolderPub())) {
			queryWrapper.eq("patent_holder_pub", dPatentEffectiveInfo.getPatentHolderPub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getPatentType())) {
			queryWrapper.eq("patent_type", dPatentEffectiveInfo.getPatentType());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getIpcMain())) {
			queryWrapper.eq("ipc_main", dPatentEffectiveInfo.getIpcMain());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getLocStr())) {
			queryWrapper.eq("loc_str", dPatentEffectiveInfo.getLocStr());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getNationalEcoStr())) {
			queryWrapper.eq("national_eco_str", dPatentEffectiveInfo.getNationalEcoStr());
		}
		if (StringUtils.isNotNull(dPatentEffectiveInfo.getPatTranCounts())) {
			queryWrapper.eq("pat_tran_counts", dPatentEffectiveInfo.getPatTranCounts());
		}
		if (StringUtils.isNotNull(dPatentEffectiveInfo.getLicCounts())) {
			queryWrapper.eq("lic_counts", dPatentEffectiveInfo.getLicCounts());
		}
		if (StringUtils.isNotNull(dPatentEffectiveInfo.getPleCounts())) {
			queryWrapper.eq("ple_counts", dPatentEffectiveInfo.getPleCounts());
		}
		if (StringUtils.isNotNull(dPatentEffectiveInfo.getPreCounts())) {
			queryWrapper.eq("pre_counts", dPatentEffectiveInfo.getPreCounts());
		}
		if (StringUtils.isNotNull(dPatentEffectiveInfo.getCurtCounts())) {
			queryWrapper.eq("curt_counts", dPatentEffectiveInfo.getCurtCounts());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getAgencyCode())) {
			queryWrapper.eq("agency_code", dPatentEffectiveInfo.getAgencyCode());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getAgencyName())) {
			queryWrapper.like("agency_name", dPatentEffectiveInfo.getAgencyName());
		}
		if (StringUtils.isNotNull(dPatentEffectiveInfo.getStatus())) {
			queryWrapper.eq("status", dPatentEffectiveInfo.getStatus());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getIpcType())) {
			queryWrapper.eq("ipc_type", dPatentEffectiveInfo.getIpcType());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getIpcSubType())) {
			queryWrapper.eq("ipc_sub_type", dPatentEffectiveInfo.getIpcSubType());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getMainClassNumber())) {
			queryWrapper.eq("main_class_number", dPatentEffectiveInfo.getMainClassNumber());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getPatenteePostcode())) {
			queryWrapper.eq("patentee_postcode", dPatentEffectiveInfo.getPatenteePostcode());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getYearBatch())) {
			queryWrapper.eq("year_batch", dPatentEffectiveInfo.getYearBatch());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getMonthBatch())) {
			queryWrapper.eq("month_batch", dPatentEffectiveInfo.getMonthBatch());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getAuthInboundDate())) {
			queryWrapper.eq("auth_inbound_date", dPatentEffectiveInfo.getAuthInboundDate());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getPubMatch())) {
			queryWrapper.eq("pub_match", dPatentEffectiveInfo.getPubMatch());
		}
		if (StringUtils.isNotNull(dPatentEffectiveInfo.getPreCountsPub())) {
			queryWrapper.eq("pre_counts_pub", dPatentEffectiveInfo.getPreCountsPub());
		}
		if (StringUtils.isNotNull(dPatentEffectiveInfo.getLicCountsPub())) {
			queryWrapper.eq("lic_counts_pub", dPatentEffectiveInfo.getLicCountsPub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getTitlePub())) {
			queryWrapper.eq("title_pub", dPatentEffectiveInfo.getTitlePub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getIpcMainPub())) {
			queryWrapper.eq("ipc_main_pub", dPatentEffectiveInfo.getIpcMainPub());
		}
		if (StringUtils.isNotNull(dPatentEffectiveInfo.getPleCountsPub())) {
			queryWrapper.eq("ple_counts_pub", dPatentEffectiveInfo.getPleCountsPub());
		}
		if (StringUtils.isNotNull(dPatentEffectiveInfo.getAppTranCountsPub())) {
			queryWrapper.eq("app_tran_counts_pub", dPatentEffectiveInfo.getAppTranCountsPub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getLocStrPub())) {
			queryWrapper.eq("loc_str_pub", dPatentEffectiveInfo.getLocStrPub());
		}
		if (StringUtils.isNotNull(dPatentEffectiveInfo.getCurtCountsPub())) {
			queryWrapper.eq("curt_counts_pub", dPatentEffectiveInfo.getCurtCountsPub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getNationalEcoStrPub())) {
			queryWrapper.eq("national_eco_str_pub", dPatentEffectiveInfo.getNationalEcoStrPub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getAgencyNamePub())) {
			queryWrapper.eq("agency_name_pub", dPatentEffectiveInfo.getAgencyNamePub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getPubNumberPub())) {
			queryWrapper.eq("pub_number_pub", dPatentEffectiveInfo.getPubNumberPub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getAppliAddressPub())) {
			queryWrapper.eq("appli_address_pub", dPatentEffectiveInfo.getAppliAddressPub());
		}
		if (StringUtils.isNotNull(dPatentEffectiveInfo.getPatTranCountsPub())) {
			queryWrapper.eq("pat_tran_counts_pub", dPatentEffectiveInfo.getPatTranCountsPub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getPatentTypePub())) {
			queryWrapper.eq("patent_type_pub", dPatentEffectiveInfo.getPatentTypePub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getAppliTypePub())) {
			queryWrapper.eq("appli_type_pub", dPatentEffectiveInfo.getAppliTypePub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getPubDatePub())) {
			queryWrapper.eq("pub_date_pub", dPatentEffectiveInfo.getPubDatePub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getPriNumberPub())) {
			queryWrapper.eq("pri_number_pub", dPatentEffectiveInfo.getPriNumberPub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getPriDatePub())) {
			queryWrapper.eq("pri_date_pub", dPatentEffectiveInfo.getPriDatePub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getHvSeisPub())) {
			queryWrapper.eq("hv_seis_pub", dPatentEffectiveInfo.getHvSeisPub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getHvHaveOverseasPub())) {
			queryWrapper.eq("hv_have_overseas_pub", dPatentEffectiveInfo.getHvHaveOverseasPub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getHvKeep10Pub())) {
			queryWrapper.eq("hv_keep10_pub", dPatentEffectiveInfo.getHvKeep10Pub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getHvHighPledgePub())) {
			queryWrapper.eq("hv_high_pledge_pub", dPatentEffectiveInfo.getHvHighPledgePub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getHvTechnologyAwardPub())) {
			queryWrapper.eq("hv_technology_award_pub", dPatentEffectiveInfo.getHvTechnologyAwardPub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getImpBatch())) {
			queryWrapper.eq("imp_batch", dPatentEffectiveInfo.getImpBatch());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getTimeCreatePub())) {
			queryWrapper.eq("time_create_pub", dPatentEffectiveInfo.getTimeCreatePub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getTimeUpdatePub())) {
			queryWrapper.eq("time_update_pub", dPatentEffectiveInfo.getTimeUpdatePub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getCurrentOwnersPub())) {
			queryWrapper.eq("current_owners_pub", dPatentEffectiveInfo.getCurrentOwnersPub());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getCownerAddressPub())) {
			queryWrapper.eq("cowner_address_pub", dPatentEffectiveInfo.getCownerAddressPub());
		}

		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getPubMatch())) {
			queryWrapper.eq("pub_match", dPatentEffectiveInfo.getPubMatch());
		}
		if (StringUtils.isNotEmpty(dPatentEffectiveInfo.getNotThisArea())) {
			queryWrapper.eq("not_this_area", dPatentEffectiveInfo.getNotThisArea());
		}
		queryWrapper.orderByDesc("id");
		return this.list(queryWrapper);
	}

}
