|  |  |  | @ -0,0 +1,747 @@ | 
			
		
	
		
			
				
					|  |  |  |  | package com.glxp.api.idc.service.impl; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import com.alibaba.fastjson.JSON; | 
			
		
	
		
			
				
					|  |  |  |  | import com.alibaba.fastjson.JSONObject; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.common.res.BaseResponse; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.common.util.ResultVOUtils; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.dao.schedule.ScheduledDao; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.entity.system.ScheduledEntity; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.entity.system.SystemParamConfigEntity; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.dao.idc.DbDao; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.idc.service.IdcService; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.idc.utils.DBAUtils; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.idc.utils.IDCUtils; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.req.system.ScheduledRequest; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.service.system.SystemParamConfigService; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.util.CustomUtil; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.util.DateUtil; | 
			
		
	
		
			
				
					|  |  |  |  | import com.glxp.api.util.FileUtils; | 
			
		
	
		
			
				
					|  |  |  |  | import lombok.extern.slf4j.Slf4j; | 
			
		
	
		
			
				
					|  |  |  |  | import okhttp3.*; | 
			
		
	
		
			
				
					|  |  |  |  | import org.apache.commons.lang3.StringUtils; | 
			
		
	
		
			
				
					|  |  |  |  | import org.apache.commons.lang3.text.WordUtils; | 
			
		
	
		
			
				
					|  |  |  |  | import org.apache.tools.ant.util.DateUtils; | 
			
		
	
		
			
				
					|  |  |  |  | import org.slf4j.Logger; | 
			
		
	
		
			
				
					|  |  |  |  | import org.slf4j.LoggerFactory; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.beans.factory.annotation.Value; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.jdbc.core.JdbcTemplate; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.scheduling.annotation.Async; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.scheduling.support.CronSequenceGenerator; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.stereotype.Service; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.web.multipart.MultipartFile; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import javax.annotation.Resource; | 
			
		
	
		
			
				
					|  |  |  |  | import javax.servlet.http.HttpServletRequest; | 
			
		
	
		
			
				
					|  |  |  |  | import java.io.File; | 
			
		
	
		
			
				
					|  |  |  |  | import java.io.FileOutputStream; | 
			
		
	
		
			
				
					|  |  |  |  | import java.io.IOException; | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.*; | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.concurrent.TimeUnit; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | /*数据中继数据中心(接收)*/ | 
			
		
	
		
			
				
					|  |  |  |  | @Slf4j | 
			
		
	
		
			
				
					|  |  |  |  | @Service | 
			
		
	
		
			
				
					|  |  |  |  | public class IdcServiceImpl implements IdcService { | 
			
		
	
		
			
				
					|  |  |  |  |     private static final Logger logger = LoggerFactory.getLogger(IdcServiceImpl.class); | 
			
		
	
		
			
				
					|  |  |  |  |     @Value("${file_path}") | 
			
		
	
		
			
				
					|  |  |  |  |     private String filePath; | 
			
		
	
		
			
				
					|  |  |  |  |     @Value("${back_file_path}") | 
			
		
	
		
			
				
					|  |  |  |  |     private String backFilePath; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Value("${API_KEY}") | 
			
		
	
		
			
				
					|  |  |  |  |     private String apiKey; | 
			
		
	
		
			
				
					|  |  |  |  |     @Value("${API_SECRET}") | 
			
		
	
		
			
				
					|  |  |  |  |     private String apiSecret; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /*自助平台->UDI*/ | 
			
		
	
		
			
				
					|  |  |  |  |     private final String[] SPMS_TO_UDI_TABLES = { | 
			
		
	
		
			
				
					|  |  |  |  |             "basic_udirel/updateTime//耗材字典", "basic_products///耗材字典信息详情", "company_product_relevance/updateTime//供应商关联信息", | 
			
		
	
		
			
				
					|  |  |  |  |             "basic_corp/updateTime//往来单位", "thr_bustype_origin/updateTime//第三方单据类型", | 
			
		
	
		
			
				
					|  |  |  |  |             "thr_corp/updateTime//第三方往来单位", "thr_dept/updateTime//第三方部门", | 
			
		
	
		
			
				
					|  |  |  |  |             "thr_inv_products/updateTime//第三方库存", "thr_inv_warehouse///第三方仓库", | 
			
		
	
		
			
				
					|  |  |  |  |             "thr_order/updateTime//第三方单据", "thr_order_detail/updateTime//第三方单据详情", | 
			
		
	
		
			
				
					|  |  |  |  |             "thr_products/updateTime//第三方产品信息", "sup_cert/updateTime/filePath/资质证书信息", | 
			
		
	
		
			
				
					|  |  |  |  |             "sup_cert_set/updateTime//供应商资质证书设置", "sup_company/updateTime//配送供应商资质信息", | 
			
		
	
		
			
				
					|  |  |  |  |             "sup_manufacturer/updateTime//生产企业资质信息", "sup_product/updateTime//产品资质信息"}; | 
			
		
	
		
			
				
					|  |  |  |  |     /*UDI->自助平台*/ | 
			
		
	
		
			
				
					|  |  |  |  |     private final String[] UDI_TO_SPMS_TABLES = { | 
			
		
	
		
			
				
					|  |  |  |  |             "basic_udirel/updateTime//耗材字典", "basic_products///耗材字典信息详情", "company_product_relevance/updateTime//供应商关联信息", | 
			
		
	
		
			
				
					|  |  |  |  |             "basic_corp/updateTime//往来单位", "thr_bustype_origin/updateTime//第三方单据类型", | 
			
		
	
		
			
				
					|  |  |  |  |             "thr_corp/updateTime//第三方往来单位", "thr_dept/updateTime//第三方部门", | 
			
		
	
		
			
				
					|  |  |  |  |             "thr_inv_products/updateTime//第三方库存", "thr_inv_warehouse///第三方仓库", | 
			
		
	
		
			
				
					|  |  |  |  |             "thr_order/updateTime//第三方单据", "thr_order_detail/updateTime//第三方单据详情", | 
			
		
	
		
			
				
					|  |  |  |  |             "thr_products/updateTime//第三方产品信息", "sup_cert/updateTime/filePath/资质证书信息", | 
			
		
	
		
			
				
					|  |  |  |  |             "sup_cert_set/updateTime//供应商资质证书设置", "sup_company/updateTime//配送供应商资质信息", | 
			
		
	
		
			
				
					|  |  |  |  |             "sup_manufacturer/updateTime//生产企业资质信息", "sup_product/updateTime//产品资质信息", | 
			
		
	
		
			
				
					|  |  |  |  |             "productinfo/updateTime//国家库UDI数据,udicompany/updateTime//国际库医疗器械注册人信息"}; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private int orderNum = 0; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Resource | 
			
		
	
		
			
				
					|  |  |  |  |     private SystemParamConfigService systemParamConfigService; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Resource | 
			
		
	
		
			
				
					|  |  |  |  |     private JdbcTemplate jdbcTemplate; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Resource | 
			
		
	
		
			
				
					|  |  |  |  |     private DbDao dbDao; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Resource | 
			
		
	
		
			
				
					|  |  |  |  |     private ScheduledDao scheduledDao; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     public BaseResponse taskList(HttpServletRequest request, Map<String, Object> params) { | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, Object> map = new HashMap<String, Object>(); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("sql", "select taskId from basic_upload_status where status='0'"); | 
			
		
	
		
			
				
					|  |  |  |  |         List<Map<String, Object>> list = dbDao.list(map); | 
			
		
	
		
			
				
					|  |  |  |  |         return ResultVOUtils.success(list); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     public BaseResponse download(HttpServletRequest request, Map<String, Object> params) { | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, Object> map = dbDao.get("select * from basic_upload_status where taskId='" + params.get("taskId") + "'"); | 
			
		
	
		
			
				
					|  |  |  |  |         if (map == null) | 
			
		
	
		
			
				
					|  |  |  |  |             ResultVOUtils.error(9000, "下载任务不存在"); | 
			
		
	
		
			
				
					|  |  |  |  |         String json = FileUtils.readFileAll(map.get("cacheFilePath").toString()); | 
			
		
	
		
			
				
					|  |  |  |  |         JSONObject object = JSON.parseObject(json); | 
			
		
	
		
			
				
					|  |  |  |  |         return ResultVOUtils.success(object); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /*拉取前一级中继服务数据*/ | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     public void pull() { | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, Object> query = new HashMap<String, Object>(); | 
			
		
	
		
			
				
					|  |  |  |  |         String result = post(getNextHost("U") + "/spssync/common/list", query); | 
			
		
	
		
			
				
					|  |  |  |  |         JSONObject json = JSON.parseObject(result); | 
			
		
	
		
			
				
					|  |  |  |  |         if (json.getInteger("code") == 20000 && json.getString("data") != null) { | 
			
		
	
		
			
				
					|  |  |  |  |             List<Map> list = JSON.parseArray(json.getString("data"), Map.class); | 
			
		
	
		
			
				
					|  |  |  |  |             if (list != null) { | 
			
		
	
		
			
				
					|  |  |  |  |                 for (Map map : list) { | 
			
		
	
		
			
				
					|  |  |  |  |                     Map<String, Object> params = new HashMap<String, Object>(); | 
			
		
	
		
			
				
					|  |  |  |  |                     params.put("taskId", map.get("taskId")); | 
			
		
	
		
			
				
					|  |  |  |  |                     pullData(getNextHost("U") + "/spssync/common/list", params); | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Async | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     public void asyncIdcTask() { | 
			
		
	
		
			
				
					|  |  |  |  |         initTable(); | 
			
		
	
		
			
				
					|  |  |  |  |         String[] tNames = {}; | 
			
		
	
		
			
				
					|  |  |  |  |         String direction = getDirection(); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         if (direction.equals("I")) { | 
			
		
	
		
			
				
					|  |  |  |  |             tNames = SPMS_TO_UDI_TABLES; | 
			
		
	
		
			
				
					|  |  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |  |             tNames = UDI_TO_SPMS_TABLES; | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         /*为顶级或末级,以及下游或上游连通,可执行*/ | 
			
		
	
		
			
				
					|  |  |  |  |         Boolean isLastLevel = isLastLevel(direction); | 
			
		
	
		
			
				
					|  |  |  |  |         Boolean isRelay = isRelay(direction); | 
			
		
	
		
			
				
					|  |  |  |  |         System.out.print("-----数据传输任务开始----" + direction + "\n"); | 
			
		
	
		
			
				
					|  |  |  |  |         System.out.print("-----是否顶级或末级服务:" + isLastLevel + ",是否转发数据:" + isRelay + "----\n"); | 
			
		
	
		
			
				
					|  |  |  |  |         if (isLastLevel && isRelay) { | 
			
		
	
		
			
				
					|  |  |  |  |             for (String t : tNames) { | 
			
		
	
		
			
				
					|  |  |  |  |                 uploadData(t); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private void uploadData(String t) { | 
			
		
	
		
			
				
					|  |  |  |  |         String[] tn = t.split("/"); | 
			
		
	
		
			
				
					|  |  |  |  |         String lastUpdateTime = getUpdateTime(tn[0]); | 
			
		
	
		
			
				
					|  |  |  |  |         Date nowUpdateTime = new Date(); | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, Object> map = new HashMap<String, Object>(); | 
			
		
	
		
			
				
					|  |  |  |  |         String sqlWhere = "not exists (select fkId from idc_record where fkId=" + tn[0] + ".id)"; | 
			
		
	
		
			
				
					|  |  |  |  |         if (!StringUtils.isEmpty(tn[1])) { | 
			
		
	
		
			
				
					|  |  |  |  |             sqlWhere += " and ifnull(" + tn[1] + ",now())>=cast('" + lastUpdateTime + "' as datetime)"; | 
			
		
	
		
			
				
					|  |  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |  |             map.put("isEnd", "1"); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("sqlWhere", sqlWhere); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("tableName", tn[0]); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("filePathColumn", tn[2]); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("messageType", tn[3]); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("messageName", tn[3]); | 
			
		
	
		
			
				
					|  |  |  |  |         ScheduledRequest scheduledRequest = new ScheduledRequest(); | 
			
		
	
		
			
				
					|  |  |  |  |         scheduledRequest.setCronName("sync" + WordUtils.capitalizeFully(tn[0], new char[]{'_'}).replace("_", "")); | 
			
		
	
		
			
				
					|  |  |  |  |         ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest); | 
			
		
	
		
			
				
					|  |  |  |  |         String cron = scheduledEntity != null ? scheduledEntity.getCron() : ""; | 
			
		
	
		
			
				
					|  |  |  |  |         boolean send = true; | 
			
		
	
		
			
				
					|  |  |  |  |         if (!StringUtils.isEmpty(cron)) { | 
			
		
	
		
			
				
					|  |  |  |  |             CronSequenceGenerator cronSequenceGenerator = new CronSequenceGenerator(cron); | 
			
		
	
		
			
				
					|  |  |  |  |             Date nextTimePoint = cronSequenceGenerator.next(DateUtil.parseDate(lastUpdateTime)); | 
			
		
	
		
			
				
					|  |  |  |  |             send = nextTimePoint.before(nowUpdateTime); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         //if(send) {
 | 
			
		
	
		
			
				
					|  |  |  |  |         BaseResponse result = send(map); | 
			
		
	
		
			
				
					|  |  |  |  |         if (result.getCode() == 20000) { | 
			
		
	
		
			
				
					|  |  |  |  |             setUpdateTime(tn[0], DateUtil.formatDate(nowUpdateTime)); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         //}
 | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private String pullData(String url, Map<String, Object> params) { | 
			
		
	
		
			
				
					|  |  |  |  |         OkHttpClient client = new OkHttpClient().newBuilder() | 
			
		
	
		
			
				
					|  |  |  |  |                 .build(); | 
			
		
	
		
			
				
					|  |  |  |  |         MediaType mediaType = MediaType.parse("application/json"); | 
			
		
	
		
			
				
					|  |  |  |  |         RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(params)); | 
			
		
	
		
			
				
					|  |  |  |  |         Request request = new Request.Builder() | 
			
		
	
		
			
				
					|  |  |  |  |                 .url(url) | 
			
		
	
		
			
				
					|  |  |  |  |                 .method("POST", body) | 
			
		
	
		
			
				
					|  |  |  |  |                 .addHeader("Content-Type", "application/json") | 
			
		
	
		
			
				
					|  |  |  |  |                 .build(); | 
			
		
	
		
			
				
					|  |  |  |  |         String result = ""; | 
			
		
	
		
			
				
					|  |  |  |  |         MultipartFile[] files = {}; | 
			
		
	
		
			
				
					|  |  |  |  |         try { | 
			
		
	
		
			
				
					|  |  |  |  |             Response response = client.newCall(request).execute(); | 
			
		
	
		
			
				
					|  |  |  |  |             result = response.body().toString(); | 
			
		
	
		
			
				
					|  |  |  |  |             JSONObject json = JSONObject.parseObject(result); | 
			
		
	
		
			
				
					|  |  |  |  |             analyToDB(json, files); | 
			
		
	
		
			
				
					|  |  |  |  |         } catch (IOException e) { | 
			
		
	
		
			
				
					|  |  |  |  |             // TODO Auto-generated catch block
 | 
			
		
	
		
			
				
					|  |  |  |  |             e.printStackTrace(); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         return result; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private String post(String url, Map<String, Object> params) { | 
			
		
	
		
			
				
					|  |  |  |  |         OkHttpClient client = new OkHttpClient().newBuilder() | 
			
		
	
		
			
				
					|  |  |  |  |                 .build(); | 
			
		
	
		
			
				
					|  |  |  |  |         MediaType mediaType = MediaType.parse("application/json"); | 
			
		
	
		
			
				
					|  |  |  |  |         RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(params)); | 
			
		
	
		
			
				
					|  |  |  |  |         Request request = new Request.Builder() | 
			
		
	
		
			
				
					|  |  |  |  |                 .url(url) | 
			
		
	
		
			
				
					|  |  |  |  |                 .method("POST", body) | 
			
		
	
		
			
				
					|  |  |  |  |                 .addHeader("Content-Type", "application/json") | 
			
		
	
		
			
				
					|  |  |  |  |                 .build(); | 
			
		
	
		
			
				
					|  |  |  |  |         String result = ""; | 
			
		
	
		
			
				
					|  |  |  |  |         try { | 
			
		
	
		
			
				
					|  |  |  |  |             Response response = client.newCall(request).execute(); | 
			
		
	
		
			
				
					|  |  |  |  |             result = response.body().toString(); | 
			
		
	
		
			
				
					|  |  |  |  |         } catch (IOException e) { | 
			
		
	
		
			
				
					|  |  |  |  |             // TODO Auto-generated catch block
 | 
			
		
	
		
			
				
					|  |  |  |  |             e.printStackTrace(); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         return result; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     public BaseResponse downlaodSuccess(HttpServletRequest request, Map<String, Object> params) { | 
			
		
	
		
			
				
					|  |  |  |  |         String sql = "update basic_upload_status set status='1' where taskId='" + params.get("taskId") + "'"; | 
			
		
	
		
			
				
					|  |  |  |  |         dbDao.update(sql); | 
			
		
	
		
			
				
					|  |  |  |  |         return ResultVOUtils.success(); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /*direction方向 U 上传,I 下发,往自助平台为上传,往UDI管理系统为下发*/ | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     public BaseResponse receive(String direction, HttpServletRequest request, | 
			
		
	
		
			
				
					|  |  |  |  |                                 String content, MultipartFile[] files) { | 
			
		
	
		
			
				
					|  |  |  |  |         /*授权检查,后续完善*/ | 
			
		
	
		
			
				
					|  |  |  |  |         String apiKey = request.getHeader("apiKey"); | 
			
		
	
		
			
				
					|  |  |  |  |         String secretKey = request.getHeader("secretKey"); | 
			
		
	
		
			
				
					|  |  |  |  |         /*******/ | 
			
		
	
		
			
				
					|  |  |  |  |         JSONObject json = JSONObject.parseObject(content); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         String datePath = DateUtil.formatDate(new Date(), "yyyy-MM-dd"); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         FileUtils.makeDirectory(filePath + datePath + "/"); | 
			
		
	
		
			
				
					|  |  |  |  |         FileUtils.makeDirectory(backFilePath + datePath + "/"); | 
			
		
	
		
			
				
					|  |  |  |  |         String fileName = filePath + datePath + "/" + json.getString("messageType") + "-" + json.getString("messageId") + ".udi"; | 
			
		
	
		
			
				
					|  |  |  |  |         String backFileName = backFilePath + datePath + "/" + json.getString("messageType") + "-" + json.getString("messageId") + ".udi"; | 
			
		
	
		
			
				
					|  |  |  |  |         FileUtils.SaveFileAs(content, fileName); | 
			
		
	
		
			
				
					|  |  |  |  |         FileUtils.SaveFileAs(content, backFileName); | 
			
		
	
		
			
				
					|  |  |  |  |         String[] saveFiles = {}; | 
			
		
	
		
			
				
					|  |  |  |  |         if (files != null) { | 
			
		
	
		
			
				
					|  |  |  |  |             saveFiles = new String[files.length]; | 
			
		
	
		
			
				
					|  |  |  |  |             int n = 0; | 
			
		
	
		
			
				
					|  |  |  |  |             try { | 
			
		
	
		
			
				
					|  |  |  |  |                 for (MultipartFile file : files) { | 
			
		
	
		
			
				
					|  |  |  |  |                     saveFiles[n] = filePath + datePath + "/" + json.getString("messageId") + "/" + file.getOriginalFilename(); | 
			
		
	
		
			
				
					|  |  |  |  |                     writeFile(file.getBytes(), filePath + datePath + "/" + json.getString("messageId") + "/", file.getOriginalFilename()); | 
			
		
	
		
			
				
					|  |  |  |  |                     writeFile(file.getBytes(), backFilePath + datePath + "/" + json.getString("messageId") + "/", file.getOriginalFilename()); | 
			
		
	
		
			
				
					|  |  |  |  |                     n++; | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             } catch (IOException e) { | 
			
		
	
		
			
				
					|  |  |  |  |                 // TODO Auto-generated catch block
 | 
			
		
	
		
			
				
					|  |  |  |  |                 e.printStackTrace(); | 
			
		
	
		
			
				
					|  |  |  |  |             } catch (Exception e) { | 
			
		
	
		
			
				
					|  |  |  |  |                 // TODO Auto-generated catch block
 | 
			
		
	
		
			
				
					|  |  |  |  |                 e.printStackTrace(); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         saveUploadStatus(json.getString("messageType"), json.getString("messageId"), fileName); | 
			
		
	
		
			
				
					|  |  |  |  |         /*解析入库*/ | 
			
		
	
		
			
				
					|  |  |  |  |         if (isLastLevel(direction)) { | 
			
		
	
		
			
				
					|  |  |  |  |             analyToDB(json, files); | 
			
		
	
		
			
				
					|  |  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |  |             //需要转发
 | 
			
		
	
		
			
				
					|  |  |  |  |             if (isRelay(direction)) { | 
			
		
	
		
			
				
					|  |  |  |  |                 relay(direction, request.getHeader("reqNo"), content, saveFiles); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         return ResultVOUtils.success(); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /*数据同步,从数据库获取数据下发或上传下级中继服务*/ | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     public BaseResponse send(Map<String, Object> params) { | 
			
		
	
		
			
				
					|  |  |  |  |         return send(params.get("messageType").toString(), params.get("tableName").toString(), params); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     public BaseResponse send(String messageType, String tableName, Map<String, Object> params) { | 
			
		
	
		
			
				
					|  |  |  |  |         if (sendOnPage(messageType, tableName, params)) | 
			
		
	
		
			
				
					|  |  |  |  |             return ResultVOUtils.success(); | 
			
		
	
		
			
				
					|  |  |  |  |         return ResultVOUtils.error(9999, ""); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private void saveUploadStatus(String messageType, String taskId, String fileName) { | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, Object> map = new HashMap<String, Object>(); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("id", CustomUtil.getId()); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("taskId", taskId); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("cacheFilePath", fileName); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("status", "0"); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("type", messageType); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("updateTime", new Date()); | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, Object> columns = getColumn("basic_upload_status"); | 
			
		
	
		
			
				
					|  |  |  |  |         String sql = "insert into basic_upload_status " + DBAUtils.parseInsert(map, columns); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         dbDao.save(sql); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private void saveDownloadStatus(String messageType, String taskId, String remark) { | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, Object> map = new HashMap<String, Object>(); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("id", CustomUtil.getId()); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("taskId", taskId); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("status", "0"); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("type", messageType); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("updateTime", new Date()); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("remark", remark); | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, Object> columns = getColumn("basic_download_status"); | 
			
		
	
		
			
				
					|  |  |  |  |         String sql = "insert into basic_download_status " + DBAUtils.parseInsert(map, columns); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         dbDao.save(sql); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private void saveIdcLog(String messageType, String taskId, String content, int offset, int total) { | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, Object> map = new HashMap<String, Object>(); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("id", CustomUtil.getId()); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("taskId", taskId); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("orderNum", orderNum); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("type", messageType); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("createTime", new Date()); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("content", content); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("offset", offset); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("total", total); | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, Object> columns = getColumn("idc_log"); | 
			
		
	
		
			
				
					|  |  |  |  |         String sql = "insert into idc_log " + DBAUtils.parseInsert(map, columns); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         dbDao.save(sql); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private boolean sendOnPage(String messageType, String tableName, Map<String, Object> params) { | 
			
		
	
		
			
				
					|  |  |  |  |         boolean success = true; | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, String> table = dbDao.getMysql(tableName); | 
			
		
	
		
			
				
					|  |  |  |  |         if (!(table != null && table.get("tableName") != null)) | 
			
		
	
		
			
				
					|  |  |  |  |             return false; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         String sql = "select count(*) from " + tableName; | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, Object> column = getColumn(tableName); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, Object> map = new HashMap<String, Object>(); | 
			
		
	
		
			
				
					|  |  |  |  |         String where = DBAUtils.convertWhere(column, params, ""); | 
			
		
	
		
			
				
					|  |  |  |  |         sql += !StringUtils.isEmpty(where) ? " where " + where : ""; | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("sql", sql); | 
			
		
	
		
			
				
					|  |  |  |  |         int total = dbDao.count(map); | 
			
		
	
		
			
				
					|  |  |  |  |         String direction = getDirection(); | 
			
		
	
		
			
				
					|  |  |  |  |         String isEnd = params.get("isEnd") != null ? params.get("isEnd").toString() : "0"; | 
			
		
	
		
			
				
					|  |  |  |  |         int limit = 50; | 
			
		
	
		
			
				
					|  |  |  |  |         String[] files = new String[limit]; | 
			
		
	
		
			
				
					|  |  |  |  |         String filePathColumn = params.get("filePathColumn") != null ? params.get("filePathColumn").toString() : ""; | 
			
		
	
		
			
				
					|  |  |  |  |         orderNum++; | 
			
		
	
		
			
				
					|  |  |  |  |         saveIdcLog(messageType, "", tableName + ">" + where, 0, total); | 
			
		
	
		
			
				
					|  |  |  |  |         if (total > 0) { | 
			
		
	
		
			
				
					|  |  |  |  |             params.put("page", 0); | 
			
		
	
		
			
				
					|  |  |  |  |             params.put("limit", limit); | 
			
		
	
		
			
				
					|  |  |  |  |             for (int i = 0; i < Math.ceil(total / limit) + 1; i++) { | 
			
		
	
		
			
				
					|  |  |  |  |                 params.replace("page", i * limit); | 
			
		
	
		
			
				
					|  |  |  |  |                 params.replace("limit", limit); | 
			
		
	
		
			
				
					|  |  |  |  |                 Map<String, Object> data = getData(messageType, tableName, params); | 
			
		
	
		
			
				
					|  |  |  |  |                 String recordSql = ""; | 
			
		
	
		
			
				
					|  |  |  |  |                 orderNum++; | 
			
		
	
		
			
				
					|  |  |  |  |                 saveIdcLog(messageType, "", tableName + ">" + where, i * limit, total); | 
			
		
	
		
			
				
					|  |  |  |  |                 if (data.get("data") != null) { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                     List<Map> list = JSONObject.parseArray(JSON.toJSONString(data.get("data")), Map.class); | 
			
		
	
		
			
				
					|  |  |  |  |                     if (list != null && list.size() > 0) { | 
			
		
	
		
			
				
					|  |  |  |  |                         for (int m = 0; m < list.size(); m++) { | 
			
		
	
		
			
				
					|  |  |  |  |                             if (!StringUtils.isEmpty(filePathColumn) && list.get(m).get(filePathColumn) != null) { | 
			
		
	
		
			
				
					|  |  |  |  |                                 files[m] = list.get(m).get(filePathColumn).toString(); | 
			
		
	
		
			
				
					|  |  |  |  |                             } | 
			
		
	
		
			
				
					|  |  |  |  |                             recordSql += !StringUtils.isEmpty(recordSql) ? "," : ""; | 
			
		
	
		
			
				
					|  |  |  |  |                             recordSql += "('" + UUID.randomUUID().toString().replaceAll("-", "") + "','" + tableName + "','" + list.get(m).get("id") + "','" + isEnd + "',now())"; | 
			
		
	
		
			
				
					|  |  |  |  |                         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                         orderNum++; | 
			
		
	
		
			
				
					|  |  |  |  |                         String result = relay(direction, "", JSON.toJSONString(data), files); | 
			
		
	
		
			
				
					|  |  |  |  |                         if (IDCUtils.isJson(result)) { | 
			
		
	
		
			
				
					|  |  |  |  |                             JSONObject json = JSON.parseObject(result); | 
			
		
	
		
			
				
					|  |  |  |  |                             if (json.getInteger("code") == 20000) { | 
			
		
	
		
			
				
					|  |  |  |  |                                 if (!StringUtils.isEmpty(recordSql)) { | 
			
		
	
		
			
				
					|  |  |  |  |                                     dbDao.save("insert into idc_record (id,type,fkId,isEnd,createTime) values " + recordSql); | 
			
		
	
		
			
				
					|  |  |  |  |                                 } | 
			
		
	
		
			
				
					|  |  |  |  |                                 saveDownloadStatus(messageType, json.getString("reqNo"), messageType + " 记录数:" + list.size() + "/" + total); | 
			
		
	
		
			
				
					|  |  |  |  |                                 saveIdcLog(messageType, "", tableName + ">success", i * limit, total); | 
			
		
	
		
			
				
					|  |  |  |  |                             } else { | 
			
		
	
		
			
				
					|  |  |  |  |                                 success = false; | 
			
		
	
		
			
				
					|  |  |  |  |                                 logger.error(result); | 
			
		
	
		
			
				
					|  |  |  |  |                                 saveIdcLog(messageType, "", tableName + ">" + result, i * limit, total); | 
			
		
	
		
			
				
					|  |  |  |  |                             } | 
			
		
	
		
			
				
					|  |  |  |  |                         } | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         return success; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /*解析到数据库*/ | 
			
		
	
		
			
				
					|  |  |  |  |     private void analyToDB(JSONObject jsonObject, MultipartFile[] files) { | 
			
		
	
		
			
				
					|  |  |  |  |         if (!StringUtils.isEmpty(jsonObject.getString("tableName"))) { | 
			
		
	
		
			
				
					|  |  |  |  |             List<Map<String, Object>> list = jsonObject.getObject("data", List.class); | 
			
		
	
		
			
				
					|  |  |  |  |             analyData(jsonObject.getString("tableName"), list); | 
			
		
	
		
			
				
					|  |  |  |  |             //图片处理
 | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /*按表名解析数据到数据库,子表暂未处理*/ | 
			
		
	
		
			
				
					|  |  |  |  |     private void analyData(String tableName, List<Map<String, Object>> list) { | 
			
		
	
		
			
				
					|  |  |  |  |         String tName = DBAUtils.tableRealName(tableName); | 
			
		
	
		
			
				
					|  |  |  |  |         String sql = "insert into " + tName + "("; | 
			
		
	
		
			
				
					|  |  |  |  |         String del = "delete from " + tName + " where "; | 
			
		
	
		
			
				
					|  |  |  |  |         String upd = "update " + tName + " set "; | 
			
		
	
		
			
				
					|  |  |  |  |         String[] keyColumn = new String[10]; | 
			
		
	
		
			
				
					|  |  |  |  |         String[] keyDataType = new String[10]; | 
			
		
	
		
			
				
					|  |  |  |  |         List<Map<String, String>> columnList = dbDao.listColumnsMysql(tName); | 
			
		
	
		
			
				
					|  |  |  |  |         int key = 0; | 
			
		
	
		
			
				
					|  |  |  |  |         int col = 0; | 
			
		
	
		
			
				
					|  |  |  |  |         for (int i = 0; i < columnList.size(); i++) { | 
			
		
	
		
			
				
					|  |  |  |  |             if (col > 0) | 
			
		
	
		
			
				
					|  |  |  |  |                 sql += ","; | 
			
		
	
		
			
				
					|  |  |  |  |             columnList.get(i).put("attrName", columnList.get(i).get("columnName")); | 
			
		
	
		
			
				
					|  |  |  |  |             String extra = columnList.get(i).get("extra") != null && columnList.get(i).get("extra").toLowerCase().contains("auto_i") ? "A" : "N"; | 
			
		
	
		
			
				
					|  |  |  |  |             sql += extra.equals("N") ? columnList.get(i).get("columnName").toString() : ""; | 
			
		
	
		
			
				
					|  |  |  |  |             col += extra.equals("N") ? 1 : 0; | 
			
		
	
		
			
				
					|  |  |  |  |             if (columnList.get(i).get("columnKey") != null && !StringUtils.isEmpty(columnList.get(i).get("columnKey").toString()) && | 
			
		
	
		
			
				
					|  |  |  |  |                     ("PRI,UNI,MUL".contains(columnList.get(i).get("columnKey").toString())) && extra.equals("N")) { | 
			
		
	
		
			
				
					|  |  |  |  |                 keyColumn[key] = columnList.get(i).get("columnName").toString(); | 
			
		
	
		
			
				
					|  |  |  |  |                 keyDataType[key] = columnList.get(i).get("dataType").toString().contains("char") ? "C" : "N"; | 
			
		
	
		
			
				
					|  |  |  |  |                 key++; | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         sql += ") values "; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         if (list != null && list.size() > 0) { | 
			
		
	
		
			
				
					|  |  |  |  |             int n = 0; | 
			
		
	
		
			
				
					|  |  |  |  |             int d = 0; | 
			
		
	
		
			
				
					|  |  |  |  |             for (int i = 0; i < list.size(); i++) { | 
			
		
	
		
			
				
					|  |  |  |  |                 String operateMode = list.get(i).get("operateMode") != null ? list.get(i).get("operateMode").toString() : "A"; | 
			
		
	
		
			
				
					|  |  |  |  |                 String updateWhere = ""; | 
			
		
	
		
			
				
					|  |  |  |  |                 String updateSet = ""; | 
			
		
	
		
			
				
					|  |  |  |  |                 if ("A,D,U".contains(operateMode)) { | 
			
		
	
		
			
				
					|  |  |  |  |                     for (int z = 0; z < keyColumn.length; z++) { | 
			
		
	
		
			
				
					|  |  |  |  |                         if (list.get(i).get(keyColumn[z]) != null && !StringUtils.isEmpty(list.get(i).get(keyColumn[z]).toString())) { | 
			
		
	
		
			
				
					|  |  |  |  |                             updateWhere += !StringUtils.isEmpty(updateWhere) ? " and " : " "; | 
			
		
	
		
			
				
					|  |  |  |  |                             updateWhere += keyColumn[z] + " = " + (keyDataType[z].equals("C") ? "'" : "") + list.get(i).get(keyColumn[z]) + (keyDataType[z].equals("C") ? "'" : ""); | 
			
		
	
		
			
				
					|  |  |  |  |                         } | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                     if ("A,D".contains(operateMode) && !StringUtils.isEmpty(updateWhere)) | 
			
		
	
		
			
				
					|  |  |  |  |                         dbDao.delete(del + updateWhere); | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |                 /*A 新增 U 更新*/ | 
			
		
	
		
			
				
					|  |  |  |  |                 if ("A,U".contains(operateMode)) { | 
			
		
	
		
			
				
					|  |  |  |  |                     sql += n > 0 ? "," : ""; | 
			
		
	
		
			
				
					|  |  |  |  |                     sql += "("; | 
			
		
	
		
			
				
					|  |  |  |  |                     int m = 0; | 
			
		
	
		
			
				
					|  |  |  |  |                     int h = 0; | 
			
		
	
		
			
				
					|  |  |  |  |                     for (int k = 0; k < columnList.size(); k++) { | 
			
		
	
		
			
				
					|  |  |  |  |                         String extra = columnList.get(k).get("extra") != null && columnList.get(k).get("extra").toLowerCase().contains("auto") ? "A" : "N"; | 
			
		
	
		
			
				
					|  |  |  |  |                         String attrName = columnList.get(k).get("attrName"); | 
			
		
	
		
			
				
					|  |  |  |  |                         String value = list.get(i).get(attrName) != null ? list.get(i).get(attrName).toString() : ""; | 
			
		
	
		
			
				
					|  |  |  |  |                         String dataType = columnList.get(k).get("dataType").toLowerCase().contains("char") || columnList.get(k).get("dataType").toLowerCase().contains("text") ? | 
			
		
	
		
			
				
					|  |  |  |  |                                 "C" : columnList.get(k).get("dataType").toLowerCase().contains("date") ? "D" : "N"; | 
			
		
	
		
			
				
					|  |  |  |  |                         if (extra.equals("N")) { | 
			
		
	
		
			
				
					|  |  |  |  |                             sql += m > 0 ? "," : ""; | 
			
		
	
		
			
				
					|  |  |  |  |                             boolean ups = list.get(i).containsKey(attrName) ? true : false; | 
			
		
	
		
			
				
					|  |  |  |  |                             updateSet += ups && h > 0 ? "," : ""; | 
			
		
	
		
			
				
					|  |  |  |  |                             updateSet += ups ? columnList.get(k).get("columnName") + "=" : ""; | 
			
		
	
		
			
				
					|  |  |  |  |                             if (StringUtils.isEmpty(value)) { | 
			
		
	
		
			
				
					|  |  |  |  |                                 sql += "null"; | 
			
		
	
		
			
				
					|  |  |  |  |                                 updateSet += ups ? "null" : ""; | 
			
		
	
		
			
				
					|  |  |  |  |                             } else { | 
			
		
	
		
			
				
					|  |  |  |  |                                 if (dataType.equals("C")) { | 
			
		
	
		
			
				
					|  |  |  |  |                                     sql += "'" + value + "'"; | 
			
		
	
		
			
				
					|  |  |  |  |                                     updateSet += ups ? "'" + value + "'" : ""; | 
			
		
	
		
			
				
					|  |  |  |  |                                 } else if (dataType.equals("N")) { | 
			
		
	
		
			
				
					|  |  |  |  |                                     sql += value; | 
			
		
	
		
			
				
					|  |  |  |  |                                     updateSet += ups ? value : ""; | 
			
		
	
		
			
				
					|  |  |  |  |                                 } else { | 
			
		
	
		
			
				
					|  |  |  |  |                                     Date date = new Date(); | 
			
		
	
		
			
				
					|  |  |  |  |                                     date = StringUtils.isNumeric(value) ? new Date(Long.valueOf(value)) : IDCUtils.parseDate(value); | 
			
		
	
		
			
				
					|  |  |  |  |                                     String str = DateUtils.format(date, "yyyy-MM-dd HH:mm:ss"); | 
			
		
	
		
			
				
					|  |  |  |  |                                     sql += "cast('" + str + "' as datetime)"; | 
			
		
	
		
			
				
					|  |  |  |  |                                     updateSet += ups ? "cast('" + str + "' as datetime)" : ""; | 
			
		
	
		
			
				
					|  |  |  |  |                                 } | 
			
		
	
		
			
				
					|  |  |  |  |                             } | 
			
		
	
		
			
				
					|  |  |  |  |                             m++; | 
			
		
	
		
			
				
					|  |  |  |  |                             if (operateMode.equals("U") && !StringUtils.isEmpty(updateSet) && !StringUtils.isEmpty(updateWhere)) | 
			
		
	
		
			
				
					|  |  |  |  |                                 dbDao.update(upd + updateSet + " where " + updateWhere); | 
			
		
	
		
			
				
					|  |  |  |  |                             h += ups ? 1 : 0; | 
			
		
	
		
			
				
					|  |  |  |  |                         } | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                     sql += ")"; | 
			
		
	
		
			
				
					|  |  |  |  |                     n++; | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             if (n > 0) | 
			
		
	
		
			
				
					|  |  |  |  |                 dbDao.save(sql); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /*转发下级或上级中继服务*/ | 
			
		
	
		
			
				
					|  |  |  |  |     private String relay(String direction, String reqNo, String content, String[] files) { | 
			
		
	
		
			
				
					|  |  |  |  |         String host = getNextHost(direction); | 
			
		
	
		
			
				
					|  |  |  |  |         String result = ""; | 
			
		
	
		
			
				
					|  |  |  |  |         if (StringUtils.isEmpty(reqNo)) | 
			
		
	
		
			
				
					|  |  |  |  |             reqNo = UUID.randomUUID().toString(); | 
			
		
	
		
			
				
					|  |  |  |  |         if (!StringUtils.isEmpty(host)) { | 
			
		
	
		
			
				
					|  |  |  |  |             host += direction.equals("U") ? "/spssync/common/upload" : "/spssync/common/issued"; | 
			
		
	
		
			
				
					|  |  |  |  |             OkHttpClient client = new OkHttpClient().newBuilder() | 
			
		
	
		
			
				
					|  |  |  |  |                     .connectTimeout(30, TimeUnit.SECONDS)//设置连接超时时间
 | 
			
		
	
		
			
				
					|  |  |  |  |                     .readTimeout(30, TimeUnit.SECONDS)//设置读取超时时间
 | 
			
		
	
		
			
				
					|  |  |  |  |                     .build(); | 
			
		
	
		
			
				
					|  |  |  |  |             MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             MultipartBody.Builder builder = new MultipartBody.Builder(); | 
			
		
	
		
			
				
					|  |  |  |  |             builder.setType(MultipartBody.FORM); | 
			
		
	
		
			
				
					|  |  |  |  |             String fileType = "application/octet-stream"; | 
			
		
	
		
			
				
					|  |  |  |  |             for (int i = 0; i < files.length; i++) { | 
			
		
	
		
			
				
					|  |  |  |  |                 if (!StringUtils.isEmpty(files[i])) { | 
			
		
	
		
			
				
					|  |  |  |  |                     File file = new File(files[i]); | 
			
		
	
		
			
				
					|  |  |  |  |                     builder.addFormDataPart("files", files[i], | 
			
		
	
		
			
				
					|  |  |  |  |                             RequestBody.create(MediaType.parse(fileType), file)); | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             builder.addFormDataPart("content", content); | 
			
		
	
		
			
				
					|  |  |  |  |             RequestBody body = builder.build(); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             Request req = new Request.Builder() | 
			
		
	
		
			
				
					|  |  |  |  |                     .url(host) | 
			
		
	
		
			
				
					|  |  |  |  |                     .method("POST", body) | 
			
		
	
		
			
				
					|  |  |  |  |                     .addHeader("Content-Type", "application/x-www-form-urlencoded") | 
			
		
	
		
			
				
					|  |  |  |  |                     .addHeader("format", "json") | 
			
		
	
		
			
				
					|  |  |  |  |                     .addHeader("apiKey", apiKey) | 
			
		
	
		
			
				
					|  |  |  |  |                     .addHeader("secretKey", apiSecret) | 
			
		
	
		
			
				
					|  |  |  |  |                     .addHeader("reqNo", reqNo) | 
			
		
	
		
			
				
					|  |  |  |  |                     .addHeader("timestamp", DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss")) | 
			
		
	
		
			
				
					|  |  |  |  |                     .addHeader("Access-Control-Allow-Headers", "Authorization, Origin, X-Requested-With, Content-Type, Accept") | 
			
		
	
		
			
				
					|  |  |  |  |                     .build(); | 
			
		
	
		
			
				
					|  |  |  |  |             try { | 
			
		
	
		
			
				
					|  |  |  |  |                 Response response = client.newCall(req).execute(); | 
			
		
	
		
			
				
					|  |  |  |  |                 result = response.body().string(); | 
			
		
	
		
			
				
					|  |  |  |  |                 log.debug("result--->" + result); | 
			
		
	
		
			
				
					|  |  |  |  |             } catch (IOException e) { | 
			
		
	
		
			
				
					|  |  |  |  |                 // TODO Auto-generated catch block
 | 
			
		
	
		
			
				
					|  |  |  |  |                 e.printStackTrace(); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |  |             log.debug("未配置中继服务地址"); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         return result; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /*获取转发服务地址,当前值允许单向,只使用参数upper_server_ip*/ | 
			
		
	
		
			
				
					|  |  |  |  |     private String getNextHost(String direction) { | 
			
		
	
		
			
				
					|  |  |  |  |         SystemParamConfigEntity systemParamConfigEntity = getSystemParamConfig("upper_server_ip", "中继上传服务地址", "", ""); | 
			
		
	
		
			
				
					|  |  |  |  |         //direction.equals("U") ? getSystemParamConfig("upper_server_ip","中继上传服务地址" , "",""):
 | 
			
		
	
		
			
				
					|  |  |  |  |         //getSystemParamConfig("sync_idc_lower_host","下级(下发)中继服务地址" , "","")	;
 | 
			
		
	
		
			
				
					|  |  |  |  |         return systemParamConfigEntity.getParamValue(); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /*判断是否最后一级*/ | 
			
		
	
		
			
				
					|  |  |  |  |     private boolean isLastLevel(String direction) { | 
			
		
	
		
			
				
					|  |  |  |  |         SystemParamConfigEntity systemParamConfigEntity = | 
			
		
	
		
			
				
					|  |  |  |  |                 direction.equals("I") ? getSystemParamConfig("sync_idc_top", "是否顶级中继服务(连接自助平台)", "0", "0:否;1:是(是,接收下级上传数据后解析入库)") : | 
			
		
	
		
			
				
					|  |  |  |  |                         getSystemParamConfig("sync_idc_final", "是否末级中继服务(连接UDI管理系统)", "0", "0:否;1:是(是,接收上级下发数据后解析入库)"); | 
			
		
	
		
			
				
					|  |  |  |  |         return systemParamConfigEntity.getParamValue().equals("0") ? false : true; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /*检查当前系统为自助平台(下发)还是UDI系统(上传),返回传输方向,如果都未设置,默认返回下发*/ | 
			
		
	
		
			
				
					|  |  |  |  |     private String getDirection() { | 
			
		
	
		
			
				
					|  |  |  |  |         SystemParamConfigEntity systemParamConfigEntity = getSystemParamConfig("sync_idc_top", "是否顶级中继服务(连接自助平台)", "0", "0:否;1:是(是,接收下级上传数据后解析入库)"); | 
			
		
	
		
			
				
					|  |  |  |  |         System.out.print(">>>>>>>>>>" + JSON.toJSONString(systemParamConfigEntity) + "\n"); | 
			
		
	
		
			
				
					|  |  |  |  |         if (systemParamConfigEntity.getParamValue().equals("0")) { | 
			
		
	
		
			
				
					|  |  |  |  |             systemParamConfigEntity = getSystemParamConfig("sync_idc_final", "是否末级中继服务(连接UDI管理系统)", "0", "0:否;1:是(是,接收上级下发数据后解析入库)"); | 
			
		
	
		
			
				
					|  |  |  |  |             if (systemParamConfigEntity.getParamValue().equals("1")) | 
			
		
	
		
			
				
					|  |  |  |  |                 return "U"; | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         return "I"; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /*是否需要转发*/ | 
			
		
	
		
			
				
					|  |  |  |  |     private boolean isRelay(String direction) { | 
			
		
	
		
			
				
					|  |  |  |  |         String relayStr = direction.equals("U") ? "sync_upstream_enable" : "sync_downstream_enable"; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey(relayStr); | 
			
		
	
		
			
				
					|  |  |  |  |         if (systemParamConfigEntity != null && systemParamConfigEntity.getParamValue() != null && | 
			
		
	
		
			
				
					|  |  |  |  |                 systemParamConfigEntity.getParamValue().equals("0")) { | 
			
		
	
		
			
				
					|  |  |  |  |             return false; | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         return true; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /*由表名获取数据*/ | 
			
		
	
		
			
				
					|  |  |  |  |     private Map<String, Object> getData(String messageType, String tableName, Map<String, Object> params) { | 
			
		
	
		
			
				
					|  |  |  |  |         String sql = "select " + tableName + ".*,'A' as operateMode from " + tableName; | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, Object> column = getColumn(tableName); | 
			
		
	
		
			
				
					|  |  |  |  |         String where = DBAUtils.convertWhere(column, params, ""); | 
			
		
	
		
			
				
					|  |  |  |  |         sql += !StringUtils.isEmpty(where) ? " where " + where : ""; | 
			
		
	
		
			
				
					|  |  |  |  |         params.put("sql", sql); | 
			
		
	
		
			
				
					|  |  |  |  |         List<Map<String, Object>> list = dbDao.list(params); | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, Object> map = new HashMap<String, Object>(); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("messageId", UUID.randomUUID().toString().replaceAll("-", "")); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("messageType", messageType); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("apiCode", "common"); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("tableName", DBAUtils.tableAliasName(tableName)); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("sendTime", new Date()); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("version", "1.0"); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("total", list.size()); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("data", list); | 
			
		
	
		
			
				
					|  |  |  |  |         return map; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private SystemParamConfigEntity getSystemParamConfig(String paramKey, String paramName, String defaultValue, String paramExplain) { | 
			
		
	
		
			
				
					|  |  |  |  |         SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey(paramKey); | 
			
		
	
		
			
				
					|  |  |  |  |         if (systemParamConfigEntity == null || (systemParamConfigEntity != null && StringUtils.isEmpty(systemParamConfigEntity.getParamKey()))) { | 
			
		
	
		
			
				
					|  |  |  |  |             systemParamConfigEntity = new SystemParamConfigEntity(); | 
			
		
	
		
			
				
					|  |  |  |  |             systemParamConfigEntity.setParamKey(paramKey); | 
			
		
	
		
			
				
					|  |  |  |  |             systemParamConfigEntity.setParamName(paramName); | 
			
		
	
		
			
				
					|  |  |  |  |             systemParamConfigEntity.setParentId(0); | 
			
		
	
		
			
				
					|  |  |  |  |             systemParamConfigEntity.setParamValue(defaultValue); | 
			
		
	
		
			
				
					|  |  |  |  |             systemParamConfigEntity.setParamExplain(paramExplain); | 
			
		
	
		
			
				
					|  |  |  |  |             systemParamConfigEntity.setParamStatus(1); | 
			
		
	
		
			
				
					|  |  |  |  |             systemParamConfigEntity.setParamType(0); | 
			
		
	
		
			
				
					|  |  |  |  |             systemParamConfigService.insert(systemParamConfigEntity); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         System.out.print(JSON.toJSONString(systemParamConfigEntity) + "\n"); | 
			
		
	
		
			
				
					|  |  |  |  |         return systemParamConfigEntity; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private void writeFile(byte[] file, String filePath, String fileName) throws Exception { | 
			
		
	
		
			
				
					|  |  |  |  |         File targetFile = new File(filePath); | 
			
		
	
		
			
				
					|  |  |  |  |         if (!targetFile.exists()) { | 
			
		
	
		
			
				
					|  |  |  |  |             targetFile.mkdirs(); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         FileOutputStream out = new FileOutputStream(filePath + fileName); | 
			
		
	
		
			
				
					|  |  |  |  |         out.write(file); | 
			
		
	
		
			
				
					|  |  |  |  |         out.flush(); | 
			
		
	
		
			
				
					|  |  |  |  |         out.close(); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /*把列数据转Map*/ | 
			
		
	
		
			
				
					|  |  |  |  |     private Map<String, Object> getColumn(String tableName) { | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, Object> map = new HashMap<String, Object>(); | 
			
		
	
		
			
				
					|  |  |  |  |         List<Map<String, String>> columnList = new ArrayList<Map<String, String>>(); | 
			
		
	
		
			
				
					|  |  |  |  |         String columnKey = ""; | 
			
		
	
		
			
				
					|  |  |  |  |         String[] tnames = tableName.split(","); | 
			
		
	
		
			
				
					|  |  |  |  |         for (String tname : tnames) { | 
			
		
	
		
			
				
					|  |  |  |  |             columnList = dbDao.listColumnsMysql(tname); | 
			
		
	
		
			
				
					|  |  |  |  |             if (columnList != null && columnList.size() > 0) { | 
			
		
	
		
			
				
					|  |  |  |  |                 for (int i = 0; i < columnList.size(); i++) { | 
			
		
	
		
			
				
					|  |  |  |  |                     Map<String, Object> column = new HashMap<String, Object>(); | 
			
		
	
		
			
				
					|  |  |  |  |                     String dataType = columnList.get(i).get("dataType").toLowerCase().contains("char") || columnList.get(i).get("dataType").toLowerCase().contains("text") ? | 
			
		
	
		
			
				
					|  |  |  |  |                             "C" : columnList.get(i).get("dataType").toLowerCase().contains("date") ? "D" : "N"; | 
			
		
	
		
			
				
					|  |  |  |  |                     ; | 
			
		
	
		
			
				
					|  |  |  |  |                     String attrName = columnList.get(i).get("columnName").toString(); | 
			
		
	
		
			
				
					|  |  |  |  |                     if (map.get(attrName) == null) { | 
			
		
	
		
			
				
					|  |  |  |  |                         column.put("tableName", tname); | 
			
		
	
		
			
				
					|  |  |  |  |                         column.put("dataType", dataType); | 
			
		
	
		
			
				
					|  |  |  |  |                         column.put("columnName", columnList.get(i).get("columnName")); | 
			
		
	
		
			
				
					|  |  |  |  |                         if (columnList.get(i).get("columnKey") != null) { | 
			
		
	
		
			
				
					|  |  |  |  |                             column.put("columnKey", columnList.get(i).get("columnKey")); | 
			
		
	
		
			
				
					|  |  |  |  |                         } else { | 
			
		
	
		
			
				
					|  |  |  |  |                             column.put("columnKey", "N"); | 
			
		
	
		
			
				
					|  |  |  |  |                         } | 
			
		
	
		
			
				
					|  |  |  |  |                         if (map.get(attrName) != null) { | 
			
		
	
		
			
				
					|  |  |  |  |                             map.put(tname.toLowerCase() + "." + attrName, column); | 
			
		
	
		
			
				
					|  |  |  |  |                         } else { | 
			
		
	
		
			
				
					|  |  |  |  |                             map.put(attrName, column); | 
			
		
	
		
			
				
					|  |  |  |  |                         } | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         return map; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private String getUpdateTime(String id) { | 
			
		
	
		
			
				
					|  |  |  |  |         String updateTime = ""; | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, Object> map = dbDao.get("select * from idc_status where id='" + id + "'"); | 
			
		
	
		
			
				
					|  |  |  |  |         if (map != null && map.get("id") != null) { | 
			
		
	
		
			
				
					|  |  |  |  |             updateTime = DateUtil.formatDate(IDCUtils.parseDate(map.get("statusTime").toString())); | 
			
		
	
		
			
				
					|  |  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |  |             updateTime = "2000-01-01 00:00:00"; | 
			
		
	
		
			
				
					|  |  |  |  |             String sql = "insert into idc_status (id,statusTime) values ('" + id + "',cast('" + updateTime + "' as datetime))"; | 
			
		
	
		
			
				
					|  |  |  |  |             dbDao.save(sql); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         return updateTime; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private String setUpdateTime(String id, String updateTime) { | 
			
		
	
		
			
				
					|  |  |  |  |         String sql = ""; | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, Object> map = dbDao.get("select * from idc_status where id='" + id + "'"); | 
			
		
	
		
			
				
					|  |  |  |  |         if (map != null && map.get("id") != null) { | 
			
		
	
		
			
				
					|  |  |  |  |             sql = "update idc_status set statusTime=cast('" + updateTime + "' as datetime) where id='" + id + "'"; | 
			
		
	
		
			
				
					|  |  |  |  |             dbDao.update(sql); | 
			
		
	
		
			
				
					|  |  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |  |             sql = "insert into idc_status (id,statusTime) values ('" + id + "',cast('" + updateTime + "' as datetime))"; | 
			
		
	
		
			
				
					|  |  |  |  |             dbDao.save(sql); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         return updateTime; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private void initTable() { | 
			
		
	
		
			
				
					|  |  |  |  |         alterTable("idc_status", "create table idc_status (id varchar(36),statusTime datetime,PRIMARY KEY (id))"); | 
			
		
	
		
			
				
					|  |  |  |  |         alterTable("idc_record", "create table idc_record (id varchar(36),type varchar(60),fkId varchar(36),isEnd char(1),createTime datetime,primary key (id),INDEX i_idc_record_fk_id (fkId),INDEX i_idc_record_create_time (createTime))"); | 
			
		
	
		
			
				
					|  |  |  |  |         alterTable("idc_log", "create table idc_log (id varchar(36),orderNum int,taskId varchar(60),type varchar(60),content varchar(2000),offset int,total int,createTime datetime,PRIMARY KEY (id))"); | 
			
		
	
		
			
				
					|  |  |  |  |         dbDao.delete("delete from idc_record where createTime<date_sub(now(),interval 2 day) and isEnd='0'"); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private void alterTable(String tableName, String sql) { | 
			
		
	
		
			
				
					|  |  |  |  |         Map<String, String> map = dbDao.getMysql(tableName); | 
			
		
	
		
			
				
					|  |  |  |  |         if (!(map != null && map.get("tableName") != null)) { | 
			
		
	
		
			
				
					|  |  |  |  |             jdbcTemplate.execute(sql); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | } |