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.StringUtils;
import com.ruoyi.common.utils.bean.PojoUtils;
import com.ruoyi.dimp.domain.DPatentAuthInfo;
import com.ruoyi.dimp.domain.DPatentAuthInfoPreDetail;
import com.ruoyi.dimp.domain.DPatentAuthInfoPreImp;
import com.ruoyi.dimp.mapper.DPatentAuthInfoMapper;
import com.ruoyi.dimp.service.IDPatentAuthInfoService;
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 DPatentAuthInfoServiceImpl extends ServiceImpl<DPatentAuthInfoMapper, DPatentAuthInfo> implements IDPatentAuthInfoService {

    private static final Logger logger = LoggerFactory.getLogger(DPatentAuthInfoServiceImpl.class);

    @Autowired
    private IDPatentPubInfoService dPatentPubInfoService;
    @Autowired
    private IBladeRegionService bladeRegionService;
    @Autowired
    private DPatentAuthInfoMapper dPatentAuthInfoMapper;
    @Autowired
	private IDIpcTypeService dIpcTypeService;
    @Autowired
	private IDFixAddressAreaService dFixAddressAreaService;
	@Autowired
	private IDPatentDataCollationLogService dPatentDataCollationLogService;
	
    @Override
	public void deleteWidthImpBatch(String impBatch) {
    	dPatentAuthInfoMapper.deleteWidthImpBatch(impBatch);
	}
    
	public void doRefreshHv() {
		long beginTime = System.currentTimeMillis();
		logger.debug("开始刷新专利授权高价值数据");
		List<DPatentAuthInfo> list = queryList(new DPatentAuthInfo());
		logger.debug("查询完成，一共:" + list.size() + "条");

		for (int i = 0; i < list.size(); i++) {
			logger.debug("开始刷新第[" + i + "]条专利授权数据的高价值,一共[" + list.size() + "]条");
			DPatentAuthInfo old = list.get(i);
			String appNumber = old.getApplyNumber();
			if (StringUtils.isNotBlank(appNumber)) {
				DPatentPubInfo pub = dPatentPubInfoService.queryByAppNumber(appNumber, true);
				if (pub != null && StringUtils.isNotBlank(pub.getHighValue())) {
					DPatentAuthInfo up = new DPatentAuthInfo();
					up.setId(old.getId());
					String hv = pub.getHighValue();
					up.setHighValuePub(hv);
					if (hv.contains("1")) {
						up.setHvSeisPub("1");
					} else {
						up.setHvSeisPub("0");
					}
					
					//20230710 2,3 对调
					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);
				}

			}

		}

	}
	
	
	private MatchThread[]threads=new MatchThread[10];
	
	public static class MatchThread extends Thread{
		List<DPatentAuthInfo> list;
		 IDPatentPubInfoService dPatentPubInfoService;
		 IDPatentAuthInfoService dPatentAuthInfoService;
		public MatchThread(List<DPatentAuthInfo> listArr,IDPatentPubInfoService dPatentPubInfoService,IDPatentAuthInfoService dPatentAuthInfoService) {
			this.list=listArr;
			this.dPatentPubInfoService=dPatentPubInfoService;
			this.dPatentAuthInfoService=dPatentAuthInfoService;
		}
		public void run() {
			for(int i=0;i<list.size();i++) {
				logger.debug("开始匹配第["+i+"]条授权数据，一共["+list.size()+"]条");
				DPatentAuthInfo act=list.get(i);
				DPatentPubInfo pub = dPatentPubInfoService.queryByAppNumber(act.getApplyNumber(), false);
				if(pub!=null) {
					DPatentAuthInfo u = doCleanData3(pub, act);
					dPatentAuthInfoService.updateById(u);
				}
			}
			logger.debug("授权数据同步线程["+Thread.currentThread().getName()+"]同步完成");
			
		}
	}

	public void reMatch3(List<DPatentAuthInfo> actList) {
		
		
	}
    public void reMatch3() {
    	
    	List<DPatentAuthInfo>[]listArr=new ArrayList[10];
    	for(int i=0;i<10;i++) {
    		listArr[i]=new ArrayList<DPatentAuthInfo>();
    		threads[i]=new MatchThread(listArr[i],dPatentPubInfoService,this) ;
    		threads[i].setName("auth-match-"+i);
    	}

    	DPatentAuthInfo dPatentEffectiveInfo=new DPatentAuthInfo();
		List<DPatentAuthInfo> actList=queryList(dPatentEffectiveInfo);
		logger.debug("一共查询到"+actList.size()+"条末匹配的授权数据");
		int j=0;
		for(DPatentAuthInfo act:actList) {
			j++;
			
			if(StringUtils.isNotBlank(act.getApplyNumber())) {
				listArr[act.getId().intValue() % 10].add(act);
//				if(pub!=null) {
//					DPatentAuthInfo u = doCleanData3(pub, act);
//					updateById(u);
//				}
			}
		}
		
		for(int i=0;i<10;i++) {
			threads[i].start();
		}
	
    }
	
	
    @Override
    public void cleanData() {
        logger.debug("开始数据清洗...");
        List<DPatentAuthInfo> list = queryList(new DPatentAuthInfo());
        for (int i = 0; i < list.size(); i++) {
            logger.debug("开始清洗第" + i + "条数据，一共" + list.size() + "条");

            DPatentAuthInfo data = list.get(i);

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

    }
	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);
		
	}
    
    public void doCleanData(DPatentPubInfo pub, DPatentAuthInfo data,Map<String,DFixAddressArea>fixMap) {
        DPatentAuthInfo u =data;

//      u.setId(data.getId());
		if (pub == null) {
			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.getPatenteeAddress());
			if(fixArea!=null) {
				logger.debug("匹配到固定地址,"+u.getPatenteeAddress()+",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 {
			
//			boolean needAjdLog=false;
//			DPatentDataCollationLog adjLog=new DPatentDataCollationLog();
//			adjLog.setDataType("auth");
			
			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.getProvinceCode()) && StringUtils.isNotBlank(u.getProvinceName())) {
				BladeRegion bladeRegion = bladeRegionService.selectByProvinceName(u.getProvinceName());
				if (bladeRegion != null) {
					u.setProvinceCode(bladeRegion.getCode());
				}
			}
			

			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.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.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());
//			}
//			if(StringUtils.isBlank(u.getModifyPatenteeType()) && StringUtils.isNotBlank(pub.getModifyAppliType())) {
//				u.setModifyPatenteeType(pub.getModifyAppliType());
//				ApplicantType at=ApplicantType.getByCode(pub.getModifyAppliType());
//				if(at!=null) {
//					u.setModifyPatenteeType(at.getTypeName());
//				}
//			}
			
			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 {
//				TODO	不要修改原始的patenteeType
//				//修改专利授权人类型
//				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.getPatenteeAddress());
			if(fixArea!=null) {
				logger.debug("匹配到固定地址,"+u.getPatenteeAddress()+",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 String1 appTranCountsPub;
			u.setAppTranCountsPub(pub.getAppTranCounts());
			u.setAppTranCounts(pub.getAppTranCounts());
//			    private String locStrPub;
			u.setLocStrPub(pub.getLocStr());
			u.setLocStr(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.setPubNumber(pub.getPubNumber());
			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");
				}
			}

//          auth_inbound_date
			
			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.getPrincipalClassNumber())) {
				u.setIpcMain(u.getPrincipalClassNumber());
			}
			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.getAreaCode())) {
				u.setAreaCode(pub.getYunnanModifyAppliCountyCode());
			}

			if (StringUtils.isBlank(u.getAreaName())) {
				u.setAreaName(pub.getYunnanModifyAppliCounty());
			}
			
			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())) {
//					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 {
						u.setNotThisArea("1");// 非本区划
					}
				}else {
					u.setNotThisArea("0");
				}
			}
			
//			if(needAjdLog) {
//				adjLog.setCreateTime(new Date());
//				adjLog.setCreateBy("系统自动");
//				dPatentDataCollationLogService.save(adjLog);
//			}
			
			
			
			

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

//        if (pubInfo == null) {
//            u.setPubMatch("0");//末匹配
//        } else {
//            u.setProvinceNamePub(pubInfo.getYunnanModifyAppliProvince());
//            u.setCityNamePub(pubInfo.getYunnanModifyAppliCity());
//            u.setAreaNamePub(pubInfo.getYunnanModifyAppliCounty());
//            u.setPubMatch("1");
//
//            if (StringUtils.isNotBlank(u.getProvinceNamePub())) {
//                BladeRegion bladeRegion = bladeRegionService.selectByProvinceName(u.getProvinceNamePub());
//                if (bladeRegion != null) {
//                    u.setProvinceCodePub(bladeRegion.getCode());
//                }
//            }
//
//            if (StringUtils.isNotBlank(u.getCityNamePub()) && StringUtils.isNotBlank(u.getProvinceCodePub())) {
//                BladeRegion bladeRegion = bladeRegionService.selectByCityName(u.getCityNamePub(), u.getProvinceCodePub());
//                if (bladeRegion != null) {
//                    u.setCityCodePub(bladeRegion.getCode());
//                }
//            }
//
//            if (StringUtils.isNotBlank(u.getAreaNamePub()) && StringUtils.isNotBlank(u.getCityCodePub())) {
//                BladeRegion bladeRegion = bladeRegionService.selectByAreaName(u.getAreaNamePub(), u.getCityCodePub());
//                if (bladeRegion != null) {
//                    u.setAreaCodePub(bladeRegion.getCode());
//                }
//            }
//        }
//        updateById(u);
		
		 //20231018
		if(pub!=null) {
			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());
		}
	   
		
		
		
    }
    
    public static DPatentAuthInfo doCleanData3(DPatentPubInfo pub, DPatentAuthInfo data) {
    	DPatentAuthInfo u=new DPatentAuthInfo();
		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;
	}
    

	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) + "";
	}
    
	private String validData(DPatentAuthInfoPreDetail d) {

		if(StringUtils.isBlank(d.getApplyNumber())) {
			return "申请号不能为空";
		}
		
//		/** 申请号 */
//		@Excel(name = "申请号")
//		private String applyNumber;//导
//
//		/** 授权入库日 */
//		@Excel(name = "授权入库日")
//		private String authInboundDate;//导
		if(StringUtils.isBlank(d.getAuthInboundDate())) {
			return "授权入库日不能为空";
		}
//
//		/** 申请日 */
//		@Excel(name = "申请日")
//		private String applyDate;//导
		if(StringUtils.isBlank(d.getApplyDate())) {
			return "申请日不能为空";
		}
//
//		/** 发明名称 */
//		@Excel(name = "发明名称")
//		private String inventionName;//导
		if(StringUtils.isBlank(d.getInventionName())) {
			return "发明名称不能为空";
		}
		

		
//
//		/** 代理机构代码 */
//		@Excel(name = "代理机构代码")
//		private String agencyCode;//导
//		if(StringUtils.isBlank(d.getAgencyCode())) {
//			return "代理机构代码不能为空";
//		}
////
////		/** 代理机构名称 */
////		@Excel(name = "代理机构名称")
////		private String agencyName;//导
//		if(StringUtils.isBlank(d.getAgencyName())) {
//			return "代理机构名称不能为空";
//		}
//
//		/** 主分类号 */
//		@Excel(name = "主分类号")
//		private String principalClassNumber;//导
		if(StringUtils.isBlank(d.getPrincipalClassNumber())) {
			return "主分类号不能为空";
		}
//
//		/** 专利权人名称 */
//		@Excel(name = "专利权人名称")
//		private String patenteeName;//导
		if(StringUtils.isBlank(d.getPatenteeName())) {
			return "专利权人名称不能为空";
		}
//
//		/** 专利权人邮编 */
//		@Excel(name = "专利权人邮编")
//		private Long patenteePostcode;//导
//
//		/** 专利权人地址 */
//		@Excel(name = "专利权人地址")
//		private String patenteeAddress;//导
		if(StringUtils.isBlank(d.getPatenteeAddress())) {
			return "专利权人地址不能为空";
		}
		
//		申请号	授权入库日	申请日	发明名称	代理机构代码	代理机构名称	主分类号	专利权人名称	专利权人邮编	专利权人地址	专利类型	专利权人类型	省份名称	城市名称
//
//		/** 专利类型 */
//		@Excel(name = "专利类型")
//		private String patentType;//导
		if(StringUtils.isBlank(d.getPatentType())) {
			return "专利类型不能为空";
		}
//
//		/** 专利权人类型 */
//		@Excel(name = "专利权人类型")
//		private String patenteeType;//导
		if(StringUtils.isBlank(d.getPatenteeType())) {
			return "专利权人类型不能为空";
		}
//
//		/** 省份名称 */
//		@Excel(name = "省份名称")
//		private String provinceName;//导
//
//		/** 城市名称 */
//		@Excel(name = "城市名称")
//		private String cityName;//导
		if(StringUtils.isBlank(d.getCityName())) {
			return "城市名称不能为空";
		}
//
//		/** 删除标识 */
//		private Integer delFlag;
//
//		/** 状态 */
//		@Excel(name = "状态")
//		private Long status;
//
//		/** 预导入id */
//		private Long preId;
//
//		/** 文件名 */
//		@Excel(name = "文件名")
//		private String fileName;
//
//		/** 导入状态 */
//		@Excel(name = "导入状态")
//		private String impState;
//
//		/** 原因 */
//		@Excel(name = "失败原因")
//		private String errReason;
		
		return null;
	}

    @Override
    public String importData(List<DPatentAuthInfoPreDetail> dataList, DPatentAuthInfoPreImp imp) {

//		logger.debug("正在导入[机构积分汇总]数据:" + new Gson().toJson(data));
        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();

        
        logger.debug("开始加载固定地址"); 
		Map<String,DFixAddressArea>fixMap=dFixAddressAreaService.loadAll();
		logger.debug("固定地址加载完成");
		
		
        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>();

        for (int j = 0; j < dataList.size(); j++) {
            DPatentAuthInfoPreDetail repd = dataList.get(j);


            DPatentAuthInfo extDPatentAuthInfo = new DPatentAuthInfo();
//			extDPatentAuthInfo.setProvinceName(repd.getProvinceName());
            extDPatentAuthInfo.setApplyNumber(repd.getApplyNumber());
            extDPatentAuthInfo.setImpBatch(imp.getImpBatch());

            int i = j + 1;
            DPatentAuthInfo branchPointsSum = PojoUtils.copyTo(DPatentAuthInfo.class, repd);
            List<DPatentAuthInfo> list = queryList(extDPatentAuthInfo);
            if (list != null && !list.isEmpty()) {
                DPatentAuthInfo 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 v=validData(repd);
            	if(StringUtils.isNotBlank(v)) {
            		skipNum++;
            		repd.setImpState(ImpStatus.IMP_SKIP);
            		repd.setErrReason(v);
            		logger.warn("数据校验不通过,"+v+","+new Gson().toJson(repd));
            		continue;
            	}
            	
            	
            	branchPointsSum.setIpcMain(repd.getPrincipalClassNumber());//主分类号
            	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()));
                String appNumber = branchPointsSum.getApplyNumber();
				if (StringUtils.isNotBlank(appNumber)) {
					DPatentPubInfo pub = dPatentPubInfoService.queryByAppNumber(appNumber,false);
					if (pub != null) {
						doCleanData(pub, branchPointsSum,fixMap);
					}else {
						logger.warn("申请号["+appNumber+"]没有匹配到公开专利数据");
						
						doCleanData(null, 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 void doCleanData2(DPatentAuthInfo 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());
//			}
//		}
//		
//		
//	
//    }
    /**
     * 查询专利授权导入列表
     *
     * @param dPatentAuthInfo 专利授权导入
     * @return 专利授权导入集合
     * @date 2023-03-19
     */
    @Override
    public List<DPatentAuthInfo> queryList(DPatentAuthInfo dPatentAuthInfo) {
        QueryWrapper<DPatentAuthInfo> queryWrapper = Wrappers.query();
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getApplyNumber())) {
            queryWrapper.eq("apply_number", dPatentAuthInfo.getApplyNumber());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getApplyDate())) {
            queryWrapper.eq("apply_date", dPatentAuthInfo.getApplyDate());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getPatenteeName())) {
            queryWrapper.like("patentee_name", dPatentAuthInfo.getPatenteeName());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getPatenteeType())) {
            queryWrapper.eq("patentee_type", dPatentAuthInfo.getPatenteeType());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getModifyPatenteeType())) {
            queryWrapper.eq("modify_patentee_type", dPatentAuthInfo.getModifyPatenteeType());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getPatenteeAddress())) {
            queryWrapper.eq("patentee_address", dPatentAuthInfo.getPatenteeAddress());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getProvinceName())) {
            queryWrapper.like("province_name", dPatentAuthInfo.getProvinceName());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getCityName())) {
            queryWrapper.like("city_name", dPatentAuthInfo.getCityName());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getAreaCode())) {
            queryWrapper.eq("area_code", dPatentAuthInfo.getAreaCode());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getAreaName())) {
            queryWrapper.like("area_name", dPatentAuthInfo.getAreaName());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getCityCode())) {
            queryWrapper.eq("city_code", dPatentAuthInfo.getCityCode());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getProvinceCode())) {
            queryWrapper.eq("province_code", dPatentAuthInfo.getProvinceCode());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getModifyProvinceCode())) {
            queryWrapper.eq("modify_province_code", dPatentAuthInfo.getModifyProvinceCode());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getModifyProvinceName())) {
            queryWrapper.like("modify_province_name", dPatentAuthInfo.getModifyProvinceName());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getModifyCityCode())) {
            queryWrapper.eq("modify_city_code", dPatentAuthInfo.getModifyCityCode());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getModifyCityName())) {
            queryWrapper.like("modify_city_name", dPatentAuthInfo.getModifyCityName());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getModifyAreaCode())) {
            queryWrapper.eq("modify_area_code", dPatentAuthInfo.getModifyAreaCode());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getModifyAreaName())) {
            queryWrapper.like("modify_area_name", dPatentAuthInfo.getModifyAreaName());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getHighValuePub())) {
            queryWrapper.eq("high_value_pub", dPatentAuthInfo.getHighValuePub());
        }
        if (StringUtils.isNotNull(dPatentAuthInfo.getAddressAdjustmentTime())) {
            queryWrapper.eq("address_adjustment_time", dPatentAuthInfo.getAddressAdjustmentTime());
        }
        if (StringUtils.isNotNull(dPatentAuthInfo.getApplyAdjustmentTime())) {
            queryWrapper.eq("apply_adjustment_time", dPatentAuthInfo.getApplyAdjustmentTime());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getInventionName())) {
            queryWrapper.like("invention_name", dPatentAuthInfo.getInventionName());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getPubNumber())) {
            queryWrapper.eq("pub_number", dPatentAuthInfo.getPubNumber());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getPatentStatus())) {
            queryWrapper.eq("patent_status", dPatentAuthInfo.getPatentStatus());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getPatentHolderPub())) {
            queryWrapper.eq("patent_holder_pub", dPatentAuthInfo.getPatentHolderPub());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getPatentType())) {
            queryWrapper.eq("patent_type", dPatentAuthInfo.getPatentType());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getIpcMain())) {
            queryWrapper.eq("ipc_main", dPatentAuthInfo.getIpcMain());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getLocStr())) {
            queryWrapper.eq("loc_str", dPatentAuthInfo.getLocStr());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getNationalEcoStr())) {
            queryWrapper.eq("national_eco_str", dPatentAuthInfo.getNationalEcoStr());
        }
        if (StringUtils.isNotNull(dPatentAuthInfo.getPatTranCounts())) {
            queryWrapper.eq("pat_tran_counts", dPatentAuthInfo.getPatTranCounts());
        }
        if (StringUtils.isNotNull(dPatentAuthInfo.getAppTranCounts())) {
            queryWrapper.eq("app_tran_counts", dPatentAuthInfo.getAppTranCounts());
        }
        if (StringUtils.isNotNull(dPatentAuthInfo.getLicCounts())) {
            queryWrapper.eq("lic_counts", dPatentAuthInfo.getLicCounts());
        }
        if (StringUtils.isNotNull(dPatentAuthInfo.getPleCounts())) {
            queryWrapper.eq("ple_counts", dPatentAuthInfo.getPleCounts());
        }
        if (StringUtils.isNotNull(dPatentAuthInfo.getPreCounts())) {
            queryWrapper.eq("pre_counts", dPatentAuthInfo.getPreCounts());
        }
        if (StringUtils.isNotNull(dPatentAuthInfo.getCurtCounts())) {
            queryWrapper.eq("curt_counts", dPatentAuthInfo.getCurtCounts());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getAgencyCode())) {
            queryWrapper.eq("agency_code", dPatentAuthInfo.getAgencyCode());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getAgencyName())) {
            queryWrapper.like("agency_name", dPatentAuthInfo.getAgencyName());
        }
        if (StringUtils.isNotNull(dPatentAuthInfo.getStatus())) {
            queryWrapper.eq("status", dPatentAuthInfo.getStatus());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getPrincipalClassNumber())) {
            queryWrapper.eq("principal_class_number", dPatentAuthInfo.getPrincipalClassNumber());
        }
        if (StringUtils.isNotNull(dPatentAuthInfo.getPatenteePostcode())) {
            queryWrapper.eq("patentee_postcode", dPatentAuthInfo.getPatenteePostcode());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getAuthInboundDate())) {
            queryWrapper.eq("auth_inbound_date", dPatentAuthInfo.getAuthInboundDate());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getYearBatch())) {
            queryWrapper.eq("year_batch", dPatentAuthInfo.getYearBatch());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getMonthBatch())) {
            queryWrapper.eq("month_batch", dPatentAuthInfo.getMonthBatch());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getProvinceCodePub())) {
            queryWrapper.eq("province_code_pub", dPatentAuthInfo.getProvinceCodePub());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getCityCodePub())) {
            queryWrapper.eq("city_code_pub", dPatentAuthInfo.getCityCodePub());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getAreaNamePub())) {
            queryWrapper.eq("area_name_pub", dPatentAuthInfo.getAreaNamePub());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getAreaCodePub())) {
            queryWrapper.eq("area_code_pub", dPatentAuthInfo.getAreaCodePub());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getProvinceNamePub())) {
            queryWrapper.eq("province_name_pub", dPatentAuthInfo.getProvinceNamePub());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getCityNamePub())) {
            queryWrapper.eq("city_name_pub", dPatentAuthInfo.getCityNamePub());
        }
        if (StringUtils.isNotEmpty(dPatentAuthInfo.getPubMatch())) {
            queryWrapper.eq("pub_match", dPatentAuthInfo.getPubMatch());
        }
        queryWrapper.orderByDesc("id");
        return this.list(queryWrapper);
    }

	
}
