package com.ruoyi.circuit.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

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

import com.alibaba.druid.support.json.JSONUtils;
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.circuit.domain.CIntegratedCircuit;
import com.ruoyi.circuit.mapper.CIntegratedCircuitMapper;
import com.ruoyi.circuit.service.ICIntegratedCircuitService;
import com.ruoyi.circuit.vo.CIntegratedCircuitDTO;
import com.ruoyi.circuit.vo.CIntegratedCircuitVO;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.report.vo.LastSumDTO;
import com.ruoyi.report.vo.SumItem;
import com.ruoyi.system.domain.BladeRegion;
import com.ruoyi.system.service.IBladeRegionService;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.utils.BladeRegionUtils;

/**
 * 中国集成电路Service业务层处理
 *
 * @author ruoyi
 * @date 2023-04-28
 */
@Service
public class CIntegratedCircuitServiceImpl extends ServiceImpl<CIntegratedCircuitMapper, CIntegratedCircuit> implements ICIntegratedCircuitService {

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

	@Autowired
	private IBladeRegionService bladeRegionService;

	@Autowired
	private ISysConfigService sysConfigService;

	@Autowired
	private RuoYiConfig ruoYiConfig;
	@Autowired
	private CIntegratedCircuitMapper cIntegratedCircuitMapper;

	public static void main(String[] args) {
		String url = "http://111.198.99.166:20000/icld/icld_total?project_code=530000&ak=268394598%4020230406";

		logger.debug("开始发送查询全国排名请求,url:" + url);

		String res = HttpUtils.sendGet(url);
		logger.debug("收到全国排名查询结果:" + res);

		LinkedHashMap map = (LinkedHashMap) JSONUtils.parse(res);
		List<LinkedHashMap> list = (List<LinkedHashMap>) map.get("results");

//		List<CIntegratedCircuitVO> item = getRankingList(list);
//		System.out.println("ok");

	}

	@Override
	public List<CIntegratedCircuitVO> listRank(CIntegratedCircuit cIntegratedCircuit) {
		String url = ruoYiConfig.getPressApiServer() + "icld/icld_total_pub?project_code=530000&ak=268394598%4020230406";

		logger.debug("开始发送查询全国排名请求,url:" + url);

		if (StringUtils.isNotBlank(cIntegratedCircuit.getBeginDate())) {
//			&bgn_date=20200101&end_date=20230101
			url = url + "&bgn_date=" + cIntegratedCircuit.getBeginDate();
		}
		if (StringUtils.isNotBlank(cIntegratedCircuit.getEndDate())) {
			url = url + "&end_date=" + cIntegratedCircuit.getEndDate();
		}
		String res = HttpUtils.sendGet(url);
		logger.debug("收到全国排名查询结果:" + res);

		LinkedHashMap map = (LinkedHashMap) JSONUtils.parse(res);
		List<LinkedHashMap> list = (List<LinkedHashMap>) map.get("results");

		List<CIntegratedCircuitVO> item = getRankingList(list);
		return item;
	}

	private List<CIntegratedCircuitVO> getRankingList(List<LinkedHashMap> list) {
		List<CIntegratedCircuitVO> itemList = new ArrayList<CIntegratedCircuitVO>();

		for (LinkedHashMap map : list) {
			Set<Map.Entry> set = map.entrySet();
			for (Map.Entry ent : set) {
				String key = ent.getKey() + "";
				String areaName = key.replace("集成电路量", "");
				if ("全国".equals(areaName)) {
					break;
				}
				CIntegratedCircuitVO vo = new CIntegratedCircuitVO();
				vo.setAreaName(areaName);
				vo.setTotalCnt(Long.parseLong(ent.getValue() + ""));

				itemList.add(vo);
				break;
			}
		}

		for (CIntegratedCircuitVO vo : itemList) {
			if (!"云南省".equals(vo.getAreaName())) {
				continue;
			}

			try {
				Long totalCnt = cIntegratedCircuitMapper.sumForLast();
				vo.setTotalCnt(totalCnt);
				break;
			} catch (Exception e) {
				logger.error(e.getMessage(), e);
			}

		}

		Collections.sort(itemList, new Comparator<CIntegratedCircuitVO>() {
			@Override
			public int compare(CIntegratedCircuitVO o1, CIntegratedCircuitVO o2) {
				if (o1 == null && o2 == null) {
					return 0;
				} else if (o1 == null) {
					return -1;
				} else if (o2 == null) {
					return 1;
				} else {
					if (o1.getTotalCnt() == null && o2.getTotalCnt() == null) {
						return 0;
					} else if (o1.getTotalCnt() == null) {
						return -1;
					} else if (o2.getTotalCnt() == null) {
						return 1;
					} else {
						return (int) (o2.getTotalCnt() - o1.getTotalCnt());
					}
				}
			}
		});

		for (int i = 0; i < itemList.size(); i++) {
			itemList.get(i).setRanking(i + 1);
		}

		return itemList;

	}

	public LastSumDTO listForLast() {
		LastSumDTO dto = new LastSumDTO();
		String lastTimeKey = "circuit_last_time";
		String lastTime = sysConfigService.selectConfigByKey(lastTimeKey);
		if (StringUtils.isNotBlank(lastTime)) {
			dto.setLastTime(lastTime);
		}

		SumItem totalItem = new SumItem();
		totalItem.setAreaCode("53");
		totalItem.setAreaName("云南省");
		totalItem.setAreaShortName("云南省");
		totalItem.setTotalCnt(0L);

		List<SumItem> itemList = new ArrayList<SumItem>();
		Set<String> citySet = new HashSet<String>();

		List<Map> dataList = cIntegratedCircuitMapper.listForLast();
//		total_cnt,modify_city,modify_city_code
		for (Map map : dataList) {
			SumItem item = new SumItem();
			itemList.add(item);
			item.setTotalCnt(getLong(map, "total_cnt"));
			item.setAreaName(getStr(map, "modify_city"));
			item.setAreaCode(getStr(map, "modify_city_code"));

			citySet.add(item.getAreaCode());

			BladeRegion bladeRegion = BladeRegionUtils.selectByCode(item.getAreaCode());
			if (bladeRegion != null) {
				if (bladeRegion.getCityName().equals(item.getAreaName())) {
					if (StringUtils.isNotBlank(bladeRegion.getCityShortName())) {
						item.setAreaShortName(bladeRegion.getCityShortName());
					}

				} else {
					logger.warn("数据错误，城市名称与城市代码不匹配,city:" + item.getAreaName() + ",code:" + item.getAreaCode());
				}
			}

			totalItem.setTotalCnt(totalItem.getTotalCnt() + item.getTotalCnt());
		}

		List<BladeRegion> cityList = bladeRegionService.selectAllCityList();
		for (BladeRegion br : cityList) {
			if (!citySet.contains(br.getCityCode())) {
				SumItem item = new SumItem();
				item.setTotalCnt(0L);
				item.setAreaName(br.getCityName());
				item.setAreaCode(br.getCityCode());
				item.setAreaShortName(br.getCityShortName());
				itemList.add(item);
			}
		}

		Collections.sort(itemList, new Comparator<SumItem>() {
			@Override
			public int compare(SumItem o1, SumItem o2) {
				return (int) (o2.getTotalCnt() - o1.getTotalCnt());
			}
		});

		itemList.add(0, totalItem);

		dto.setList(itemList);
		return dto;

	}

	@Override
	public CIntegratedCircuitDTO listReport(CIntegratedCircuit cIntegratedCircuit) {

		boolean retEmpty = false;
		if (StringUtils.isNotBlank(cIntegratedCircuit.getCityCode()) && !"53".equals(cIntegratedCircuit.getCityCode())) {
			String cityCode = cIntegratedCircuit.getCityCode().trim();
			if (SecurityUtils.isNeedFilterByCityCode()) {
				String cc = SecurityUtils.needFilterByCityCode();
				if (!cc.equals(cityCode)) {
					retEmpty = true;
				}
			}
		} else {
			if (SecurityUtils.isNeedFilterByCityCode()) {
				String cityCode = SecurityUtils.needFilterByCityCode();
				cIntegratedCircuit.setCityCode(cityCode);
			}
		}
		List<Map> dataList =new ArrayList<Map> ();
		if(!retEmpty) {
			dataList = cIntegratedCircuitMapper.listReport(cIntegratedCircuit);
		}

		CIntegratedCircuitDTO dto = new CIntegratedCircuitDTO();
		dto.setList(new ArrayList());

		Set<String> yearSet = new HashSet<String>();
		for (Map map : dataList) {
			yearSet.add(getStr(map, "pub_year"));
		}

		List<String> years = new ArrayList<String>();
		years.addAll(yearSet);

		Collections.sort(years, new Comparator<String>() {
			@Override
			public int compare(String o1, String o2) {
				return Integer.parseInt(o1) - Integer.parseInt(o2);
			}

		});

		dto.setYears(years);

		CIntegratedCircuitVO totalVo = new CIntegratedCircuitVO();
		totalVo.setTotals(new HashMap<String, Long>());
		String cityCode = cIntegratedCircuit.getCityCode();
		if (StringUtils.isBlank(cityCode)) {
			totalVo.setAreaName("云南省");
		} else {
			String areaName = "---";
			BladeRegion bladeRegion = BladeRegionUtils.selectByCode(cityCode);
//			BladeRegion bladeRegion = bladeRegionService.selectByCityName(cityCode, "53");
			if (bladeRegion != null) {
				String name = bladeRegion.getName();
				if (StringUtils.isNotBlank(bladeRegion.getCityShortName())) {
					name = bladeRegion.getCityShortName().replace("-", "");
				} else if (StringUtils.isNotBlank(bladeRegion.getDistrictShortName())) {
					name = bladeRegion.getDistrictShortName();
				}
				areaName = name;
			}
			totalVo.setAreaName(areaName);
		}

		for (String year : years) {
			totalVo.getTotals().put(year, 0L);
		}

		Map<String, CIntegratedCircuitVO> alreadyMap = new HashMap<String, CIntegratedCircuitVO>();

		for (Map map : dataList) {

			String areaName = getStr(map, "area_name");
			if (!alreadyMap.containsKey(areaName)) {
				CIntegratedCircuitVO vo = new CIntegratedCircuitVO();
				vo.setAreaName(areaName);
				alreadyMap.put(areaName, vo);
				vo.setTotals(new HashMap<String, Long>());
				for (String year : yearSet) {
					vo.getTotals().put(year, 0L);
				}
			}

			CIntegratedCircuitVO vo = alreadyMap.get(areaName);
			String year = getStr(map, "pub_year");
			long oldCnt = 0L;
			if (vo.getTotals().containsKey(year)) {
				oldCnt = vo.getTotals().get(year);
			}
			long newCnt = getLong(map, "total_cnt");
			vo.getTotals().put(year, oldCnt + newCnt);

			if (totalVo.getTotals().containsKey(year)) {
				long oldTotalCnt = totalVo.getTotals().get(year);
				totalVo.getTotals().put(year, oldTotalCnt + newCnt);
			}

		}

		if(!alreadyMap.isEmpty()) {

			dto.getList().add(totalVo);
		}
		dto.getList().addAll(alreadyMap.values());

		return dto;

	}

	private String getStr(Map map, String key) {
		if (map == null || key == null || !map.containsKey(key)) {
			return "";
		}
		return map.get(key).toString();
	}

	private int getInt(Map map, String key) {
		if (map == null || key == null || !map.containsKey(key)) {
			return 0;
		}
		return Integer.parseInt(map.get(key).toString());
	}

	private long getLong(Map map, String key) {
		if (map == null || key == null || !map.containsKey(key)) {
			return 0;
		}
		return Long.parseLong(map.get(key).toString());
	}

	public CIntegratedCircuit queryByPid(String pid) {
		CIntegratedCircuit qo = new CIntegratedCircuit();
		qo.setPid(pid);
		List<CIntegratedCircuit> list = queryList(qo);
		if (list != null && !list.isEmpty() && list.get(0) != null) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public void doSyncForIprd(String beginDate, String endDate) {

		// TODO Auto-generated method stub
//		http://111.198.99.166:20000/icld/iprd_icld?project_code=530000&ak=397394268%4020230406&time_update=20210102&size=100'
		String baseUrl = ruoYiConfig.getPressApiServer() + "icld/iprd_icld?project_code=530000&ak=397394268%4020230406&time_update=" + beginDate + "&size=1000";

		String code = "200";
		String scroll_id = null;

		// 清空集成电路数据
		logger.debug("清空集成电路数据");
		cIntegratedCircuitMapper.clearData();

		int i = 0;
		while ("200".equals(code)) {
			String url = baseUrl;
			if (StringUtils.isNotBlank(scroll_id)) {
				url = baseUrl + "&scroll_id=" + scroll_id;
			}
			i++;
			logger.debug("开始查询第" + i + "页集成电路基本数据,url:" + url);
			long beginTime = System.currentTimeMillis();
			String res = HttpUtils.sendGet(url);
			logger.debug("第" + i + "页基本数据查询结果,用时:" + (System.currentTimeMillis() - beginTime) + ",res:" + res);
			IcldMod mod = new Gson().fromJson(res, IcldMod.class);
			scroll_id = mod.scroll_id;
			code = mod.code;
			if (mod.results == null || mod.results.isEmpty()) {
				break;
			}
			for (Icld ti : mod.results) {

//				CIntegratedCircuit old = queryByPid(ti._id);
				CIntegratedCircuit old = null;

				CIntegratedCircuit t = ti.toCIntegratedCircuit();

//				if (StringUtils.isNotBlank(t.getProvince())) {
//					BladeRegion bladeRegion = bladeRegionService.selectByProvinceName(t.getProvince());
//					if (bladeRegion != null) {
//						t.setProvinceCode(bladeRegion.getCode());
//					}
//				}

//				if (StringUtils.isNotBlank(t.getCity()) && StringUtils.isNotBlank(t.getProvinceCode())) {
//					BladeRegion bladeRegion = bladeRegionService.selectByCityName(t.getCity(), t.getProvinceCode());
//					if (bladeRegion != null) {
//						t.setCityCode(bladeRegion.getCode());
//					}
//				}

//				if (StringUtils.isNotBlank(t.getCounty()) && StringUtils.isNotBlank(t.getCityCode())) {
//					BladeRegion bladeRegion = bladeRegionService.selectByAreaName(t.getCounty(), t.getCityCode());
//					if (bladeRegion != null) {
//						t.setCountyCode(bladeRegion.getCode());
//					}
//				}

				if (StringUtils.isNotBlank(t.getModifyProvince())) {
					if (t.getModifyProvince().contains(";")) {
//						TODO	
						String modifyProvinceCodes = "";
						String modifyProvinces[] = t.getModifyProvince().trim().split(";");
						for (int j = 0; j < modifyProvinces.length; j++) {
							String modifyProvince = modifyProvinces[j];
							BladeRegion bladeRegion = bladeRegionService.selectByProvinceName(modifyProvince);
							if (bladeRegion != null) {
								if (j > 0) {
									modifyProvinceCodes = modifyProvinceCodes + ";";
								}
								modifyProvinceCodes = modifyProvinceCodes + bladeRegion.getCode();

							}
						}
						t.setModifyProvinceCode(modifyProvinceCodes);

					} else {
						BladeRegion bladeRegion = bladeRegionService.selectByProvinceName(t.getModifyProvince());
						if (bladeRegion != null) {
							t.setModifyProvinceCode(bladeRegion.getCode());
						}
					}

				}

				if (StringUtils.isNotBlank(t.getModifyCity()) && StringUtils.isNotBlank(t.getModifyProvinceCode())) {
					if (t.getModifyCity().contains(";")) {

						if (t.getModifyProvinceCode().contains(";") && t.getModifyCity().split(";").length == t.getModifyProvinceCode().split(";").length) {
//							TODO	
							String modifyCityCodes = "";
							String modifyCitys[] = t.getModifyCity().trim().split(";");
							for (int j = 0; j < modifyCitys.length; j++) {
								String modifyCity = modifyCitys[j];
								String modifyProvinceCode = t.getModifyProvinceCode().split(";")[j];

								BladeRegion bladeRegion = bladeRegionService.selectByCityName(modifyCity, modifyProvinceCode);
								if (bladeRegion != null) {
									if (j > 0) {
										modifyCityCodes = modifyCityCodes + ";";
									}
									modifyCityCodes = modifyCityCodes + bladeRegion.getCode();

								}
							}
							t.setModifyCityCode(modifyCityCodes);
						}

					} else {
						BladeRegion bladeRegion = bladeRegionService.selectByCityName(t.getModifyCity(), t.getModifyProvinceCode());
						if (bladeRegion != null) {
							t.setModifyCityCode(bladeRegion.getCode());
						}
					}

				}

				if (StringUtils.isNotBlank(t.getModifyCounty()) && StringUtils.isNotBlank(t.getModifyCityCode())) {
					if (t.getModifyCounty().contains(";")) {
						if (t.getModifyCityCode().contains(";") && t.getModifyCounty().split(";").length == t.getModifyCityCode().split(";").length) {
//							TODO	
							String modifyCountyCodes = "";
							String modifyCountys[] = t.getModifyCounty().trim().split(";");
							for (int j = 0; j < modifyCountys.length; j++) {
								String modifyCounty = modifyCountys[j];
								String modifyCityCode = t.getModifyCityCode().split(";")[j];

								BladeRegion bladeRegion = bladeRegionService.selectByAreaName(modifyCounty, modifyCityCode);
								if (bladeRegion != null) {
									if (j > 0) {
										modifyCountyCodes = modifyCountyCodes + ";";
									}
									modifyCountyCodes = modifyCountyCodes + bladeRegion.getCode();

								}
							}
							t.setModifyCountyCode(modifyCountyCodes);
						}

					} else {
						BladeRegion bladeRegion = bladeRegionService.selectByAreaName(t.getModifyCounty(), t.getModifyCityCode());
						if (bladeRegion != null) {
							t.setModifyCountyCode(bladeRegion.getCode());
						}
					}

				}
				if (old != null) {
					t.setId(old.getId());
					t.setUpdateTime(new Date());
					updateById(t);
				} else {
					save(t);
				}
			}

		}

	}

	/**
	 * 查询中国集成电路列表
	 *
	 * @param cIntegratedCircuit 中国集成电路
	 * @return 中国集成电路集合
	 * @date 2023-04-28
	 */
	@Override
	public List<CIntegratedCircuit> queryList(CIntegratedCircuit cIntegratedCircuit) {
		QueryWrapper<CIntegratedCircuit> queryWrapper = Wrappers.query();
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getPid())) {
			queryWrapper.eq("pid", cIntegratedCircuit.getPid());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getRegNo())) {
			queryWrapper.eq("reg_no", cIntegratedCircuit.getRegNo());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getAplDate())) {
			queryWrapper.eq("apl_date", cIntegratedCircuit.getAplDate());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getAplYear())) {
			queryWrapper.eq("apl_year", cIntegratedCircuit.getAplYear());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getPubDate())) {
			queryWrapper.eq("pub_date", cIntegratedCircuit.getPubDate());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getPubYear())) {
			queryWrapper.eq("pub_year", cIntegratedCircuit.getPubYear());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getPubNo())) {
			queryWrapper.eq("pub_no", cIntegratedCircuit.getPubNo());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getName())) {
			queryWrapper.like("name", cIntegratedCircuit.getName());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getType())) {
			queryWrapper.eq("type", cIntegratedCircuit.getType());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getCreator())) {
			queryWrapper.eq("creator", cIntegratedCircuit.getCreator());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getCompletionDate())) {
			queryWrapper.eq("completion_date", cIntegratedCircuit.getCompletionDate());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getCommercialUtilizationDay())) {
			queryWrapper.eq("commercial_utilization_day", cIntegratedCircuit.getCommercialUtilizationDay());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getApp())) {
			queryWrapper.eq("app", cIntegratedCircuit.getApp());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getAddress())) {
			queryWrapper.eq("address", cIntegratedCircuit.getAddress());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getCountry())) {
			queryWrapper.eq("country", cIntegratedCircuit.getCountry());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getModifyProvince())) {
			queryWrapper.eq("modify_province", cIntegratedCircuit.getModifyProvince());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getModifyCity())) {
			queryWrapper.eq("modify_city", cIntegratedCircuit.getModifyCity());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getModifyCounty())) {
			queryWrapper.eq("modify_county", cIntegratedCircuit.getModifyCounty());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getPark())) {
			queryWrapper.eq("park", cIntegratedCircuit.getPark());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getTimeCreate())) {
			queryWrapper.eq("time_create", cIntegratedCircuit.getTimeCreate());
		}
		if (StringUtils.isNotEmpty(cIntegratedCircuit.getTimeUpdate())) {
			queryWrapper.eq("time_update", cIntegratedCircuit.getTimeUpdate());
		}
		if (StringUtils.isNotNull(cIntegratedCircuit.getStatus())) {
			queryWrapper.eq("status", cIntegratedCircuit.getStatus());
		}
		if (StringUtils.isNotNull(cIntegratedCircuit.getSysFileId())) {
			queryWrapper.eq("sys_file_id", cIntegratedCircuit.getSysFileId());
		}
		queryWrapper.orderByDesc("id");
		return this.list(queryWrapper);
	}

	public static class IcldMod {
		private String code;
		private Long total;
		private String scroll_id;
		private List<Icld> results;
	}

	public static class Icld {
//		"_id": "BS.205625347",
		private String _id;

//	      "update_id_zyqgg": 11992,
		private String update_id_zyqgg;

//	      "app": "云南南天信息设备有限公司;云南南天电子信息产业股份有限公司",
		private String app;

//	      "time_create": "20230328",
		private String time_create;

//	      "country": "中国;中国",
		private String country;

//	      "creator": "云南南天信息设备有限公司;云南南天电子信息产业股份有限公司",
		private String creator;

//	      "address": "云南省昆明市中国（云南）自由贸易试验区昆明片区经开区洛羊街道办事处拓翔路243号;云南省昆明市云南省昆明市环城东路455号",
		private String address;

//	      "reg_no": "BS.205625347",
		private String reg_no;

//	      "modify_county": "呈贡区;盘龙区",
		private String modify_county;

//	      "type": "结构：MOS\n技术：CMOS\n功能：微型计算机",
		private String type;

//	      "apl_date": "20201224",
		private String apl_date;

//	      "pub_date": "20210310",
		private String pub_date;

//	      "commercial_utilization_day": "",
		private String commercial_utilization_day;

//	      "time_update": "20230404",
		private String time_update;

//	      "modify_province": "云南省;云南省",
		private String modify_province;

//	      "apl_year": "2020",
		private String apl_year;

//	      "pub_year": "2021",
		private String pub_year;

//	      "update_id_zyqr": 11994,
		private String update_id_zyqr;

//	      "name": "串行击打式打印机专用控制芯片PRIC001",
		private String name;

//	      "completion_date": "20180509",
		private String completion_date;

//	      "pub_no": "40983",
		private String pub_no;

//	      "modify_city": "昆明市;昆明市",
		private String modify_city;

//	      "park": ""
		private String park;

		public CIntegratedCircuit toCIntegratedCircuit() {
			CIntegratedCircuit c = new CIntegratedCircuit();

////			"_id": "BS.205625347",
//			private String _id;
			c.setPid(_id);
//			
////		      "update_id_zyqgg": 11992,
//			private String update_id_zyqgg;
//			
////		      "app": "云南南天信息设备有限公司;云南南天电子信息产业股份有限公司",
//			private String app;
			c.setApp(app);
//			
////		      "time_create": "20230328",
//			private String time_create;
			c.setTimeCreate(time_create);
//			
////		      "country": "中国;中国",
//			private String country;
			if (StringUtils.isNotBlank(country) && country.contains(";")) {
				country = country.split(";")[0];
			}
			c.setCountry(country);
//			
////		      "creator": "云南南天信息设备有限公司;云南南天电子信息产业股份有限公司",
//			private String creator;
			c.setCreator(creator);
//			
////		      "address": "云南省昆明市中国（云南）自由贸易试验区昆明片区经开区洛羊街道办事处拓翔路243号;云南省昆明市云南省昆明市环城东路455号",
//			private String address;
			c.setAddress(address);
//			
////		      "reg_no": "BS.205625347",
//			private String reg_no;
			c.setRegNo(reg_no);
//			
////		      "modify_county": "呈贡区;盘龙区",
//			private String modify_county;
			if (StringUtils.isNotBlank(modify_county) && modify_county.contains(";")) {
				modify_county = modify_county.split(";")[0];
			}
			c.setModifyCounty(modify_county);

//			
////		      "type": "结构：MOS\n技术：CMOS\n功能：微型计算机",
//			private String type;
			c.setType(type);
//			
////		      "apl_date": "20201224",
//			private String apl_date;
			c.setAplDate(apl_date);
//			
////		      "pub_date": "20210310",
//			private String pub_date;
			c.setPubDate(pub_date);
//			
////		      "commercial_utilization_day": "",
//			private String commercial_utilization_day;
			c.setCommercialUtilizationDay(commercial_utilization_day);
//			
////		      "time_update": "20230404",
//			private String time_update;
			c.setTimeUpdate(time_update);
//			
////		      "modify_province": "云南省;云南省",
//			private String modify_province;
			if (StringUtils.isNotBlank(modify_province) && modify_province.contains(";")) {
				modify_province = modify_province.split(";")[0];
			}
			c.setModifyProvince(modify_province);
//			
////		      "apl_year": "2020",
//			private String apl_year;
			c.setAplYear(apl_year);
//			
////		      "pub_year": "2021",
//			private String pub_year;
			c.setPubYear(pub_year);
//			
////		      "update_id_zyqr": 11994,
//			private String update_id_zyqr;

//			
////		      "name": "串行击打式打印机专用控制芯片PRIC001",
//			private String name;
			c.setName(name);
//			
////		      "completion_date": "20180509",
//			private String completion_date;
			c.setCompletionDate(completion_date);
//			
////		      "pub_no": "40983",
//			private String pub_no;
			c.setPubNo(pub_no);
//			
////		      "modify_city": "昆明市;昆明市",
//			private String modify_city;
			if (StringUtils.isNotBlank(modify_city) && modify_city.contains(";")) {
				modify_city = modify_city.split(";")[0];
			}
			c.setModifyCity(modify_city);
//			
////		      "park": ""
//			private String park;
			c.setPark(park);

			return c;
		}

	}

}
