public String Trustee() {
MSLog.debug("@@BankTrusteeService开始执行报备"+ "------时间:" + DateUtil.getParseDate( Constants.TIME_FORMAT, new Date()));
//1.查询所有前一天bus进件中放款成功的工单信息
Map<String,Object> condition = new HashMap<String, Object>();//添加查询条件
Date yesterday = DateUtil.getYesterday();//获取昨天
String strYesterday = DateUtil.msFormatDateTime(yesterday, Constants.DATE_FORMAT);
condition.put("startDate", strYesterday+" 23:30:00");
Date today = DateUtil.msGetCurrentDate();
String strToday = DateUtil.msFormatDateTime(today, Constants.DATE_FORMAT);
condition.put("endDate", strToday+" 23:30:00");
List<TLonApplication> lonApplications = bankTrusteeShipMapper.selectApps(condition);
//2.将符合条件的工单信息插入报备表t_lon_bank_trustee
if (lonApplications!=null && lonApplications.size()>0) {
MSLog.debug("存在需要新报备的工单记录,执行插入报备表操作"+JsonUtil.list2json(lonApplications)+ "------时间:" + DateUtil.getParseDate( Constants.TIME_FORMAT, new Date()));
insert(lonApplications);
MSLog.debug("插入报备表结束------时间:" + DateUtil.getParseDate( Constants.TIME_FORMAT, new Date()));
}
//3.从报备表中查询所有未进行报备的记录
MSLog.debug("从报备表中获取所有未报备的数据------时间:" + DateUtil.getParseDate( Constants.TIME_FORMAT, new Date()));
List<BankTrusteeShip> records = bankTrusteeShipMapper.selectAll("0");
MSLog.debug("从报备表中获取所有未报备的数据结束---"+JsonUtil.list2json(records)+"---时间:" + DateUtil.getParseDate( Constants.TIME_FORMAT, new Date()));
records = validate(records);
MSLog.debug("数据校验结束---"+JsonUtil.list2json(records)+"---时间:" + DateUtil.getParseDate( Constants.TIME_FORMAT, new Date()));
if (records != null && records.size() > 0) {
//4.生成报备文件
String fileName = createFile(records);
if (fileName != null) {
//5.将文件上传至sftp
MSLog.debug("开始向sftp上传报备文件------时间:" + DateUtil.getParseDate( Constants.TIME_FORMAT, new Date()));
String ftpIp = ParameterPub.getSystemParam().getSystemSetting().getProperty("bank_sFtp_ip");//sftp地址
String ftpPort = ParameterPub.getSystemParam().getSystemSetting().getProperty("bank_sFtp_port");//sftp端口号
String ftpUser = ParameterPub.getSystemParam().getSystemSetting().getProperty("bank_sFtp_userName");//sftp用户名
String ftpPwd = ParameterPub.getSystemParam().getSystemSetting().getProperty("bank_sFtp_passWord");//sftp密码
String ftpDir = ParameterPub.getSystemParam().getSystemSetting().getProperty("bank_sFtp_path");//sftp上传路径
String fileDir = ParameterPub.getSystemParam().getSystemSetting().getProperty("BankTrusteeShipDir");//文件的本地地址
String fileNameToUp = fileName+".txt";
boolean loanFileUploadFTP = loanFTPService.loanFileUploadFTP(ftpIp, Integer.parseInt(ftpPort), ftpUser, ftpPwd, fileDir, fileNameToUp, ftpDir, "");
MSLog.debug("向sftp上传报备文件结束,返回值:"+loanFileUploadFTP+"------时间:" + DateUtil.getParseDate( Constants.TIME_FORMAT, new Date()));
if ( !loanFileUploadFTP ){
// 上传报备文件失败,同时终止程序
MSLog.info( "上传报备文件失败-------" + fileNameToUp + "------时间:" + DateUtil.getParseDate( Constants.TIME_FORMAT, new Date()));
return "fail";
}
//6.调用账务系统上传报备文件
String url = ParameterPub.getSystemParam().getSystemSetting().getProperty("BankTrusteeShip");
Map<String, String> params = new HashMap<String, String>();
params.put("fullPath", ftpDir+fileNameToUp);
try {
MSLog.debug("开始调用账务接口进行报备url:"+url+" params:"+JsonUtil.map2json(params)+"------时间:" + DateUtil.getParseDate( Constants.TIME_FORMAT, new Date()));
String result = HttpClientUtil.doHttpPost(url, "GBK", params, 60000);
MSLog.debug("调用账务接口进行报备结束,返回值:"+result+"------时间:" + DateUtil.getParseDate( Constants.TIME_FORMAT, new Date()));
if (result != null && !result.equals("")) {
//响应信息转换对象操作
JsonNode node = mapper.readTree(result);
//响应码
String strCode = node.get("resp_code").getTextValue();
if (strCode!= null && "0000".equals(strCode)) {
MSLog.debug("通知账务进行报备成功,开始更新报备表数据------时间:" + DateUtil.getParseDate( Constants.TIME_FORMAT, new Date()));
//7.更新报备表数据
for (int j = 0; j < records.size(); j++) {
Map<String, Object> conditions = new HashMap<String, Object>();
conditions.put("appId", records.get(j).getAppId());
conditions.put("isTrustee", "1");
conditions.put("lastUpDate", DateUtil.getCurrentTime(Constants.TIME_FORMAT));
conditions.put("fileName", ftpDir+fileNameToUp);
bankTrusteeShipMapper.updateIsTrustee(conditions);
}
MSLog.debug("更新报备表数据成功,报备任务结束------时间:" + DateUtil.getParseDate( Constants.TIME_FORMAT, new Date()));
return "success";
} else {
MSLog.debug("报备失败"+result+ "------时间:" + DateUtil.getParseDate( Constants.TIME_FORMAT, new Date()));
return "fail";
}
}else {
MSLog.debug("报备失败"+result+ "------时间:" + DateUtil.getParseDate( Constants.TIME_FORMAT, new Date()));
return "fail";
}
} catch (Exception e) {
MSLog.debug("调用账务系统进行报备异常",e);
return "fail";
}
} else {
MSLog.debug("生成报备文件失败---时间:" + DateUtil.getParseDate( Constants.TIME_FORMAT, new Date()));
return "fail";
}
} else {
MSLog.debug("没有需要报备的数据---时间:" + DateUtil.getParseDate( Constants.TIME_FORMAT, new Date()));
return "success";
}
}